@@ -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 soures
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,12 @@ 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+ s .SetNotifyChannel (w .sourceEvent )
342+ }
343+
307344 httpMux := http .NewServeMux ()
308345
309346 // Register to metrics server
@@ -341,6 +378,12 @@ func (w *nfdWorker) Run() error {
341378 return err
342379 }
343380
381+ case sourceName := <- w .sourceEvent :
382+ err = w .runFeatureDiscoveryBySourceName (sourceName )
383+ if err != nil {
384+ return err
385+ }
386+
344387 case <- w .stop :
345388 klog .InfoS ("shutting down nfd-worker" )
346389 return nil
0 commit comments