@@ -149,37 +149,48 @@ func Execute(r *nfdv1alpha1.Rule, features *nfdv1alpha1.Features, failFast bool)
149
149
150
150
// ExecuteGroupRule executes the GroupRule against a set of input features, and return true if the
151
151
// 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 )
155
159
// Logical OR over the matchAny matchers
156
160
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
+ }
165
172
}
173
+ matchStatus .MatchAny = append (matchStatus .MatchAny , featureStatus )
166
174
}
167
- if ! matched {
168
- return false , nil
175
+ if ! isMatch && failFast {
176
+ return matchStatus , nil
169
177
}
170
178
}
171
179
172
180
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
175
184
} else if ! isMatch {
176
185
klog .V (2 ).InfoS ("rule did not match" , "ruleName" , r .Name )
177
- return false , nil
186
+ return matchStatus , nil
178
187
}
179
188
}
180
189
190
+ matchStatus .IsMatch = true
191
+
181
192
klog .V (2 ).InfoS ("rule matched" , "ruleName" , r .Name )
182
- return true , nil
193
+ return matchStatus , nil
183
194
}
184
195
185
196
func executeLabelsTemplate (r * nfdv1alpha1.Rule , in matchedFeatures , out map [string ]string ) error {
0 commit comments