@@ -120,7 +120,8 @@ type nfdWorker struct {
120
120
kubernetesNamespace string
121
121
k8sClient k8sclient.Interface
122
122
nfdClient nfdclient.Interface
123
- stop chan struct {} // channel for signaling stop
123
+ stop chan struct {} // channel for signaling stop
124
+ sourceEvent chan * source.FeatureSource // channel for events from sources
124
125
featureSources []source.FeatureSource
125
126
labelSources []source.LabelSource
126
127
ownerReference []metav1.OwnerReference
@@ -220,6 +221,19 @@ func (i *infiniteTicker) Reset(d time.Duration) {
220
221
}
221
222
}
222
223
224
+ // Publish labels.
225
+ func (w * nfdWorker ) publishLabels () error {
226
+ // Get the set of feature labels.
227
+ labels := createFeatureLabels (w .labelSources , w .config .Core .LabelWhiteList .Regexp )
228
+
229
+ // Update the node with the feature labels.
230
+ if ! w .config .Core .NoPublish {
231
+ return w .advertiseFeatures (labels )
232
+ }
233
+
234
+ return nil
235
+ }
236
+
223
237
// Run feature discovery.
224
238
func (w * nfdWorker ) runFeatureDiscovery () error {
225
239
discoveryStart := time .Now ()
@@ -237,12 +251,9 @@ func (w *nfdWorker) runFeatureDiscovery() error {
237
251
if w .config .Core .SleepInterval .Duration > 0 && discoveryDuration > w .config .Core .SleepInterval .Duration / 2 {
238
252
klog .InfoS ("feature discovery sources took over half of sleep interval " , "duration" , discoveryDuration , "sleepInterval" , w .config .Core .SleepInterval .Duration )
239
253
}
240
- // Get the set of feature labels.
241
- labels := createFeatureLabels (w .labelSources , w .config .Core .LabelWhiteList .Regexp )
242
254
243
- // Update the node with the feature labels.
244
- if ! w .config .Core .NoPublish {
245
- return w .advertiseFeatures (labels )
255
+ if err := w .publishLabels (); err != nil {
256
+ return err
246
257
}
247
258
248
259
return nil
@@ -341,6 +352,13 @@ func (w *nfdWorker) Run() error {
341
352
return err
342
353
}
343
354
355
+ case s := <- w .sourceEvent :
356
+ (* s ).Discover ()
357
+ err = w .publishLabels ()
358
+ if err != nil {
359
+ return err
360
+ }
361
+
344
362
case <- w .stop :
345
363
klog .InfoS ("shutting down nfd-worker" )
346
364
return nil
@@ -525,6 +543,14 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
525
543
s .SetConfig (c .Sources [s .Name ()])
526
544
}
527
545
546
+ w .sourceEvent = make (chan * source.FeatureSource )
547
+ eventSources := source .GetAllEventSources ()
548
+ for _ , s := range eventSources {
549
+ if err := s .SetNotifyChannel (w .sourceEvent ); err != nil {
550
+ klog .ErrorS (err , "failed to set notify channel for event source" , "source" , s .Name ())
551
+ }
552
+ }
553
+
528
554
klog .InfoS ("configuration successfully updated" , "configuration" , w .config )
529
555
return nil
530
556
}
0 commit comments