mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-04-24 05:07:11 +00:00
Merge pull request #865 from stek29/fix-864
Fix templates for NodeFeatureRule with MatchAny
This commit is contained in:
commit
4e6a718dfe
2 changed files with 15 additions and 3 deletions
pkg/apis/nfd/v1alpha1
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue