Skip to content

Commit 81eec09

Browse files
authored
Merge pull request #2114 from fmuyassarov/ns-drop
Enable unprefixed label setting via feature gate
2 parents bfc2893 + 881642e commit 81eec09

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

docs/reference/feature-gates.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ to `false`, a NodeFeatureRule with
5555
foo: bar
5656
```
5757
58-
will turn into `feature.node.kubernetes.io/foo=bar` node label. With
59-
`DisableAutoPrefix` set to `true`, no prefix is added and the label will be
60-
filtered out.
61-
62-
Note that taint keys are not affected by this feature gate.
58+
will be automatically prefixed, resulting in the node label
59+
`feature.node.kubernetes.io/foo=bar`. However, when `DisableAutoPrefix` is set
60+
to `true`, no prefix is added, and the label remains as `foo=bar`. Note that
61+
taint keys are not affected by this feature gate.

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,33 @@ func newFakeMaster(opts ...NfdMasterOption) *nfdMaster {
134134
return m.(*nfdMaster)
135135
}
136136

137+
func newFakeMasterWithFeatureGate(opts ...NfdMasterOption) *nfdMaster {
138+
nfdCli := fakenfdclient.NewSimpleClientset()
139+
defaultOpts := []NfdMasterOption{
140+
withNodeName(testNodeName),
141+
withConfig(&NFDConfig{Restrictions: Restrictions{AllowOverwrite: true}}),
142+
WithKubernetesClient(fakeclient.NewSimpleClientset()),
143+
withNFDClient(nfdCli),
144+
}
145+
m, err := NewNfdMaster(append(defaultOpts, opts...)...)
146+
if err != nil {
147+
panic(err)
148+
}
149+
// Add FeatureGates
150+
if err := features.NFDMutableFeatureGate.Add(features.DefaultNFDFeatureGates); err != nil {
151+
panic(err)
152+
}
153+
if err := features.NFDMutableFeatureGate.Set("DisableAutoPrefix=true"); err != nil {
154+
panic(err)
155+
}
156+
// Enable DisableAutoPrefix feature gate
157+
if !features.NFDFeatureGate.Enabled(features.DisableAutoPrefix) {
158+
err = errors.New("DisableAutoPrefix feature gate is not enabled")
159+
panic(err)
160+
}
161+
return m.(*nfdMaster)
162+
}
163+
137164
func TestUpdateNodeObject(t *testing.T) {
138165
Convey("When I update the node using fake client", t, func() {
139166
featureLabels := map[string]string{
@@ -432,6 +459,28 @@ func TestFilterLabels(t *testing.T) {
432459
}
433460
})
434461
}
462+
// Create a new fake master with the feature gate enabled
463+
fakeMaster = newFakeMasterWithFeatureGate()
464+
tcs = []TC{
465+
{
466+
description: "Unprefixed should be allowed",
467+
labelName: "test-label",
468+
labelValue: "test-value",
469+
expectedValue: "test-value",
470+
},
471+
}
472+
for _, tc := range tcs {
473+
t.Run(tc.description, func(t *testing.T) {
474+
labelValue, err := fakeMaster.filterFeatureLabel(tc.labelName, tc.labelValue, &tc.features)
475+
476+
Convey("Label should not be filtered out", t, func() {
477+
So(err, ShouldBeNil)
478+
})
479+
Convey("Label value should be correct", t, func() {
480+
So(labelValue, ShouldEqual, tc.expectedValue)
481+
})
482+
})
483+
}
435484
}
436485

437486
func TestCreatePatches(t *testing.T) {

pkg/nfd-master/nfd-master.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ func (m *nfdMaster) filterFeatureLabels(labels Labels, features *nfdv1alpha1.Fea
485485

486486
return outLabels
487487
}
488-
489488
func (m *nfdMaster) filterFeatureLabel(name, value string, features *nfdv1alpha1.Features) (string, error) {
490489
// Check if Value is dynamic
491490
var filteredValue string
@@ -507,7 +506,9 @@ func (m *nfdMaster) filterFeatureLabel(name, value string, features *nfdv1alpha1
507506
return "", fmt.Errorf("namespace %q is not allowed", ns)
508507
}
509508
} else if err != nil {
510-
return "", err
509+
if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) || err != validate.ErrUnprefixedKeysNotAllowed {
510+
return "", err
511+
}
511512
}
512513

513514
// Skip if label doesn't match labelWhiteList

0 commit comments

Comments
 (0)