Skip to content

Commit 19f6b4f

Browse files
authored
Merge pull request #2068 from mfranczy/bugfix-compatibility-processing
Bugfix: handle matchAny and matchFeatures when they appear in one spec
2 parents e7deb5c + efc86e9 commit 19f6b4f

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

pkg/apis/nfd/nodefeaturerule/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Execute(r *nfdv1alpha1.Rule, features *nfdv1alpha1.Features, failFast bool)
108108
matchStatus.MatchAny = append(matchStatus.MatchAny, featureStatus)
109109
}
110110

111-
if !isMatch {
111+
if !isMatch && failFast {
112112
klog.V(2).InfoS("rule did not match", "ruleName", r.Name)
113113
return RuleOutput{MatchStatus: &matchStatus}, nil
114114
}

pkg/client-nfd/compat/node-validator/node-validator_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,86 @@ func TestNodeValidator(t *testing.T) {
311311
assertOutput(ctx, spec, expectedOutput)
312312
})
313313

314+
Convey("That contains matchAny and matchFeatures in one spec", func() {
315+
spec := buildDefaultSpec([]v1alpha1.Rule{
316+
{
317+
Name: "fake_6",
318+
MatchAny: []v1alpha1.MatchAnyElem{
319+
{
320+
MatchFeatures: v1alpha1.FeatureMatcher{
321+
{
322+
Feature: "fake.instance",
323+
MatchExpressions: &v1alpha1.MatchExpressionSet{
324+
"name": &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"instance_1"}},
325+
},
326+
},
327+
},
328+
},
329+
{
330+
MatchFeatures: v1alpha1.FeatureMatcher{
331+
{
332+
Feature: "fake.instance",
333+
MatchExpressions: &v1alpha1.MatchExpressionSet{
334+
"name": &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"instance_unknown"}},
335+
},
336+
},
337+
},
338+
},
339+
},
340+
MatchFeatures: v1alpha1.FeatureMatcher{
341+
{
342+
Feature: "fake.attribute",
343+
MatchExpressions: &v1alpha1.MatchExpressionSet{
344+
"attr_1": &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"true"}},
345+
},
346+
},
347+
},
348+
},
349+
})
350+
351+
expectedOutput := buildDefaultExpectedOutput([]ProcessedRuleStatus{
352+
{
353+
Name: "fake_6",
354+
IsMatch: true,
355+
MatchedAny: []MatchAnyElem{
356+
{
357+
MatchedExpressions: []MatchedExpression{
358+
{
359+
Feature: "fake.instance",
360+
Name: "name",
361+
Expression: &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"instance_1"}},
362+
MatcherType: MatchExpressionType,
363+
IsMatch: true,
364+
},
365+
},
366+
},
367+
{
368+
MatchedExpressions: []MatchedExpression{
369+
{
370+
Feature: "fake.instance",
371+
Name: "name",
372+
Expression: &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"instance_unknown"}},
373+
MatcherType: MatchExpressionType,
374+
IsMatch: false,
375+
},
376+
},
377+
},
378+
},
379+
MatchedExpressions: []MatchedExpression{
380+
{
381+
Feature: "fake.attribute",
382+
Name: "attr_1",
383+
Expression: &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"true"}},
384+
MatcherType: MatchExpressionType,
385+
IsMatch: true,
386+
},
387+
},
388+
},
389+
})
390+
391+
assertOutput(ctx, spec, expectedOutput)
392+
})
393+
314394
})
315395

316396
Convey("With multiple compatibility sets", t, func() {

0 commit comments

Comments
 (0)