@@ -50,7 +50,7 @@ func analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollec
5050
5151 for _ , outcome := range analyzer .Outcomes {
5252 if outcome .Fail != nil {
53- isWhenMatch , err := compareNodeResourceConditionalToActual (outcome .Fail .When , matchingNodes , len ( nodes ) )
53+ isWhenMatch , err := compareNodeResourceConditionalToActual (outcome .Fail .When , matchingNodes )
5454 if err != nil {
5555 return nil , errors .Wrap (err , "failed to parse when" )
5656 }
@@ -63,7 +63,7 @@ func analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollec
6363 return result , nil
6464 }
6565 } else if outcome .Warn != nil {
66- isWhenMatch , err := compareNodeResourceConditionalToActual (outcome .Warn .When , matchingNodes , len ( nodes ) )
66+ isWhenMatch , err := compareNodeResourceConditionalToActual (outcome .Warn .When , matchingNodes )
6767 if err != nil {
6868 return nil , errors .Wrap (err , "failed to parse when" )
6969 }
@@ -76,7 +76,7 @@ func analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollec
7676 return result , nil
7777 }
7878 } else if outcome .Pass != nil {
79- isWhenMatch , err := compareNodeResourceConditionalToActual (outcome .Pass .When , matchingNodes , len ( nodes ) )
79+ isWhenMatch , err := compareNodeResourceConditionalToActual (outcome .Pass .When , matchingNodes )
8080 if err != nil {
8181 return nil , errors .Wrap (err , "failed to parse when" )
8282 }
@@ -94,7 +94,7 @@ func analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollec
9494 return result , nil
9595}
9696
97- func compareNodeResourceConditionalToActual (conditional string , matchingNodes []corev1.Node , totalNodeCount int ) (res bool , err error ) {
97+ func compareNodeResourceConditionalToActual (conditional string , matchingNodes []corev1.Node ) (res bool , err error ) {
9898 res = false
9999 err = nil
100100
@@ -159,6 +159,27 @@ func compareNodeResourceConditionalToActual(conditional string, matchingNodes []
159159 actualValue = findMax (matchingNodes , property )
160160 case "sum" :
161161 actualValue = findSum (matchingNodes , property )
162+ case "nodeCondition" :
163+ operatorChecker := regexp .MustCompile (`={1,3}` )
164+ if ! operatorChecker .MatchString (operator ) {
165+ err = errors .New ("nodeCondition function can only be compared using equals expression." )
166+ return
167+ }
168+ if match [2 ] == "" {
169+ err = errors .New ("value function parameter missing." )
170+ return
171+ }
172+
173+ for _ , node := range matchingNodes {
174+ for _ , condition := range node .Status .Conditions {
175+ if string (condition .Type ) == match [2 ] && condition .Status == desiredValue {
176+ res = true
177+ return
178+ }
179+ }
180+ }
181+ res = false
182+ return
162183 }
163184
164185 switch operator {
0 commit comments