@@ -30,6 +30,7 @@ import (
3030
3131 "maps"
3232
33+ "github.com/fsnotify/fsnotify"
3334 "github.com/prometheus/client_golang/prometheus"
3435 "github.com/prometheus/client_golang/prometheus/promhttp"
3536 "golang.org/x/net/context"
@@ -121,6 +122,8 @@ type nfdWorker struct {
121122 k8sClient k8sclient.Interface
122123 nfdClient nfdclient.Interface
123124 stop chan struct {} // channel for signaling stop
125+ fsEvent chan fsnotify.Event
126+ fsWatcher * fsnotify.Watcher
124127 featureSources []source.FeatureSource
125128 labelSources []source.LabelSource
126129 ownerReference []metav1.OwnerReference
@@ -304,6 +307,29 @@ func (w *nfdWorker) Run() error {
304307 labelTrigger .Reset (w .config .Core .SleepInterval .Duration )
305308 defer labelTrigger .Stop ()
306309
310+ featureFilesDir := "/etc/kubernetes/node-feature-discovery/features.d/"
311+
312+ info , err := os .Stat (featureFilesDir )
313+ if err != nil {
314+ if ! os .IsNotExist (err ) {
315+ return err
316+ }
317+ }
318+
319+ if info != nil && info .IsDir () {
320+ watcher , err := fsnotify .NewWatcher ()
321+ if err != nil {
322+ return err
323+ }
324+ defer watcher .Close ()
325+
326+ err = watcher .Add (featureFilesDir )
327+ if err != nil {
328+ return fmt .Errorf ("unable to access %v: %w" , featureFilesDir , err )
329+ }
330+ w .fsWatcher = watcher
331+ }
332+
307333 httpMux := http .NewServeMux ()
308334
309335 // Register to metrics server
@@ -341,6 +367,13 @@ func (w *nfdWorker) Run() error {
341367 return err
342368 }
343369
370+ case event := <- w .fsWatcher .Events :
371+ if event .Op & fsnotify .Create == fsnotify .Create || event .Op & fsnotify .Write == fsnotify .Write || event .Op & fsnotify .Remove == fsnotify .Remove || event .Op & fsnotify .Rename == fsnotify .Rename || event .Op & fsnotify .Chmod == fsnotify .Chmod {
372+ err = w .runFeatureDiscovery ()
373+ if err != nil {
374+ return err
375+ }
376+ }
344377 case <- w .stop :
345378 klog .InfoS ("shutting down nfd-worker" )
346379 return nil
0 commit comments