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(blockDevice *blockdevice.BlockDevice) bool
- func (c *Controller) Broadcast()
- func (c *Controller) CreateBlockDevice(blockDevice apis.BlockDevice) error
- func (c *Controller) DeactivateBlockDevice(blockDevice apis.BlockDevice)
- func (c *Controller) DeactivateStaleBlockDeviceResource(devices []string)
- func (c *Controller) DeleteBlockDevice(name string)
- func (c *Controller) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevice)
- func (c *Controller) GetBlockDevice(name string) (*apis.BlockDevice, error)
- func (c *Controller) GetExistingBlockDeviceResource(blockDeviceList *apis.BlockDeviceList, uuid string) *apis.BlockDevice
- func (c *Controller) InitializeSparseFiles()
- func (c *Controller) ListBlockDeviceResource(listAll bool) (*apis.BlockDeviceList, error)
- func (c *Controller) ListFilter() []*Filter
- func (c *Controller) ListProbe() []*Probe
- func (c *Controller) Lock()
- func (c *Controller) MarkBlockDeviceStatusToUnknown()
- func (c *Controller) MarkSparseBlockDeviceStateActive(sparseFile string, sparseFileSize int64)
- func (c *Controller) NewDeviceInfoFromBlockDevice(blockDevice *bd.BlockDevice) *DeviceInfo
- func (c *Controller) PushBlockDeviceResource(oldBlockDevice *apis.BlockDevice, deviceDetails *DeviceInfo) error
- func (c *Controller) SetControllerOptions(opts NDMOptions) error
- func (c *Controller) SetNDMConfig(opts NDMOptions)
- func (c *Controller) Start()
- func (c *Controller) Unlock()
- func (c *Controller) UpdateBlockDevice(blockDevice apis.BlockDevice, oldBlockDevice *apis.BlockDevice) error
- func (c *Controller) WaitForBlockDeviceCRD()
- type DeviceInfo
- type EventMessage
- type FSInfo
- type Filter
- type FilterConfig
- type FilterInterface
- type Filters
- type NDMOptions
- type NodeDiskManagerConfig
- type Probe
- type ProbeConfig
- type ProbeInterface
- type TagConfig
Constants ¶
const ( // FalseString contains string value of false FalseString = "false" // TrueString contains string value of true TrueString = "true" // 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" // NDMDeviceTypeKey specifies the block device type NDMDeviceTypeKey = "ndm.io/blockdevice-type" // NDMManagedKey specifies blockdevice 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" //SparseBlockDevicePrefix defines the prefix for the sparse device SparseBlockDevicePrefix = "sparse-" )
const ( // CRDRetryInterval is used if CRD is not present. CRDRetryInterval = 10 * time.Second )
const ( // DefaultConfigFilePath is the default path at which config is present inside // container DefaultConfigFilePath = "/host/node-disk-manager.config" )
Variables ¶
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.
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 { // Namespace is the namespace in which NDM is installed Namespace string // 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 // BDHierarchy stores the hierarchy of devices on this node BDHierarchy blockdevice.Hierarchy // 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(blockDevice *blockdevice.BlockDevice) 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) error
CreateBlockDevice creates the BlockDevice resource in etcd This API will be called for each new addDiskEvent blockDevice is DeviceResource-CR
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) 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) DeleteBlockDevice ¶
func (c *Controller) DeleteBlockDevice(name string)
DeleteBlockDevice delete the BlockDevice resource from etcd
func (*Controller) FillBlockDeviceDetails ¶ added in v0.5.0
func (c *Controller) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevice)
FillBlockDeviceDetails 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) 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) 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 BlockDevice CR accordingly
func (*Controller) ListBlockDeviceResource ¶
func (c *Controller) ListBlockDeviceResource(listAll bool) (*apis.BlockDeviceList, error)
ListBlockDeviceResource queries the etcd for the devices and returns list of blockdevice resources. if listAll = true, all the BlockDevices in the cluster will be listed, else only devices present in this node will be listed.
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) 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) NewDeviceInfoFromBlockDevice ¶ added in v0.5.0
func (c *Controller) NewDeviceInfoFromBlockDevice(blockDevice *bd.BlockDevice) *DeviceInfo
NewDeviceInfoFromBlockDevice converts the internal BlockDevice struct to the BlockDevice API resource
func (*Controller) PushBlockDeviceResource ¶
func (c *Controller) PushBlockDeviceResource(oldBlockDevice *apis.BlockDevice, deviceDetails *DeviceInfo) error
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) SetControllerOptions ¶ added in v0.5.0
func (c *Controller) SetControllerOptions(opts NDMOptions) error
SetControllerOptions sets the various attributes and options on the controller
func (*Controller) SetNDMConfig ¶
func (c *Controller) SetNDMConfig(opts NDMOptions)
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) WaitForBlockDeviceCRD ¶
func (c *Controller) WaitForBlockDeviceCRD()
WaitForBlockDeviceCRD 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 bd.NodeAttribute // Optional labels that can be added to the blockdevice resource Labels map[string]string 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 LogicalBlockSize uint32 // LogicalBlockSize is the logical block size of the device in bytes PhysicalBlockSize uint32 // PhysicalBlockSize is the physical block size in bytes HardwareSectorSize uint32 // HardwareSectorSize is the hardware sector size in bytes Compliance string // Compliance is implemented specifications version i.e. SPC-1, SPC-2, etc DeviceType string // DeviceType represents the type of device, like disk/sparse/partition DriveType string // DriveType represents the type of backing drive HDD/SSD 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 EventMessage ¶
type EventMessage struct { Action string // Action is event action like attach/detach Devices []*blockdevice.BlockDevice // list of block device 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 ¶
func (f *Filter) ApplyFilter(blockDevice *blockdevice.BlockDevice) bool
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(*blockdevice.BlockDevice) bool // Include returns True if passing BlockDevice matches with include value Exclude(*blockdevice.BlockDevice) bool // exclude returns True if passing BlockDevice 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 BlockDevice matches with include value then it returns true if passing BlockDevice does not match with exclude value then it returns false
type NDMOptions ¶ added in v0.5.0
type NDMOptions struct { ConfigFilePath string // holds the slice of feature gates. FeatureGate []string }
NDMOptions defines the options to run the NDM daemon
type NodeDiskManagerConfig ¶
type NodeDiskManagerConfig struct { ProbeConfigs []ProbeConfig `json:"probeconfigs"` // ProbeConfigs contains configs of Probes FilterConfigs []FilterConfig `json:"filterconfigs"` // FilterConfigs contains configs of Filters // TagConfigs contains configs for tags TagConfigs []TagConfig `json:"tagconfigs"` }
NodeDiskManagerConfig contains configs of probes and filters
type Probe ¶
type Probe struct { Priority int Name string State bool Interface ProbeInterface }
Probe contains name, state and probeinterface
func (*Probe) FillBlockDeviceDetails ¶ added in v0.5.0
func (p *Probe) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevice)
FillBlockDeviceDetails implements ProbeInterface's FillBlockDeviceDetails()
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 ProbeInterface ¶
type ProbeInterface interface { Start() FillBlockDeviceDetails(*blockdevice.BlockDevice) }
ProbeInterface contains Start() and FillBlockDeviceDetails()