@@ -77,14 +77,16 @@ type NFDConfig struct {
77
77
}
78
78
79
79
type coreConfig struct {
80
- Klog klogutils.KlogConfigOpts
81
- LabelWhiteList utils.RegexpVal
82
- NoPublish bool
83
- NoOwnerRefs bool
84
- FeatureSources []string
85
- Sources * []string
86
- LabelSources []string
87
- SleepInterval utils.DurationVal
80
+ Klog klogutils.KlogConfigOpts
81
+ LabelWhiteList utils.RegexpVal
82
+ FeatureAllowList utils.RegexpVal
83
+ FeatureDenyList utils.RegexpVal
84
+ NoPublish bool
85
+ NoOwnerRefs bool
86
+ FeatureSources []string
87
+ Sources * []string
88
+ LabelSources []string
89
+ SleepInterval utils.DurationVal
88
90
}
89
91
90
92
type sourcesConfig map [string ]source.Config
@@ -196,11 +198,13 @@ func NewNfdWorker(opts ...NfdWorkerOption) (NfdWorker, error) {
196
198
func newDefaultConfig () * NFDConfig {
197
199
return & NFDConfig {
198
200
Core : coreConfig {
199
- LabelWhiteList : utils.RegexpVal {Regexp : * regexp .MustCompile ("" )},
200
- SleepInterval : utils.DurationVal {Duration : 60 * time .Second },
201
- FeatureSources : []string {"all" },
202
- LabelSources : []string {"all" },
203
- Klog : make (map [string ]string ),
201
+ LabelWhiteList : utils.RegexpVal {Regexp : * regexp .MustCompile ("" )},
202
+ FeatureAllowList : utils.RegexpVal {Regexp : * regexp .MustCompile ("" )},
203
+ FeatureDenyList : utils.RegexpVal {Regexp : * regexp .MustCompile ("" )},
204
+ SleepInterval : utils.DurationVal {Duration : 60 * time .Second },
205
+ FeatureSources : []string {"all" },
206
+ LabelSources : []string {"all" },
207
+ Klog : make (map [string ]string ),
204
208
},
205
209
}
206
210
}
@@ -238,7 +242,7 @@ func (w *nfdWorker) runFeatureDiscovery() error {
238
242
klog .InfoS ("feature discovery sources took over half of sleep interval " , "duration" , discoveryDuration , "sleepInterval" , w .config .Core .SleepInterval .Duration )
239
243
}
240
244
// Get the set of feature labels.
241
- labels := createFeatureLabels (w .labelSources , w .config .Core .LabelWhiteList .Regexp )
245
+ labels := createFeatureLabels (w .labelSources , w .config .Core .LabelWhiteList .Regexp , w . config . Core . FeatureAllowList . Regexp , w . config . Core . FeatureDenyList . Regexp )
242
246
243
247
// Update the node with the feature labels.
244
248
if ! w .config .Core .NoPublish {
@@ -531,13 +535,13 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
531
535
532
536
// createFeatureLabels returns the set of feature labels from the enabled
533
537
// sources and the whitelist argument.
534
- func createFeatureLabels (sources []source.LabelSource , labelWhiteList regexp.Regexp ) (labels Labels ) {
538
+ func createFeatureLabels (sources []source.LabelSource , labelWhiteList regexp.Regexp , featureAllowList regexp. Regexp , featureDenyList regexp. Regexp ) (labels Labels ) {
535
539
labels = Labels {}
536
540
537
541
// Get labels from all enabled label sources
538
542
klog .InfoS ("starting feature discovery..." )
539
543
for _ , source := range sources {
540
- labelsFromSource , err := getFeatureLabels (source , labelWhiteList )
544
+ labelsFromSource , err := getFeatureLabels (source , labelWhiteList , featureAllowList , featureDenyList )
541
545
if err != nil {
542
546
klog .ErrorS (err , "discovery failed" , "source" , source .Name ())
543
547
continue
@@ -555,7 +559,7 @@ func createFeatureLabels(sources []source.LabelSource, labelWhiteList regexp.Reg
555
559
556
560
// getFeatureLabels returns node labels for features discovered by the
557
561
// supplied source.
558
- func getFeatureLabels (source source.LabelSource , labelWhiteList regexp.Regexp ) (labels Labels , err error ) {
562
+ func getFeatureLabels (source source.LabelSource , labelWhiteList regexp.Regexp , featureAllowList regexp. Regexp , featureDenyList regexp. Regexp ) (labels Labels , err error ) {
559
563
labels = Labels {}
560
564
features , err := source .GetLabels ()
561
565
if err != nil {
@@ -564,6 +568,15 @@ func getFeatureLabels(source source.LabelSource, labelWhiteList regexp.Regexp) (
564
568
565
569
for k , v := range features {
566
570
name := k
571
+ if ! featureAllowList .MatchString (name ) {
572
+ klog .InfoS ("feature does not match the allowlist" , "feature" , name , "regexp" , featureAllowList .String ())
573
+ continue
574
+ }
575
+ if featureDenyList .MatchString (name ) {
576
+ klog .InfoS ("feature matchs the denylist" , "feature" , name , "regexp" , featureDenyList .String ())
577
+ continue
578
+ }
579
+
567
580
switch sourceName := source .Name (); sourceName {
568
581
case "local" , "custom" :
569
582
// No mangling of labels from the custom rules or feature files
0 commit comments