Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAndCreateSparseFile(sparseFile string, sparseFileSize int64) error
- func GetActiveSparseDisksUuids(hostname string) []string
- func GetSparseDiskUUID(hostname string, 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) CreateDisk(dr apis.Disk)
- func (c *Controller) DeactivateDisk(dr apis.Disk)
- func (c *Controller) DeactivateStaleDiskResource(devices []string)
- func (c *Controller) DeleteDisk(name string)
- func (c *Controller) FillDiskDetails(diskDetails *DiskInfo)
- func (c *Controller) GetExistingResource(listDr *apis.DiskList, uuid string) *apis.Disk
- func (c *Controller) InitializeSparseFiles()
- func (c *Controller) ListDiskResource() (*apis.DiskList, error)
- func (c *Controller) ListFilter() []*Filter
- func (c *Controller) ListProbe() []*Probe
- func (c *Controller) Lock()
- func (c *Controller) MarkDiskStatusToUnknown()
- func (c *Controller) MarkSparseDiskStateActive(sparseFile string, sparseFileSize int64)
- func (c *Controller) PushDiskResource(oldDr *apis.Disk, diskDetails *DiskInfo)
- func (c *Controller) SetNDMConfig()
- func (c *Controller) Start()
- func (c *Controller) Unlock()
- func (c *Controller) UpdateDisk(dr apis.Disk, oldDr *apis.Disk) error
- func (c *Controller) WaitForDiskCRD()
- type DiskInfo
- type EventMessage
- type Filter
- type FilterConfig
- type FilterInterface
- type Filters
- type NodeDiskManagerConfig
- type PartitionInfo
- type Probe
- type ProbeConfig
- type ProbeIdentifier
- type ProbeInterface
Constants ¶
const ( // NDMKind is the CR kind. NDMKind = "Disk" // FalseString contains string value of false FalseString = "false" // TrueString contains string value of true TrueString = "true" // NDMVersion is the CR version. NDMVersion = "openebs.io/v1alpha1" // NDMHostKey is host name label prefix. NDMHostKey = "kubernetes.io/hostname" // NDMActive is constant for active resource status. NDMActive = "Active" // NDMInactive is constant for inactive resource status. NDMInactive = "Inactive" // NDMUnknown is constant for resource unknown satus. NDMUnknown = "Unknown" // NDMDiskTypeKey specifies the type of disk. NDMDiskTypeKey = "ndm.io/disk-type" // NDMUnmanagedDiskKey specifies disk cr should be managed by ndm or not. NDMManagedKey = "ndm.io/managed" )
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 Disk 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" //SparseDiskType defines sparse disk type SparseDiskType = "sparse" //SparseDiskPrefix defines the prefix for the sparse disk SparseDiskPrefix = "sparse-" )
const ( // CRDRetryInterval is used if CRD is not present. CRDRetryInterval = 10 * time.Second )
const (
// NDMDefaultDiskType will be used to initialize the disk type.
NDMDefaultDiskType = "disk"
)
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.
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 GetActiveSparseDisksUuids ¶
GetActiveSparseDisksUuids returns UUIDs for the sparse disks present in a given node.
func GetSparseDiskUUID ¶ added in v0.2.0
GetSparseDiskUUID 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 { HostName string // HostName is host name in which disk is attached KubeClientset kubernetes.Interface // KubeClientset is standard kubernetes clientset Clientset clientset.Interface // Clientset is clientset for our own API group 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 }
Controller is the controller implementation for do resources
func NewController ¶
func NewController(kubeconfig string) (*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) CreateDisk ¶
func (c *Controller) CreateDisk(dr apis.Disk)
CreateDisk creates the Disk resource in etcd
func (*Controller) DeactivateDisk ¶
func (c *Controller) DeactivateDisk(dr apis.Disk)
DeactivateDisk sets the disk status to inactive in etcd
func (*Controller) DeactivateStaleDiskResource ¶
func (c *Controller) DeactivateStaleDiskResource(devices []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) DeleteDisk ¶
func (c *Controller) DeleteDisk(name string)
DeleteDisk delete the Disk resource from etcd
func (*Controller) FillDiskDetails ¶
func (c *Controller) FillDiskDetails(diskDetails *DiskInfo)
FillDiskDetails lists registered probes and fills details from each probe
func (*Controller) GetExistingResource ¶
GetExistingResource 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) 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) 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) MarkSparseDiskStateActive ¶
func (c *Controller) MarkSparseDiskStateActive(sparseFile string, sparseFileSize int64)
MarkSparseDiskStateActive will either create a Disk 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 Disk CRs are marked with State as Unknown.
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) UpdateDisk ¶
UpdateDisk update the Disk resource in etcd
func (*Controller) WaitForDiskCRD ¶
func (c *Controller) WaitForDiskCRD()
WaitForDiskCRD will block till the CRDs are loaded into Kubernetes
type DiskInfo ¶
type DiskInfo struct { ProbeIdentifiers ProbeIdentifier // ProbeIdentifiers contains some keys to uniquely identify each disk by probe HostName string // HostName contains the node's hostname in which this disk is attached. 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., FileSystemInfo string // FileSystemInfo stores the filesystem on the disk. Can be none, xfs, ext4 etc 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 ¶ added in v0.3.0
ToPartition convert the PartitionData struct inside DiskInfo to apis.Partition which will be used to include the parition 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 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 matche 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 NodeDiskManagerConfig ¶
type NodeDiskManagerConfig struct { ProbeConfigs []ProbeConfig `json:"probeconfigs"` // ProbeConfigs contains configs of Probes FilterConfigs []FilterConfig `json:"filterconfigs"` // FilterConfigs contains configs of Filters }
NodeDiskManagerConfig contains congigs of probes and filters
type PartitionInfo ¶ added in v0.3.0
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. }
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()