@@ -149,37 +149,48 @@ func Execute(r *nfdv1alpha1.Rule, features *nfdv1alpha1.Features, failFast bool)
149149
150150// ExecuteGroupRule executes the GroupRule against a set of input features, and return true if the
151151// rule matches.
152- func ExecuteGroupRule (r * nfdv1alpha1.GroupRule , features * nfdv1alpha1.Features , failFast bool ) (bool , error ) {
153- matched := false
154- if len (r .MatchAny ) > 0 {
152+ func ExecuteGroupRule (r * nfdv1alpha1.GroupRule , features * nfdv1alpha1.Features , failFast bool ) (MatchStatus , error ) {
153+ var (
154+ matchStatus MatchStatus
155+ isMatch bool
156+ )
157+ if n := len (r .MatchAny ); n > 0 {
158+ matchStatus .MatchAny = make ([]* MatchFeatureStatus , 0 , n )
155159 // Logical OR over the matchAny matchers
156160 for _ , matcher := range r .MatchAny {
157- if isMatch , matches , err := evaluateMatchAnyElem (& matcher , features , failFast ); err != nil {
158- return false , err
159- } else if isMatch {
160- matched = true
161- klog .V (4 ).InfoS ("matchAny matched" , "ruleName" , r .Name , "matchedFeatures" , utils .DelayedDumper (matches ))
162- // there's no need to evaluate other matchers in MatchAny
163- // One match is enough for MatchAny
164- break
161+ matched , featureStatus , err := evaluateMatchAnyElem (& matcher , features , failFast )
162+ if err != nil {
163+ return matchStatus , err
164+ } else if matched {
165+ isMatch = true
166+ klog .V (4 ).InfoS ("matchAny matched" , "ruleName" , r .Name , "matchedFeatures" , utils .DelayedDumper (featureStatus .MatchedFeatures ))
167+
168+ if failFast {
169+ // there's no need to evaluate other matchers in MatchAny
170+ break
171+ }
165172 }
173+ matchStatus .MatchAny = append (matchStatus .MatchAny , featureStatus )
166174 }
167- if ! matched {
168- return false , nil
175+ if ! isMatch && failFast {
176+ return matchStatus , nil
169177 }
170178 }
171179
172180 if len (r .MatchFeatures ) > 0 {
173- if isMatch , _ , err := evaluateFeatureMatcher (& r .MatchFeatures , features , failFast ); err != nil {
174- return false , err
181+ var err error
182+ if isMatch , matchStatus .MatchFeatureStatus , err = evaluateFeatureMatcher (& r .MatchFeatures , features , failFast ); err != nil {
183+ return matchStatus , err
175184 } else if ! isMatch {
176185 klog .V (2 ).InfoS ("rule did not match" , "ruleName" , r .Name )
177- return false , nil
186+ return matchStatus , nil
178187 }
179188 }
180189
190+ matchStatus .IsMatch = true
191+
181192 klog .V (2 ).InfoS ("rule matched" , "ruleName" , r .Name )
182- return true , nil
193+ return matchStatus , nil
183194}
184195
185196func executeLabelsTemplate (r * nfdv1alpha1.Rule , in matchedFeatures , out map [string ]string ) error {
0 commit comments