Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAndCreateSparseFile(sparseFile string, sparseFileSize int64) error
- func GetActiveSparseBlockDevicesUUID(hostname string) []string
- func GetSparseBlockDeviceUUID(hostname, sparseFile string) string
- func GetSparseFileCount() int
- func GetSparseFileDir() string
- func GetSparseFileSize() int64
- type Controller
- func (c *Controller) AddNewFilter(filter *Filter)
- func (c *Controller) AddNewProbe(probe *Probe)
- func (c *Controller) ApplyFilter(diskDetails *DiskInfo) bool
- func (c *Controller) Broadcast()
- func (c *Controller) CreateBlockDevice(blockDevice apis.BlockDevice)
- func (c *Controller) CreateDisk(dr apis.Disk)
- func (c *Controller) DeactivateBlockDevice(blockDevice apis.BlockDevice)
- func (c *Controller) DeactivateDisk(dr apis.Disk)
- func (c *Controller) DeactivateStaleBlockDeviceResource(devices []string)
- func (c *Controller) DeactivateStaleDiskResource(disks []string)
- func (c *Controller) DeleteBlockDevice(name string)
- func (c *Controller) DeleteDisk(name string)
- func (c *Controller) DiskToDeviceUUID(diskUUID string) string
- func (c *Controller) FillDiskDetails(diskDetails *DiskInfo)
- func (c *Controller) GetBlockDevice(name string) (*apis.BlockDevice, error)
- func (c *Controller) GetDisk(name string) (*apis.Disk, error)
- func (c *Controller) GetExistingBlockDeviceResource(blockDeviceList *apis.BlockDeviceList, uuid string) *apis.BlockDevice
- func (c *Controller) GetExistingDiskResource(listDr *apis.DiskList, uuid string) *apis.Disk
- func (c *Controller) InitializeSparseFiles()
- func (c *Controller) ListBlockDeviceResource() (*apis.BlockDeviceList, error)
- func (c *Controller) ListDiskResource() (*apis.DiskList, error)
- func (c *Controller) ListFilter() []*Filter
- func (c *Controller) ListProbe() []*Probe
- func (c *Controller) Lock()
- func (c *Controller) MarkBlockDeviceStatusToUnknown()
- func (c *Controller) MarkDiskStatusToUnknown()
- func (c *Controller) MarkSparseBlockDeviceStateActive(sparseFile string, sparseFileSize int64)
- func (c *Controller) NewDeviceInfoFromDiskInfo(diskDetails *DiskInfo) *DeviceInfo
- func (c *Controller) PushBlockDeviceResource(oldBlockDevice *apis.BlockDevice, deviceDetails *DeviceInfo)
- func (c *Controller) PushDiskResource(oldDr *apis.Disk, diskDetails *DiskInfo)
- func (c *Controller) SetNDMConfig()
- func (c *Controller) Start()
- func (c *Controller) Unlock()
- func (c *Controller) UpdateBlockDevice(blockDevice apis.BlockDevice, oldBlockDevice *apis.BlockDevice) error
- func (c *Controller) UpdateDisk(dr apis.Disk, oldDr *apis.Disk) error
- func (c *Controller) WaitForBlockDeviceCRD()
- func (c *Controller) WaitForDiskCRD()
- type DeviceInfo
- type DiskInfo
- type EventMessage
- type FSInfo
- type Filter
- type FilterConfig
- type FilterInterface
- type Filters
- type NodeAttribute
- type NodeDiskManagerConfig
- type PartitionInfo
- type Probe
- type ProbeConfig
- type ProbeIdentifier
- type ProbeInterface
Constants ¶
const ( // FalseString contains string value of false FalseString = "false" // TrueString contains string value of true TrueString = "true" // NDMDiskKind is the Disk kind CR. NDMDiskKind = "Disk" // NDMBlockDeviceKind is the Device kind CR. NDMBlockDeviceKind = "BlockDevice" // HostNameKey is the key for hostname HostNameKey = "hostname" // NodeNameKey is the node name label prefix NodeNameKey = "nodename" // KubernetesHostNameLabel is the hostname label used by k8s KubernetesHostNameLabel = kubernetesLabelPrefix + HostNameKey // NDMVersion is the CR version. NDMVersion = openEBSLabelPrefix + "v1alpha1" // OpenEBSReconcile is used in annotation to check whether CR is to be reconciled or not OpenEBSReconcile = openEBSLabelPrefix + reconcileKey // NDMNotPartitioned is used to say blockdevice does not have any partition. NDMNotPartitioned = "No" // NDMPartitioned is used to say blockdevice has some partitions. NDMPartitioned = "Yes" // NDMActive is constant for active resource status. NDMActive = "Active" // NDMInactive is constant for inactive resource status. NDMInactive = "Inactive" // NDMUnknown is constant for resource unknown status. NDMUnknown = "Unknown" // NDMDiskTypeKey specifies the type of disk. NDMDiskTypeKey = "ndm.io/disk-type" // NDMDeviceTypeKey specifies the block device type NDMDeviceTypeKey = "ndm.io/blockdevice-type" // NDMManagedKey specifies disk cr should be managed by ndm or not. NDMManagedKey = "ndm.io/managed" )
const ( // NDMDefaultDiskType will be used to initialize the disk type. NDMDefaultDiskType = "disk" // NDMDefaultDeviceType will be used to initialize the blockdevice type. NDMDefaultDeviceType = "blockdevice" )
const ( // EnvSparseFileDir - defines a sparse directory. // if it is specified as a environment variable, // a sparse file with specified size (EnvSparseFileSize) will // be created inside specified directory (EnvSparseFileDir) // and an associated BlockDevice CR will be added to Kubernetes. EnvSparseFileDir = "SPARSE_FILE_DIR" //EnvSparseFileSize define the size of created sparse file EnvSparseFileSize = "SPARSE_FILE_SIZE" //EnvSparseFileCount defines the number of sparse files to be created EnvSparseFileCount = "SPARSE_FILE_COUNT" //SparseFileName is a name of Sparse file SparseFileName = "ndm-sparse.img" //SparseFileDefaultSize defines the default sparse file default size SparseFileDefaultSize = int64(1073741824) //SparseFileMinSize defines the minimum size for sparse file SparseFileMinSize = int64(1073741824) //SparseFileDefaultCount defines the default sparse count files SparseFileDefaultCount = "1" //SparseBlockDeviceType defines sparse device type SparseBlockDeviceType = "sparse" //SparseBlockDevicePrefix defines the prefix for the sparse device SparseBlockDevicePrefix = "sparse-" )
const ( // CRDRetryInterval is used if CRD is not present. CRDRetryInterval = 10 * time.Second )
Variables ¶
var ConfigFilePath = "/host/node-disk-manager.config"
ConfigFilePath contains configmap file path
var ControllerBroadcastChannel = make(chan *Controller)
ControllerBroadcastChannel is used to send a copy of controller object to each probe. Each probe can get the copy of controller struct any time they need to read the channel.
var Namespace string
Namespace is the namespace in which NDM is installed
Functions ¶
func CheckAndCreateSparseFile ¶
CheckAndCreateSparseFile will reuse the existing sparse file if it already exists, for handling cases where NDM is upgraded or restarted. If the file doesn't exist a new file will be created.
func GetActiveSparseBlockDevicesUUID ¶
GetActiveSparseBlockDevicesUUID returns UUIDs for the sparse disks present in a given node.
func GetSparseBlockDeviceUUID ¶
GetSparseBlockDeviceUUID returns a fixed UUID for the sparse disk on a given node.
func GetSparseFileCount ¶
func GetSparseFileCount() int
GetSparseFileCount returns the number of sparse files to be
created by NDM. Returns 0, if invalid count is specified.
func GetSparseFileDir ¶
func GetSparseFileDir() string
GetSparseFileDir returns the full path to the sparse file directory on the node.
func GetSparseFileSize ¶
func GetSparseFileSize() int64
GetSparseFileSize returns the size of the sparse file to be
created by NDM. Returns 0, if invalid size is specified.
Types ¶
type Controller ¶
type Controller struct { // Clientset is the client used to interface with API server Clientset client.Client NDMConfig *NodeDiskManagerConfig // NDMConfig contains custom config for ndm Mutex *sync.Mutex // Mutex is used to lock and unlock Controller Filters []*Filter // Filters are the registered filters like os disk filter Probes []*Probe // Probes are the registered probes like udev/smart // NodeAttribute is a map of various attributes of the node in which this daemon is running. // The attributes can be hostname, nodename, zone, failure-domain etc NodeAttributes map[string]string // contains filtered or unexported fields }
Controller is the controller implementation for disk resources
func NewController ¶
func NewController() (*Controller, error)
NewController returns a controller pointer for any error case it will return nil
func (*Controller) AddNewFilter ¶
func (c *Controller) AddNewFilter(filter *Filter)
AddNewFilter adds new filter to controller object
func (*Controller) AddNewProbe ¶
func (c *Controller) AddNewProbe(probe *Probe)
AddNewProbe adds new probe to controller object
func (*Controller) ApplyFilter ¶
func (c *Controller) ApplyFilter(diskDetails *DiskInfo) bool
ApplyFilter checks status for every registered filters if any of the filters wants to stop further process of the event it returns true else it returns false
func (*Controller) Broadcast ¶
func (c *Controller) Broadcast()
Broadcast Broadcasts controller pointer. We are using one single pointer of controller in our application. In that controller pointer each probe and filter registers themselves and later we can list no of active probe using controller object.
func (*Controller) CreateBlockDevice ¶
func (c *Controller) CreateBlockDevice(blockDevice apis.BlockDevice)
CreateBlockDevice creates the BlockDevice resource in etcd This API will be called for each new addDiskEvent blockDevice is DeviceResource-CR
func (*Controller) CreateDisk ¶
func (c *Controller) CreateDisk(dr apis.Disk)
CreateDisk creates the Disk resource in etcd
func (*Controller) DeactivateBlockDevice ¶
func (c *Controller) DeactivateBlockDevice(blockDevice apis.BlockDevice)
DeactivateBlockDevice API is used to set blockdevice status to "inactive" state in etcd
func (*Controller) DeactivateDisk ¶
func (c *Controller) DeactivateDisk(dr apis.Disk)
DeactivateDisk sets the disk status to inactive in etcd
func (*Controller) DeactivateStaleBlockDeviceResource ¶
func (c *Controller) DeactivateStaleBlockDeviceResource(devices []string)
DeactivateStaleBlockDeviceResource deactivates the stale entry from etcd. It gets list of resources which are present in system and queries etcd to get list of active resources. Active resource which is present in etcd not in system that will be marked as inactive.
func (*Controller) DeactivateStaleDiskResource ¶
func (c *Controller) DeactivateStaleDiskResource(disks []string)
DeactivateStaleDiskResource deactivates the stale entry from etcd. It gets list of resources which are present in system and queries etcd to get list of active resources. One active resource which is present in etcd not in system that will be marked as inactive.
func (*Controller) DeleteBlockDevice ¶
func (c *Controller) DeleteBlockDevice(name string)
DeleteBlockDevice delete the BlockDevice resource from etcd
func (*Controller) DeleteDisk ¶
func (c *Controller) DeleteDisk(name string)
DeleteDisk delete the Disk resource from etcd
func (*Controller) DiskToDeviceUUID ¶
func (c *Controller) DiskToDeviceUUID(diskUUID string) string
DiskToDeviceUUID converts a disk UUID (disk-xxx) to a block- device UUID (blockdevice-xxx)
func (*Controller) FillDiskDetails ¶
func (c *Controller) FillDiskDetails(diskDetails *DiskInfo)
FillDiskDetails lists registered probes and fills details from each probe
func (*Controller) GetBlockDevice ¶
func (c *Controller) GetBlockDevice(name string) (*apis.BlockDevice, error)
GetBlockDevice get Disk resource from etcd
func (*Controller) GetDisk ¶
func (c *Controller) GetDisk(name string) (*apis.Disk, error)
GetDisk get Disk resource from etcd
func (*Controller) GetExistingBlockDeviceResource ¶
func (c *Controller) GetExistingBlockDeviceResource(blockDeviceList *apis.BlockDeviceList, uuid string) *apis.BlockDevice
GetExistingBlockDeviceResource returns the existing blockdevice resource if it is present in etcd if not it returns nil pointer.
func (*Controller) GetExistingDiskResource ¶
GetExistingDiskResource returns the existing disk resource if it is present in etcd if not it returns nil pointer.
func (*Controller) InitializeSparseFiles ¶
func (c *Controller) InitializeSparseFiles()
InitializeSparseFiles will check if the sparse file exist or have to be created and will update or create the associated Disk CR accordingly
func (*Controller) ListBlockDeviceResource ¶
func (c *Controller) ListBlockDeviceResource() (*apis.BlockDeviceList, error)
ListBlockDeviceResource queries the etcd for the devices for the host/node and returns list of blockdevice resources.
func (*Controller) ListDiskResource ¶
func (c *Controller) ListDiskResource() (*apis.DiskList, error)
ListDiskResource queries the etcd for the devices for the host/node and returns list of disk resources.
func (*Controller) ListFilter ¶
func (c *Controller) ListFilter() []*Filter
ListFilter returns list of active filters associated with controller object
func (*Controller) ListProbe ¶
func (c *Controller) ListProbe() []*Probe
ListProbe returns list of active probe associated with controller object
func (*Controller) MarkBlockDeviceStatusToUnknown ¶
func (c *Controller) MarkBlockDeviceStatusToUnknown()
MarkBlockDeviceStatusToUnknown makes state of all resources owned by node unknown This will call as a cleanup process before shutting down.
func (*Controller) MarkDiskStatusToUnknown ¶
func (c *Controller) MarkDiskStatusToUnknown()
MarkDiskStatusToUnknown makes state of all resources owned by node unknown This will call as a cleanup process before shutting down.
func (*Controller) MarkSparseBlockDeviceStateActive ¶
func (c *Controller) MarkSparseBlockDeviceStateActive(sparseFile string, sparseFileSize int64)
MarkSparseBlockDeviceStateActive will either create a BlockDevice CR if it doesn't exist, or it will update the state of the existing CR as Active. Note that, when the NDM is going being gracefully shutdown, all its BlockDevice CRs are marked with State as Unknown.
func (*Controller) NewDeviceInfoFromDiskInfo ¶
func (c *Controller) NewDeviceInfoFromDiskInfo(diskDetails *DiskInfo) *DeviceInfo
func (*Controller) PushBlockDeviceResource ¶
func (c *Controller) PushBlockDeviceResource(oldBlockDevice *apis.BlockDevice, deviceDetails *DeviceInfo)
PushBlockDeviceResource is a utility function which checks old blockdevice resource present or not. If it presents in etcd then it updates the resource else it creates new blockdevice resource in etcd
func (*Controller) PushDiskResource ¶
func (c *Controller) PushDiskResource(oldDr *apis.Disk, diskDetails *DiskInfo)
PushDiskResource is a utility function which checks old disk resource present or not. If it presents in etcd then it updates the resource else it creates one new disk resource in etcd
func (*Controller) SetNDMConfig ¶
func (c *Controller) SetNDMConfig()
SetNDMConfig sets config for probes and filters which user provides via configmap. If no configmap present then ndm will load default config for each probes and filters.
func (*Controller) Start ¶
func (c *Controller) Start()
Start is called when we execute cli command ndm start.
func (*Controller) Unlock ¶
func (c *Controller) Unlock()
Unlock unlocks the lock on Controller struct
func (*Controller) UpdateBlockDevice ¶
func (c *Controller) UpdateBlockDevice(blockDevice apis.BlockDevice, oldBlockDevice *apis.BlockDevice) error
UpdateBlockDevice update the BlockDevice resource in etcd
func (*Controller) UpdateDisk ¶
UpdateDisk update the Disk resource in etcd
func (*Controller) WaitForBlockDeviceCRD ¶
func (c *Controller) WaitForBlockDeviceCRD()
WaitForBlockDeviceCRD will block till the CRDs are loaded into Kubernetes
func (*Controller) WaitForDiskCRD ¶
func (c *Controller) WaitForDiskCRD()
WaitForDiskCRD will block till the CRDs are loaded into Kubernetes
type DeviceInfo ¶
type DeviceInfo struct { // NodeAttributes is the attributes of the node to which this block device is attached, // like hostname, nodename NodeAttributes NodeAttribute UUID string // UUID of backing disk Capacity uint64 // Capacity of blockdevice Model string // Do blockdevice have model ?? Serial string // Do blockdevice have serial no ?? Vendor string // Vendor of blockdevice Path string // blockdevice Path like /dev/sda ByIdDevLinks []string // ByIdDevLinks contains by-id devlinks ByPathDevLinks []string // ByPathDevLinks contains by-path devlinks FirmwareRevision string // FirmwareRevision is the firmware revision for a disk LogicalSectorSize uint32 // LogicalSectorSize is the Logical size of blockdevice sector in bytes PhysicalSectorSize uint32 // PhysicalSectorSize is the Physical size of blockdevice sector in bytes Compliance string // Compliance is implemented specifications version i.e. SPC-1, SPC-2, etc DeviceType string // DeviceType represents the type of backing disk PartitionType string // Partition type if the blockdevice is a partition FileSystemInfo FSInfo // FileSystem info of the blockdevice like FSType and MountPoint }
DeviceInfo contains details of blockdevice which can be converted into api.BlockDevice There will be one DeviceInfo created for each physical disk (may change in future). At the end it is converted to BlockDevice struct which will be pushed to etcd as a CR of that blockdevice.
func NewDeviceInfo ¶
func NewDeviceInfo() *DeviceInfo
NewDeviceInfo returns a pointer of empty DeviceInfo struct which will be field from DiskInfo.
func (*DeviceInfo) ToDevice ¶
func (di *DeviceInfo) ToDevice() apis.BlockDevice
ToDevice convert deviceInfo struct to api.BlockDevice type which will be pushed to etcd
type DiskInfo ¶
type DiskInfo struct { ProbeIdentifiers ProbeIdentifier // ProbeIdentifiers contains some keys to uniquely identify each disk by probe NodeAttributes NodeAttribute // NodeAttribute contains the node's attributes like hostname and nodename Uuid string // Uuid is the unique id given by ndm Capacity uint64 // Capacity is capacity of a disk Model string // Model is model no of a disk Serial string // Serial is serial no of a disk Vendor string // Vendor is vendor of a disk Path string // Path is dev path of a disk like /dev/sda ByIdDevLinks []string // ByIdDevLinks contains by-id devlinks ByPathDevLinks []string // ByPathDevLinks contains by-path devlinks FirmwareRevision string // FirmwareRevision is the firmware revision for a disk LogicalSectorSize uint32 // LogicalSectorSize is the Logical size of disk sector in bytes PhysicalSectorSize uint32 // PhysicalSectorSize is the Physical size of disk sector in bytes RotationRate uint16 // 0 = not reported. 1 = SSD, everything else is an RPM Compliance string // Compliance is implemented specifications version i.e. SPC-1, SPC-2, etc DiskType string // DiskType represents the type of disk like Disk, Sparse etc., DriveType string // DriveType represents the type of disk like HHD, HDD etc., FileSystemInformation FSInfo // FileSystemInformation stores the FS related information like filesystem type and mountpoint PartitionData []PartitionInfo // Information of the partitions on the disk //Stats of disk which keep changing TotalBytesRead uint64 TotalBytesWritten uint64 DeviceUtilizationRate float64 PercentEnduranceUsed float64 //Temperature of Drive, all in degree celsius TemperatureInfo struct { TemperatureDataValid bool CurrentTemperature int16 HighestValid bool HighestTemperature int16 //lifetime measured highest LowestValid bool LowestTemperature int16 //lifetime measured lowest } }
DiskInfo contains details of a disk which can be converted into api.Disk This is one utility struct used by different module like probe, controller also in event message. One DiskInfo struct for each disk is created when one event is generated then each probe fills that disk related data in that struct. At the end it is converted to Disk struct which will push to etcd as a CR of that disk.
func NewDiskInfo ¶
func NewDiskInfo() *DiskInfo
NewDiskInfo returns a pointer of empty diskInfo struct which will be field by different probes each probe will responsible for populate some specific fields of DiskInfo struct.
func (*DiskInfo) ToDisk ¶
ToDisk convert diskInfo struct to api.Disk type which will be pushed to etcd
func (*DiskInfo) ToPartition ¶
ToPartition convert the PartitionData struct inside DiskInfo to apis.Partition which will be used to include the partition information in the Disk CR
type EventMessage ¶
type EventMessage struct { Action string // Action is event action like attach/detach Devices []*DiskInfo // list of disks details }
EventMessage struct contains attribute of event message info.
type FSInfo ¶
type FSInfo struct { FileSystem string // Filesystem on the block device MountPoint string // MountPoint of the block device }
FSInfo defines the filesystem related information of block device/disk, like mountpoint and filesystem
type Filter ¶
type Filter struct { Name string // Name is the name of the filter State bool // State is the State of the filter Interface FilterInterface // Interface contains registered filter }
Filter contains name, state and filterInterface
func (*Filter) ApplyFilter ¶
ApplyFilter returns true if both any of include() or exclude() returns true. We are having two types of filter function one is inclusion and exclusion type if any of them returns true then filter doesn't want further process of that event.
type FilterConfig ¶
type FilterConfig struct { Key string `json:"key"` // Key is key for each Filter Name string `json:"name"` // Name is name of Filer State string `json:"state"` // State is state of Filter Include string `json:"include"` // Include contains , separated values which we want to include for filter Exclude string `json:"exclude"` // Exclude contains , separated values which we want to exclude for filter }
FilterConfig contains configs of Filter
type FilterInterface ¶
type FilterInterface interface { Start() Filters }
FilterInterface contains Filters interface and Start()
type Filters ¶
type Filters interface { Include(*DiskInfo) bool // Include returns True if passing DiskInfo matches with include value Exclude(*DiskInfo) bool // exclude returns True if passing DiskInfo does not match with exclude value }
Filters contains Include() and Exclude() filter method. There will be some preset value of include and exclude if passing DiskInfo matches with include value then it returns true if passing DiskINfo does not match with exclude value then it returns false
type NodeAttribute ¶ added in v0.4.2
NodeAttribute is a map of string, which stores various attributes like hostname, node name, failure domain etc of a node
type NodeDiskManagerConfig ¶
type NodeDiskManagerConfig struct { ProbeConfigs []ProbeConfig `json:"probeconfigs"` // ProbeConfigs contains configs of Probes FilterConfigs []FilterConfig `json:"filterconfigs"` // FilterConfigs contains configs of Filters }
NodeDiskManagerConfig contains configs of probes and filters
type PartitionInfo ¶
type PartitionInfo struct { PartitionType string // Partition type like 83, 8e etc. FileSystemInformation FSInfo // FileSystem related information like, filesystem type, mountpoint }
PartitionInfo defines the partition related information like partition type, filesystem etc on the partition
type Probe ¶
type Probe struct { Priority int Name string State bool Interface ProbeInterface }
Probe contains name, state and probeinterface
func (*Probe) FillDiskDetails ¶
FillDiskDetails implements ProbeInterface's FillDiskDetails()
type ProbeConfig ¶
type ProbeConfig struct { Key string `json:"key"` // Key is key for each Probe Name string `json:"name"` // Name is name of Probe State string `json:"state"` // State is state of Probe }
ProbeConfig contains configs of Probe
type ProbeIdentifier ¶
type ProbeIdentifier struct { Uuid string // Uuid is uuid of disk which is generated by udev probe. UdevIdentifier string // UdevIdentifier(syspath) used to identify disk by udevprobe. SmartIdentifier string // SmartIdentifier (devPath) is used to identify disk by smartprobe. SeachestIdentifier string // SeachestIdentifier (devPath) is used to identify disk by seachest. MountIdentifier string // MountIdentifier (devPath) is used to identify disks by mountprobe }
ProbeIdentifier contains some keys to enable probes to uniquely identify each disk. These keys are defined here in order to denote the identifier that a particular probe needs in order to identify a particular disk such as device Path for smart probe and syspath for udev probe Defining all the identifiers separately here makes it more clear and readable to know the keys or the fields that a particular probe requires to identify each and every disk Uuid here is totally related to udev probe since udev is the only probe to scan disks and as a part of discovery, it assign uuid to each disk and which is copied to uuid field of DiskInfo struct.
type ProbeInterface ¶
type ProbeInterface interface { Start() FillDiskDetails(*DiskInfo) }
ProbeInterface contains Start() and FillDiskDetails()