@@ -103,6 +103,8 @@ type Controller struct {
103
103
config * rest.Config // config is the generated config using kubeconfig/incluster config
104
104
// Namespace is the namespace in which NDM is installed
105
105
Namespace string
106
+ //
107
+ LabelList string
106
108
// Clientset is the client used to interface with API server
107
109
Clientset client.Client
108
110
NDMConfig * NodeDiskManagerConfig // NDMConfig contains custom config for ndm
@@ -132,6 +134,13 @@ func NewController() (*Controller, error) {
132
134
}
133
135
controller .Namespace = ns
134
136
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
+
135
144
mgr , err := manager .New (controller .config , manager.Options {Namespace : controller .Namespace , MetricsBindAddress : "0" })
136
145
if err != nil {
137
146
return controller , err
@@ -188,15 +197,15 @@ func (c *Controller) setNodeAttributes() error {
188
197
c .NodeAttributes [NodeNameKey ] = nodeName
189
198
190
199
// set the hostname label
191
- if err = c .setHostName (); err != nil {
200
+ if err = c .setNodeLabels (); err != nil {
192
201
return fmt .Errorf ("unable to set node attributes:%v" , err )
193
202
}
194
203
return nil
195
204
}
196
205
197
- // setHostName set NodeAttribute field in Controller struct
206
+ // setNodeLabels set NodeAttribute field in Controller struct
198
207
// from the labels in node object
199
- func (c * Controller ) setHostName () error {
208
+ func (c * Controller ) setNodeLabels () error {
200
209
nodeName := c .NodeAttributes [NodeNameKey ]
201
210
// get the node object and fetch the hostname label from the
202
211
// node object
@@ -213,6 +222,14 @@ func (c *Controller) setHostName() error {
213
222
} else {
214
223
c .NodeAttributes [HostNameKey ] = hostName
215
224
}
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
+ }
216
233
return nil
217
234
}
218
235
@@ -235,6 +252,17 @@ func getNamespace() (string, error) {
235
252
return ns , nil
236
253
}
237
254
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
+
238
266
// WaitForBlockDeviceCRD will block till the CRDs are loaded
239
267
// into Kubernetes
240
268
func (c * Controller ) WaitForBlockDeviceCRD () {
0 commit comments