1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-17 13:58:21 +00:00

Merge pull request #2065 from marquiz/devel/node-feature-group-match-status

Change ExecuteGroupRule to return detailed result
This commit is contained in:
Kubernetes Prow Robot 2025-03-06 05:03:44 -08:00 committed by GitHub
commit 6a101422ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 19 deletions

View file

@ -149,37 +149,48 @@ func Execute(r *nfdv1alpha1.Rule, features *nfdv1alpha1.Features, failFast bool)
// ExecuteGroupRule executes the GroupRule against a set of input features, and return true if the // ExecuteGroupRule executes the GroupRule against a set of input features, and return true if the
// rule matches. // rule matches.
func ExecuteGroupRule(r *nfdv1alpha1.GroupRule, features *nfdv1alpha1.Features, failFast bool) (bool, error) { func ExecuteGroupRule(r *nfdv1alpha1.GroupRule, features *nfdv1alpha1.Features, failFast bool) (MatchStatus, error) {
matched := false var (
if len(r.MatchAny) > 0 { matchStatus MatchStatus
isMatch bool
)
if n := len(r.MatchAny); n > 0 {
matchStatus.MatchAny = make([]*MatchFeatureStatus, 0, n)
// Logical OR over the matchAny matchers // Logical OR over the matchAny matchers
for _, matcher := range r.MatchAny { for _, matcher := range r.MatchAny {
if isMatch, matches, err := evaluateMatchAnyElem(&matcher, features, failFast); err != nil { matched, featureStatus, err := evaluateMatchAnyElem(&matcher, features, failFast)
return false, err if err != nil {
} else if isMatch { return matchStatus, err
matched = true } else if matched {
klog.V(4).InfoS("matchAny matched", "ruleName", r.Name, "matchedFeatures", utils.DelayedDumper(matches)) isMatch = true
// there's no need to evaluate other matchers in MatchAny klog.V(4).InfoS("matchAny matched", "ruleName", r.Name, "matchedFeatures", utils.DelayedDumper(featureStatus.MatchedFeatures))
// One match is enough for MatchAny
break if failFast {
// there's no need to evaluate other matchers in MatchAny
break
}
} }
matchStatus.MatchAny = append(matchStatus.MatchAny, featureStatus)
} }
if !matched { if !isMatch && failFast {
return false, nil return matchStatus, nil
} }
} }
if len(r.MatchFeatures) > 0 { if len(r.MatchFeatures) > 0 {
if isMatch, _, err := evaluateFeatureMatcher(&r.MatchFeatures, features, failFast); err != nil { var err error
return false, err if isMatch, matchStatus.MatchFeatureStatus, err = evaluateFeatureMatcher(&r.MatchFeatures, features, failFast); err != nil {
return matchStatus, err
} else if !isMatch { } else if !isMatch {
klog.V(2).InfoS("rule did not match", "ruleName", r.Name) klog.V(2).InfoS("rule did not match", "ruleName", r.Name)
return false, nil return matchStatus, nil
} }
} }
matchStatus.IsMatch = true
klog.V(2).InfoS("rule matched", "ruleName", r.Name) klog.V(2).InfoS("rule matched", "ruleName", r.Name)
return true, nil return matchStatus, nil
} }
func executeTemplate(tmpl string, in matchedFeatures, out map[string]string) error { func executeTemplate(tmpl string, in matchedFeatures, out map[string]string) error {

View file

@ -742,8 +742,7 @@ func (m *nfdMaster) nfdAPIUpdateNodeFeatureGroup(nfdClient nfdclientset.Interfac
continue continue
} }
if match { if match.IsMatch {
klog.ErrorS(err, "failed to evaluate rule", "ruleName", rule.Name, "nodeName", feature.Name)
system := feature.Spec.Features.Attributes["system.name"] system := feature.Spec.Features.Attributes["system.name"]
nodeName := system.Elements["nodename"] nodeName := system.Elements["nodename"]
if _, ok := nodeGroupValidator[nodeName]; !ok { if _, ok := nodeGroupValidator[nodeName]; !ok {