@@ -121,6 +121,7 @@ type nfdWorker struct {
121121 k8sClient k8sclient.Interface
122122 nfdClient nfdclient.Interface
123123 stop chan struct {} // channel for signaling stop
124+ sourceEvent chan string // channel for events from sources
124125 featureSources []source.FeatureSource
125126 labelSources []source.LabelSource
126127 ownerReference []metav1.OwnerReference
@@ -248,6 +249,36 @@ func (w *nfdWorker) runFeatureDiscovery() error {
248249 return nil
249250}
250251
252+ // Run feature discovery.
253+ func (w * nfdWorker ) runFeatureDiscoveryBySourceName (source string ) error {
254+ discoveryStart := time .Now ()
255+ for _ , s := range w .featureSources {
256+ if s .Name () == source {
257+ currentSourceStart := time .Now ()
258+ if err := s .Discover (); err != nil {
259+ klog .ErrorS (err , "feature discovery failed" , "source" , s .Name ())
260+ }
261+ klog .V (3 ).InfoS ("feature discovery completed" , "featureSource" , s .Name (), "duration" , time .Since (currentSourceStart ))
262+ }
263+ }
264+
265+ discoveryDuration := time .Since (discoveryStart )
266+ klog .V (2 ).InfoS ("feature discovery of all sources completed" , "duration" , discoveryDuration )
267+ featureDiscoveryDuration .WithLabelValues (utils .NodeName ()).Observe (discoveryDuration .Seconds ())
268+ if w .config .Core .SleepInterval .Duration > 0 && discoveryDuration > w .config .Core .SleepInterval .Duration / 2 {
269+ klog .InfoS ("feature discovery sources took over half of sleep interval " , "duration" , discoveryDuration , "sleepInterval" , w .config .Core .SleepInterval .Duration )
270+ }
271+ // Get the set of feature labels.
272+ labels := createFeatureLabels (w .labelSources , w .config .Core .LabelWhiteList .Regexp )
273+
274+ // Update the node with the feature labels.
275+ if ! w .config .Core .NoPublish {
276+ return w .advertiseFeatures (labels )
277+ }
278+
279+ return nil
280+ }
281+
251282// Set owner ref
252283func (w * nfdWorker ) setOwnerReference () error {
253284 ownerReference := []metav1.OwnerReference {}
@@ -304,6 +335,15 @@ func (w *nfdWorker) Run() error {
304335 labelTrigger .Reset (w .config .Core .SleepInterval .Duration )
305336 defer labelTrigger .Stop ()
306337
338+ w .sourceEvent = make (chan string )
339+ eventSources := source .GetAllEventSources ()
340+ for _ , s := range eventSources {
341+ if err := s .SetNotifyChannel (w .sourceEvent ); err != nil {
342+ klog .ErrorS (err , "failed to set notify channel for event source" , "source" , s .Name ())
343+ return fmt .Errorf ("failed to set notify channel for event source %s: %w" , s .Name (), err )
344+ }
345+ }
346+
307347 httpMux := http .NewServeMux ()
308348
309349 // Register to metrics server
@@ -341,6 +381,12 @@ func (w *nfdWorker) Run() error {
341381 return err
342382 }
343383
384+ case sourceName := <- w .sourceEvent :
385+ err = w .runFeatureDiscoveryBySourceName (sourceName )
386+ if err != nil {
387+ return err
388+ }
389+
344390 case <- w .stop :
345391 klog .InfoS ("shutting down nfd-worker" )
346392 return nil
0 commit comments