@@ -77,14 +77,16 @@ type NFDConfig struct {
7777}
7878
7979type 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
8890}
8991
9092type sourcesConfig map [string ]source.Config
@@ -196,11 +198,13 @@ func NewNfdWorker(opts ...NfdWorkerOption) (NfdWorker, error) {
196198func newDefaultConfig () * NFDConfig {
197199 return & NFDConfig {
198200 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 ),
204208 },
205209 }
206210}
@@ -238,7 +242,7 @@ func (w *nfdWorker) runFeatureDiscovery() error {
238242 klog .InfoS ("feature discovery sources took over half of sleep interval " , "duration" , discoveryDuration , "sleepInterval" , w .config .Core .SleepInterval .Duration )
239243 }
240244 // 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 )
242246
243247 // Update the node with the feature labels.
244248 if ! w .config .Core .NoPublish {
@@ -531,13 +535,13 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
531535
532536// createFeatureLabels returns the set of feature labels from the enabled
533537// 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 ) {
535539 labels = Labels {}
536540
537541 // Get labels from all enabled label sources
538542 klog .InfoS ("starting feature discovery..." )
539543 for _ , source := range sources {
540- labelsFromSource , err := getFeatureLabels (source , labelWhiteList )
544+ labelsFromSource , err := getFeatureLabels (source , labelWhiteList , featureAllowList , featureDenyList )
541545 if err != nil {
542546 klog .ErrorS (err , "discovery failed" , "source" , source .Name ())
543547 continue
@@ -555,7 +559,7 @@ func createFeatureLabels(sources []source.LabelSource, labelWhiteList regexp.Reg
555559
556560// getFeatureLabels returns node labels for features discovered by the
557561// 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 ) {
559563 labels = Labels {}
560564 features , err := source .GetLabels ()
561565 if err != nil {
@@ -564,6 +568,15 @@ func getFeatureLabels(source source.LabelSource, labelWhiteList regexp.Regexp) (
564568
565569 for k , v := range features {
566570 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+
567580 switch sourceName := source .Name (); sourceName {
568581 case "local" , "custom" :
569582 // No mangling of labels from the custom rules or feature files
0 commit comments