Skip to content

Commit 1213454

Browse files
committed
nfd-master: add DisableAutoPrefix feature gate
Now that we have support for feature gates deprecate the autoDefaultNs config option of nfd-master and replace it with a new alpha feature gate DisableAutoPrefix (defaults to false). Using a feature gate to handle and communicate these kind of changes, where the default behavior is intended to be changed in a future release, feels much more natural than using random flags/options. The combined logic of the feature gate and the config option is a logical OR over disabling auto-prefixing. That is, auto-prefixing is disabled if either the feature gate or the config options is used set to disable it: | DisableAutoPrefix (feature gate) | false | true -------------------- | -------------------------------- autoDefaultNs true | ON | OFF (config opt) false | OFF | OFF
1 parent eb7a0ad commit 1213454

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

docs/reference/feature-gates.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ The feature gates are set using the `-feature-gates` command line flag or
1616

1717
| Name | Default | Stage | Since | Until |
1818
| --------------------- | ------- | ------ | ------- | ------ |
19-
| `NodeFeatureAPI` | true | Beta | V0.14 | |
19+
| `NodeFeatureAPI` | true | Beta | V0.14 | |
20+
| `DisableAutoPrefix` | false | Alpha | V0.16 | |
2021

2122
## NodeFeatureAPI
2223

@@ -25,3 +26,27 @@ When enabled, NFD will register the Node Feature API with the Kubernetes API
2526
server. The Node Feature API is used to expose node-specific hardware and
2627
software features to the Kubernetes scheduler. The Node Feature API is a beta
2728
feature and is enabled by default.
29+
30+
## DisableAutoPrefix
31+
32+
The `DisableAutoPrefix` feature gate controls the automatic prefixing of names.
33+
When enabled nfd-master does not automatically add the default
34+
`feature.node.kubernetes.io/` prefix to unprefixed labels, annotations and
35+
extended resources. Automatic prefixing is the default behavior in NFD v0.16
36+
and earlier.
37+
38+
Note that enabling the feature gate effectively causes unprefixed names to be
39+
filtered out as NFD does not allow unprefixed names of labels, annotations or
40+
extended resources. For example, with the `DisableAutoPrefix` feature gate set
41+
to `false`, a NodeFeatureRule with
42+
43+
```yaml
44+
labels:
45+
foo: bar
46+
```
47+
48+
will turn into `feature.node.kubernetes.io/foo=bar` node label. With
49+
`DisableAutoPrefix` set to `true`, no prefix is added and the label will be
50+
filtered out.
51+
52+
Note that taint keys are not affected by this feature gate.

docs/reference/master-configuration-reference.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ denyLabelNs: ["denied.ns.io","denied.kubernetes.io"]
7070

7171
## autoDefaultNs
7272

73+
**DEPRECATED**: Will be removed in NFD v0.17. Use the
74+
[DisableAutoPrefix](feature-gates.md#disableautoprefix) feature gate instead.
75+
7376
The `autoDefaultNs` option controls the automatic prefixing of names. When set
7477
to true (the default in NFD version {{ site.version }}) nfd-master
7578
automatically adds the default `feature.node.kubernetes.io/` prefix to

pkg/features/features.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
)
2222

2323
const (
24-
NodeFeatureAPI featuregate.Feature = "NodeFeatureAPI"
24+
NodeFeatureAPI featuregate.Feature = "NodeFeatureAPI"
25+
DisableAutoPrefix featuregate.Feature = "DisableAutoPrefix"
2526
)
2627

2728
var (
@@ -33,5 +34,6 @@ var (
3334
)
3435

3536
var DefaultNFDFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
36-
NodeFeatureAPI: {Default: true, PreRelease: featuregate.Beta},
37+
NodeFeatureAPI: {Default: true, PreRelease: featuregate.Beta},
38+
DisableAutoPrefix: {Default: false, PreRelease: featuregate.Alpha},
3739
}

pkg/nfd-master/nfd-master-internal_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ func TestRemovingExtResources(t *testing.T) {
333333

334334
func TestSetLabels(t *testing.T) {
335335
Convey("When servicing SetLabels request", t, func() {
336+
// Add feature gates as running nfd-master depends on that
337+
err := features.NFDMutableFeatureGate.Add(features.DefaultNFDFeatureGates)
338+
So(err, ShouldBeNil)
339+
336340
testNode := newTestNode()
337341
// We need to populate the node with some annotations or the patching in the fake client fails
338342
testNode.Labels["feature.node.kubernetes.io/foo"] = "bar"

pkg/nfd-master/nfd-master.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,12 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(cli k8sclient.Interface, node *corev1.No
801801
// NOTE: changing the rule api to support handle multiple objects instead
802802
// of merging would probably perform better with lot less data to copy.
803803
features = objs[0].Spec.DeepCopy()
804-
if m.config.AutoDefaultNs {
804+
if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) && m.config.AutoDefaultNs {
805805
features.Labels = addNsToMapKeys(features.Labels, nfdv1alpha1.FeatureLabelNs)
806806
}
807807
for _, o := range objs[1:] {
808808
s := o.Spec.DeepCopy()
809-
if m.config.AutoDefaultNs {
809+
if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) && m.config.AutoDefaultNs {
810810
s.Labels = addNsToMapKeys(s.Labels, nfdv1alpha1.FeatureLabelNs)
811811
}
812812
s.MergeInto(features)
@@ -864,7 +864,7 @@ func filterExtendedResource(name, value string, features *nfdv1alpha1.Features)
864864
}
865865

866866
func (m *nfdMaster) refreshNodeFeatures(cli k8sclient.Interface, node *corev1.Node, labels map[string]string, features *nfdv1alpha1.Features) error {
867-
if m.config.AutoDefaultNs {
867+
if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) && m.config.AutoDefaultNs {
868868
labels = addNsToMapKeys(labels, nfdv1alpha1.FeatureLabelNs)
869869
} else if labels == nil {
870870
labels = make(map[string]string)
@@ -1041,7 +1041,7 @@ func (m *nfdMaster) processNodeFeatureRule(nodeName string, features *nfdv1alpha
10411041
l := ruleOut.Labels
10421042
e := ruleOut.ExtendedResources
10431043
a := ruleOut.Annotations
1044-
if m.config.AutoDefaultNs {
1044+
if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) && m.config.AutoDefaultNs {
10451045
l = addNsToMapKeys(ruleOut.Labels, nfdv1alpha1.FeatureLabelNs)
10461046
e = addNsToMapKeys(ruleOut.ExtendedResources, nfdv1alpha1.ExtendedResourceNs)
10471047
a = addNsToMapKeys(ruleOut.Annotations, nfdv1alpha1.FeatureAnnotationNs)

0 commit comments

Comments
 (0)