Skip to content

Commit 8fdf4f5

Browse files
author
Abhishek Agarwal
committed
added device attributes and location details as bd labels
Signed-off-by: Abhishek Agarwal <[email protected]>
1 parent 426eeaa commit 8fdf4f5

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

cmd/ndm_daemonset/controller/blockdevice.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ func (di *DeviceInfo) getObjectMeta() metav1.ObjectMeta {
8585
Annotations: make(map[string]string),
8686
Name: di.UUID,
8787
}
88-
objectMeta.Labels[KubernetesHostNameLabel] = di.NodeAttributes[HostNameKey]
88+
//objectMeta.Labels[KubernetesHostNameLabel] = di.NodeAttributes[HostNameKey]
89+
objectMeta.Labels = di.NodeAttributes
8990
objectMeta.Labels[NDMDeviceTypeKey] = NDMDefaultDeviceType
9091
objectMeta.Labels[NDMManagedKey] = TrueString
9192
// adding custom labels

cmd/ndm_daemonset/controller/controller.go

+31-3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ type Controller struct {
103103
config *rest.Config // config is the generated config using kubeconfig/incluster config
104104
// Namespace is the namespace in which NDM is installed
105105
Namespace string
106+
//
107+
LabelList string
106108
// Clientset is the client used to interface with API server
107109
Clientset client.Client
108110
NDMConfig *NodeDiskManagerConfig // NDMConfig contains custom config for ndm
@@ -132,6 +134,13 @@ func NewController() (*Controller, error) {
132134
}
133135
controller.Namespace = ns
134136

137+
// get the namespace in which NDM is installed
138+
labelList, err := getLabelList()
139+
if err != nil {
140+
return controller, err
141+
}
142+
controller.LabelList = labelList
143+
135144
mgr, err := manager.New(controller.config, manager.Options{Namespace: controller.Namespace, MetricsBindAddress: "0"})
136145
if err != nil {
137146
return controller, err
@@ -188,15 +197,15 @@ func (c *Controller) setNodeAttributes() error {
188197
c.NodeAttributes[NodeNameKey] = nodeName
189198

190199
// set the hostname label
191-
if err = c.setHostName(); err != nil {
200+
if err = c.setNodeLabels(); err != nil {
192201
return fmt.Errorf("unable to set node attributes:%v", err)
193202
}
194203
return nil
195204
}
196205

197-
// setHostName set NodeAttribute field in Controller struct
206+
// setNodeLabels set NodeAttribute field in Controller struct
198207
// from the labels in node object
199-
func (c *Controller) setHostName() error {
208+
func (c *Controller) setNodeLabels() error {
200209
nodeName := c.NodeAttributes[NodeNameKey]
201210
// get the node object and fetch the hostname label from the
202211
// node object
@@ -213,6 +222,14 @@ func (c *Controller) setHostName() error {
213222
} else {
214223
c.NodeAttributes[HostNameKey] = hostName
215224
}
225+
226+
// Fill the blockdevice labels with all the topological labels of the node
227+
// to which it is attached to
228+
for key, value := range node.Labels {
229+
if value != "" {
230+
c.NodeAttributes[key] = value
231+
}
232+
}
216233
return nil
217234
}
218235

@@ -235,6 +252,17 @@ func getNamespace() (string, error) {
235252
return ns, nil
236253
}
237254

255+
256+
// getLabelList get list of labels to be added to the blockdevice from env,
257+
// else it returns error
258+
func getLabelList() (string, error) {
259+
labelList, ok := os.LookupEnv("LABEL_LIST")
260+
if !ok {
261+
return "", errors.New("error getting the list of labels")
262+
}
263+
return labelList, nil
264+
}
265+
238266
// WaitForBlockDeviceCRD will block till the CRDs are loaded
239267
// into Kubernetes
240268
func (c *Controller) WaitForBlockDeviceCRD() {

cmd/ndm_daemonset/probe/addhandler.go

+41
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package probe
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
apis "github.com/openebs/node-disk-manager/api/v1alpha1"
2324
"github.com/openebs/node-disk-manager/blockdevice"
@@ -34,6 +35,20 @@ const (
3435
gptUUIDScheme = "gpt"
3536
internalFSUUIDAnnotation = "internal.openebs.io/fsuuid"
3637
internalPartitionUUIDAnnotation = "internal.openebs.io/partition-uuid"
38+
39+
LabelTypeVendor = "vendor"
40+
LabelTypeModel = "model"
41+
LabelTypeDriveType = "drive-type"
42+
LabelTypeFilesystem = "fs"
43+
44+
// NDMVendorKey specifies the block device vendor
45+
NDMVendorKey = "ndm.io/vendor"
46+
// NDMModelKey specifies block device model
47+
NDMModelKey = "ndm.io/model"
48+
// NDMDriveType specifies the block device type (SSD/HDD/NVMe...)
49+
NDMDriveType = "ndm.io/drive-type"
50+
// NDMFilesystemType specifies the file system present on the block device
51+
NDMFilesystemType = "ndm.io/filesystem-type"
3752
)
3853

3954
// addBlockDeviceToHierarchyCache adds the given block device to the hierarchy of devices.
@@ -247,6 +262,32 @@ func (pe *ProbeEvent) addBlockDevice(bd blockdevice.BlockDevice, bdAPIList *apis
247262
return nil
248263
}
249264

265+
// addBlockDeviceLabels adds labels to the blockdevice resource
266+
func (pe *ProbeEvent) addBlockDeviceLabels(bd blockdevice.BlockDevice) {
267+
// get the list of labels to be added
268+
labelList := pe.Controller.LabelList
269+
if labelList != "" {
270+
labels := make([]string, 0)
271+
labels = strings.Split(labelList, ",")
272+
for _, label := range labels {
273+
if len(label) == 0 {
274+
switch label {
275+
case LabelTypeVendor:
276+
bd.Labels[NDMVendorKey] = bd.DeviceAttributes.Vendor
277+
case LabelTypeModel:
278+
bd.Labels[NDMModelKey] = bd.DeviceAttributes.Model
279+
case LabelTypeDriveType:
280+
bd.Labels[NDMDriveType] = bd.DeviceAttributes.DriveType
281+
case LabelTypeFilesystem:
282+
bd.Labels[NDMFilesystemType] = bd.FSInfo.FileSystem
283+
default:
284+
// do nothing
285+
}
286+
}
287+
}
288+
}
289+
}
290+
250291
// createBlockDeviceResourceIfNoHolders creates/updates a blockdevice resource if it does not have any
251292
// holder devices
252293
func (pe *ProbeEvent) createBlockDeviceResourceIfNoHolders(bd blockdevice.BlockDevice, bdAPIList *apis.BlockDeviceList) error {

cmd/ndm_daemonset/probe/changehandler.go

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ func (pe *ProbeEvent) changeBlockDevice(bd *blockdevice.BlockDevice, requestedPr
3333
}
3434
bd.UUID = uuid
3535
}
36+
// add labels to block device that may be helpful for filtering the block device
37+
// based on some/generic attributes like drive-type, model, vendor etc.
38+
pe.addBlockDeviceLabels(*bd)
3639
pe.addBlockDeviceToHierarchyCache(*bd)
3740
if !pe.Controller.ApplyFilter(bd) {
3841
return nil

cmd/ndm_daemonset/probe/eventhandler.go

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (pe *ProbeEvent) addBlockDeviceEvent(msg controller.EventMessage) {
6262
klog.Infof("Processing details for %s", device.DevPath)
6363
pe.Controller.FillBlockDeviceDetails(device, msg.RequestedProbes...)
6464

65+
// add labels to block device that may be helpful for filtering the block device
66+
// based on some/generic attributes like drive-type, model, vendor etc.
67+
pe.addBlockDeviceLabels(*device)
68+
6569
// add all devices to the hierarchy cache, irrespective of whether they will be
6670
// filtered at a later stage. This is done so that a complete disk hierarchy is available
6771
// at all times by NDM. It also helps in device processing when complex filter configurations

0 commit comments

Comments
 (0)