@@ -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,13 @@ func (w *nfdWorker) Run() error {
341352 return err
342353 }
343354
355+ case s := <- w .sourceEvent :
356+ (* s ).Discover ()
357+ err = w .publishLabels ()
358+ if err != nil {
359+ return err
360+ }
361+
344362 case <- w .stop :
345363 klog .InfoS ("shutting down nfd-worker" )
346364 return nil
@@ -525,6 +543,14 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
525543 s .SetConfig (c .Sources [s .Name ()])
526544 }
527545
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+
528554 klog .InfoS ("configuration successfully updated" , "configuration" , w .config )
529555 return nil
530556}
0 commit comments