diff --git a/docs/reference/feature-gates.md b/docs/reference/feature-gates.md index 85c0a2984f..d3e6ac18b6 100644 --- a/docs/reference/feature-gates.md +++ b/docs/reference/feature-gates.md @@ -16,7 +16,8 @@ The feature gates are set using the `-feature-gates` command line flag or | Name | Default | Stage | Since | Until | | --------------------- | ------- | ------ | ------- | ------ | -| `NodeFeatureAPI` | true | Beta | V0.14 | | +| `NodeFeatureAPI` | true | Beta | V0.14 | | +| `DisableAutoPrefix` | false | Alpha | V0.16 | | ## NodeFeatureAPI @@ -25,3 +26,27 @@ When enabled, NFD will register the Node Feature API with the Kubernetes API server. The Node Feature API is used to expose node-specific hardware and software features to the Kubernetes scheduler. The Node Feature API is a beta feature and is enabled by default. + +## DisableAutoPrefix + +The `DisableAutoPrefix` feature gate controls the automatic prefixing of names. +When enabled nfd-master does not automatically add the default +`feature.node.kubernetes.io/` prefix to unprefixed labels, annotations and +extended resources. Automatic prefixing is the default behavior in NFD v0.16 +and earlier. + +Note that enabling the feature gate effectively causes unprefixed names to be +filtered out as NFD does not allow unprefixed names of labels, annotations or +extended resources. For example, with the `DisableAutoPrefix` feature gate set +to `false`, a NodeFeatureRule with + +```yaml + labels: + foo: bar +``` + +will turn into `feature.node.kubernetes.io/foo=bar` node label. With +`DisableAutoPrefix` set to `true`, no prefix is added and the label will be +filtered out. + +Note that taint keys are not affected by this feature gate. diff --git a/docs/reference/master-configuration-reference.md b/docs/reference/master-configuration-reference.md index 6102489822..90980c5150 100644 --- a/docs/reference/master-configuration-reference.md +++ b/docs/reference/master-configuration-reference.md @@ -70,6 +70,9 @@ denyLabelNs: ["denied.ns.io","denied.kubernetes.io"] ## autoDefaultNs +**DEPRECATED**: Will be removed in NFD v0.17. Use the +[DisableAutoPrefix](feature-gates.md#disableautoprefix) feature gate instead. + The `autoDefaultNs` option controls the automatic prefixing of names. When set to true (the default in NFD version {{ site.version }}) nfd-master automatically adds the default `feature.node.kubernetes.io/` prefix to diff --git a/pkg/features/features.go b/pkg/features/features.go index 7c7ec24573..b619aa15d7 100644 --- a/pkg/features/features.go +++ b/pkg/features/features.go @@ -21,7 +21,8 @@ import ( ) const ( - NodeFeatureAPI featuregate.Feature = "NodeFeatureAPI" + NodeFeatureAPI featuregate.Feature = "NodeFeatureAPI" + DisableAutoPrefix featuregate.Feature = "DisableAutoPrefix" ) var ( @@ -33,5 +34,6 @@ var ( ) var DefaultNFDFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ - NodeFeatureAPI: {Default: true, PreRelease: featuregate.Beta}, + NodeFeatureAPI: {Default: true, PreRelease: featuregate.Beta}, + DisableAutoPrefix: {Default: false, PreRelease: featuregate.Alpha}, } diff --git a/pkg/nfd-master/nfd-master-internal_test.go b/pkg/nfd-master/nfd-master-internal_test.go index 7efdfa764a..024a0b3913 100644 --- a/pkg/nfd-master/nfd-master-internal_test.go +++ b/pkg/nfd-master/nfd-master-internal_test.go @@ -333,6 +333,10 @@ func TestRemovingExtResources(t *testing.T) { func TestSetLabels(t *testing.T) { Convey("When servicing SetLabels request", t, func() { + // Add feature gates as running nfd-master depends on that + err := features.NFDMutableFeatureGate.Add(features.DefaultNFDFeatureGates) + So(err, ShouldBeNil) + testNode := newTestNode() // We need to populate the node with some annotations or the patching in the fake client fails testNode.Labels["feature.node.kubernetes.io/foo"] = "bar" diff --git a/pkg/nfd-master/nfd-master.go b/pkg/nfd-master/nfd-master.go index d99a404834..ce2ee5b117 100644 --- a/pkg/nfd-master/nfd-master.go +++ b/pkg/nfd-master/nfd-master.go @@ -801,12 +801,12 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(cli k8sclient.Interface, node *corev1.No // NOTE: changing the rule api to support handle multiple objects instead // of merging would probably perform better with lot less data to copy. features = objs[0].Spec.DeepCopy() - if m.config.AutoDefaultNs { + if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) && m.config.AutoDefaultNs { features.Labels = addNsToMapKeys(features.Labels, nfdv1alpha1.FeatureLabelNs) } for _, o := range objs[1:] { s := o.Spec.DeepCopy() - if m.config.AutoDefaultNs { + if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) && m.config.AutoDefaultNs { s.Labels = addNsToMapKeys(s.Labels, nfdv1alpha1.FeatureLabelNs) } s.MergeInto(features) @@ -864,7 +864,7 @@ func filterExtendedResource(name, value string, features *nfdv1alpha1.Features) } func (m *nfdMaster) refreshNodeFeatures(cli k8sclient.Interface, node *corev1.Node, labels map[string]string, features *nfdv1alpha1.Features) error { - if m.config.AutoDefaultNs { + if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) && m.config.AutoDefaultNs { labels = addNsToMapKeys(labels, nfdv1alpha1.FeatureLabelNs) } else if labels == nil { labels = make(map[string]string) @@ -1041,7 +1041,7 @@ func (m *nfdMaster) processNodeFeatureRule(nodeName string, features *nfdv1alpha l := ruleOut.Labels e := ruleOut.ExtendedResources a := ruleOut.Annotations - if m.config.AutoDefaultNs { + if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) && m.config.AutoDefaultNs { l = addNsToMapKeys(ruleOut.Labels, nfdv1alpha1.FeatureLabelNs) e = addNsToMapKeys(ruleOut.ExtendedResources, nfdv1alpha1.ExtendedResourceNs) a = addNsToMapKeys(ruleOut.Annotations, nfdv1alpha1.FeatureAnnotationNs)