@@ -120,7 +120,8 @@ type nfdWorker struct {
120120 kubernetesNamespace string
121121 k8sClient k8sclient.Interface
122122 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
124125 featureSources []source.FeatureSource
125126 labelSources []source.LabelSource
126127 ownerReference []metav1.OwnerReference
@@ -220,6 +221,19 @@ func (i *infiniteTicker) Reset(d time.Duration) {
220221 }
221222}
222223
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+
223237// Run feature discovery.
224238func (w * nfdWorker ) runFeatureDiscovery () error {
225239 discoveryStart := time .Now ()
@@ -237,12 +251,9 @@ func (w *nfdWorker) runFeatureDiscovery() error {
237251 if w .config .Core .SleepInterval .Duration > 0 && discoveryDuration > w .config .Core .SleepInterval .Duration / 2 {
238252 klog .InfoS ("feature discovery sources took over half of sleep interval " , "duration" , discoveryDuration , "sleepInterval" , w .config .Core .SleepInterval .Duration )
239253 }
240- // Get the set of feature labels.
241- labels := createFeatureLabels (w .labelSources , w .config .Core .LabelWhiteList .Regexp )
242254
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
246257 }
247258
248259 return nil
@@ -341,6 +352,15 @@ func (w *nfdWorker) Run() error {
341352 return err
342353 }
343354
355+ case s := <- w .sourceEvent :
356+ if err := (* s ).Discover (); err != nil {
357+ klog .ErrorS (err , "feature discovery failed" , "source" , (* s ).Name ())
358+ break
359+ }
360+ if err = w .publishLabels (); err != nil {
361+ return err
362+ }
363+
344364 case <- w .stop :
345365 klog .InfoS ("shutting down nfd-worker" )
346366 return nil
@@ -525,6 +545,14 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
525545 s .SetConfig (c .Sources [s .Name ()])
526546 }
527547
548+ w .sourceEvent = make (chan * source.FeatureSource )
549+ eventSources := source .GetAllEventSources ()
550+ for _ , s := range eventSources {
551+ if err := s .SetNotifyChannel (w .sourceEvent ); err != nil {
552+ klog .ErrorS (err , "failed to set notify channel for event source" , "source" , s .Name ())
553+ }
554+ }
555+
528556 klog .InfoS ("configuration successfully updated" , "configuration" , w .config )
529557 return nil
530558}
0 commit comments