@@ -30,6 +30,7 @@ import (
30
30
31
31
"maps"
32
32
33
+ "github.com/fsnotify/fsnotify"
33
34
"github.com/prometheus/client_golang/prometheus"
34
35
"github.com/prometheus/client_golang/prometheus/promhttp"
35
36
"golang.org/x/net/context"
@@ -121,6 +122,8 @@ type nfdWorker struct {
121
122
k8sClient k8sclient.Interface
122
123
nfdClient nfdclient.Interface
123
124
stop chan struct {} // channel for signaling stop
125
+ fsEvent chan fsnotify.Event
126
+ fsWatcher * fsnotify.Watcher
124
127
featureSources []source.FeatureSource
125
128
labelSources []source.LabelSource
126
129
ownerReference []metav1.OwnerReference
@@ -304,6 +307,29 @@ func (w *nfdWorker) Run() error {
304
307
labelTrigger .Reset (w .config .Core .SleepInterval .Duration )
305
308
defer labelTrigger .Stop ()
306
309
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
+
307
333
httpMux := http .NewServeMux ()
308
334
309
335
// Register to metrics server
@@ -341,6 +367,13 @@ func (w *nfdWorker) Run() error {
341
367
return err
342
368
}
343
369
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
+ }
344
377
case <- w .stop :
345
378
klog .InfoS ("shutting down nfd-worker" )
346
379
return nil
0 commit comments