Skip to content

Enable unprefixed label setting via feature gate #2114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docs/reference/feature-gates.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ to `false`, a NodeFeatureRule with
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.
will be automatically prefixed, resulting in the node label
`feature.node.kubernetes.io/foo=bar`. However, when `DisableAutoPrefix` is set
to `true`, no prefix is added, and the label remains as `foo=bar`. Note that
taint keys are not affected by this feature gate.
49 changes: 49 additions & 0 deletions pkg/nfd-master/nfd-master-internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@ func newFakeMaster(opts ...NfdMasterOption) *nfdMaster {
return m.(*nfdMaster)
}

func newFakeMasterWithFeatureGate(opts ...NfdMasterOption) *nfdMaster {
nfdCli := fakenfdclient.NewSimpleClientset()
defaultOpts := []NfdMasterOption{
withNodeName(testNodeName),
withConfig(&NFDConfig{Restrictions: Restrictions{AllowOverwrite: true}}),
WithKubernetesClient(fakeclient.NewSimpleClientset()),
withNFDClient(nfdCli),
}
m, err := NewNfdMaster(append(defaultOpts, opts...)...)
if err != nil {
panic(err)
}
// Add FeatureGates
if err := features.NFDMutableFeatureGate.Add(features.DefaultNFDFeatureGates); err != nil {
panic(err)
}
if err := features.NFDMutableFeatureGate.Set("DisableAutoPrefix=true"); err != nil {
panic(err)
}
// Enable DisableAutoPrefix feature gate
if !features.NFDFeatureGate.Enabled(features.DisableAutoPrefix) {
err = errors.New("DisableAutoPrefix feature gate is not enabled")
panic(err)
}
return m.(*nfdMaster)
}

func TestUpdateNodeObject(t *testing.T) {
Convey("When I update the node using fake client", t, func() {
featureLabels := map[string]string{
Expand Down Expand Up @@ -432,6 +459,28 @@ func TestFilterLabels(t *testing.T) {
}
})
}
// Create a new fake master with the feature gate enabled
fakeMaster = newFakeMasterWithFeatureGate()
tcs = []TC{
{
description: "Unprefixed should be allowed",
labelName: "test-label",
labelValue: "test-value",
expectedValue: "test-value",
},
}
for _, tc := range tcs {
t.Run(tc.description, func(t *testing.T) {
labelValue, err := fakeMaster.filterFeatureLabel(tc.labelName, tc.labelValue, &tc.features)

Convey("Label should not be filtered out", t, func() {
So(err, ShouldBeNil)
})
Convey("Label value should be correct", t, func() {
So(labelValue, ShouldEqual, tc.expectedValue)
})
})
}
}

func TestCreatePatches(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ func (m *nfdMaster) filterFeatureLabels(labels Labels, features *nfdv1alpha1.Fea

return outLabels
}

func (m *nfdMaster) filterFeatureLabel(name, value string, features *nfdv1alpha1.Features) (string, error) {
// Check if Value is dynamic
var filteredValue string
Expand All @@ -504,7 +503,9 @@ func (m *nfdMaster) filterFeatureLabel(name, value string, features *nfdv1alpha1
return "", fmt.Errorf("namespace %q is not allowed", ns)
}
} else if err != nil {
return "", err
if !nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.DisableAutoPrefix) || err != validate.ErrUnprefixedKeysNotAllowed {
return "", err
}
}

// Skip if label doesn't match labelWhiteList
Expand Down