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:
commit
6a101422ee
2 changed files with 29 additions and 19 deletions
|
@ -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
|
||||
// rule matches.
|
||||
func ExecuteGroupRule(r *nfdv1alpha1.GroupRule, features *nfdv1alpha1.Features, failFast bool) (bool, error) {
|
||||
matched := false
|
||||
if len(r.MatchAny) > 0 {
|
||||
func ExecuteGroupRule(r *nfdv1alpha1.GroupRule, features *nfdv1alpha1.Features, failFast bool) (MatchStatus, error) {
|
||||
var (
|
||||
matchStatus MatchStatus
|
||||
isMatch bool
|
||||
)
|
||||
if n := len(r.MatchAny); n > 0 {
|
||||
matchStatus.MatchAny = make([]*MatchFeatureStatus, 0, n)
|
||||
// Logical OR over the matchAny matchers
|
||||
for _, matcher := range r.MatchAny {
|
||||
if isMatch, matches, err := evaluateMatchAnyElem(&matcher, features, failFast); err != nil {
|
||||
return false, err
|
||||
} else if isMatch {
|
||||
matched = true
|
||||
klog.V(4).InfoS("matchAny matched", "ruleName", r.Name, "matchedFeatures", utils.DelayedDumper(matches))
|
||||
matched, featureStatus, err := evaluateMatchAnyElem(&matcher, features, failFast)
|
||||
if err != nil {
|
||||
return matchStatus, err
|
||||
} else if matched {
|
||||
isMatch = true
|
||||
klog.V(4).InfoS("matchAny matched", "ruleName", r.Name, "matchedFeatures", utils.DelayedDumper(featureStatus.MatchedFeatures))
|
||||
|
||||
if failFast {
|
||||
// there's no need to evaluate other matchers in MatchAny
|
||||
// One match is enough for MatchAny
|
||||
break
|
||||
}
|
||||
}
|
||||
if !matched {
|
||||
return false, nil
|
||||
matchStatus.MatchAny = append(matchStatus.MatchAny, featureStatus)
|
||||
}
|
||||
if !isMatch && failFast {
|
||||
return matchStatus, nil
|
||||
}
|
||||
}
|
||||
|
||||
if len(r.MatchFeatures) > 0 {
|
||||
if isMatch, _, err := evaluateFeatureMatcher(&r.MatchFeatures, features, failFast); err != nil {
|
||||
return false, err
|
||||
var err error
|
||||
if isMatch, matchStatus.MatchFeatureStatus, err = evaluateFeatureMatcher(&r.MatchFeatures, features, failFast); err != nil {
|
||||
return matchStatus, err
|
||||
} else if !isMatch {
|
||||
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)
|
||||
return true, nil
|
||||
return matchStatus, nil
|
||||
}
|
||||
|
||||
func executeTemplate(tmpl string, in matchedFeatures, out map[string]string) error {
|
||||
|
|
|
@ -742,8 +742,7 @@ func (m *nfdMaster) nfdAPIUpdateNodeFeatureGroup(nfdClient nfdclientset.Interfac
|
|||
continue
|
||||
}
|
||||
|
||||
if match {
|
||||
klog.ErrorS(err, "failed to evaluate rule", "ruleName", rule.Name, "nodeName", feature.Name)
|
||||
if match.IsMatch {
|
||||
system := feature.Spec.Features.Attributes["system.name"]
|
||||
nodeName := system.Elements["nodename"]
|
||||
if _, ok := nodeGroupValidator[nodeName]; !ok {
|
||||
|
|
Loading…
Add table
Reference in a new issue