1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-04-24 05:07:11 +00:00

Merge pull request from stek29/fix-864

Fix templates for NodeFeatureRule with MatchAny
This commit is contained in:
Kubernetes Prow Robot 2022-08-23 09:55:24 -07:00 committed by GitHub
commit 4e6a718dfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions
pkg/apis/nfd/v1alpha1

View file

@ -50,11 +50,13 @@ func (r *Rule) Execute(features feature.Features) (RuleOutput, error) {
matched = true
utils.KlogDump(4, "matches for matchAny "+r.Name, " ", matches)
if r.labelsTemplate == nil {
// No templating so we stop here (further matches would just
// produce the same labels)
if r.LabelsTemplate == "" && r.VarsTemplate == "" {
// there's no need to evaluate other matchers in MatchAny
// if there are no templates to be executed on them - so
// short-circuit and stop on first match here
break
}
if err := r.executeLabelsTemplate(matches, labels); err != nil {
return RuleOutput{}, err
}

View file

@ -297,6 +297,11 @@ var-2=
},
}
// test with empty MatchFeatures, but with MatchAny
r3 := r1.DeepCopy()
r3.MatchAny = []MatchAnyElem{{MatchFeatures: r3.MatchFeatures}}
r3.MatchFeatures = nil
expectedLabels := map[string]string{
"label-1": "label-val-1",
"label-2": "",
@ -325,6 +330,11 @@ var-2=
assert.Equal(t, expectedLabels, m.Labels, "instances should have matched")
assert.Equal(t, expectedVars, m.Vars, "instances should have matched")
m, err = r3.Execute(f)
assert.Nilf(t, err, "unexpected error: %v", err)
assert.Equal(t, expectedLabels, m.Labels, "instances should have matched")
assert.Equal(t, expectedVars, m.Vars, "instances should have matched")
//
// Test error cases
//