Skip to content

Commit 5d9f14f

Browse files
authored
Merge pull request #474 from replicatedhq/add-node-status-check
38798: Adding node status check
2 parents 1446364 + 1345b20 commit 5d9f14f

12 files changed

+744
-5
lines changed

config/crds/troubleshoot.sh_analyzers.yaml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,53 @@ spec:
485485
- namespace
486486
- outcomes
487487
type: object
488+
jobStatus:
489+
properties:
490+
checkName:
491+
type: string
492+
exclude:
493+
type: BoolString
494+
name:
495+
type: string
496+
namespace:
497+
type: string
498+
outcomes:
499+
items:
500+
properties:
501+
fail:
502+
properties:
503+
message:
504+
type: string
505+
uri:
506+
type: string
507+
when:
508+
type: string
509+
type: object
510+
pass:
511+
properties:
512+
message:
513+
type: string
514+
uri:
515+
type: string
516+
when:
517+
type: string
518+
type: object
519+
warn:
520+
properties:
521+
message:
522+
type: string
523+
uri:
524+
type: string
525+
when:
526+
type: string
527+
type: object
528+
type: object
529+
type: array
530+
required:
531+
- name
532+
- namespace
533+
- outcomes
534+
type: object
488535
longhorn:
489536
properties:
490537
checkName:
@@ -780,6 +827,53 @@ spec:
780827
- collectorName
781828
- outcomes
782829
type: object
830+
replicasetStatus:
831+
properties:
832+
checkName:
833+
type: string
834+
exclude:
835+
type: BoolString
836+
name:
837+
type: string
838+
namespace:
839+
type: string
840+
outcomes:
841+
items:
842+
properties:
843+
fail:
844+
properties:
845+
message:
846+
type: string
847+
uri:
848+
type: string
849+
when:
850+
type: string
851+
type: object
852+
pass:
853+
properties:
854+
message:
855+
type: string
856+
uri:
857+
type: string
858+
when:
859+
type: string
860+
type: object
861+
warn:
862+
properties:
863+
message:
864+
type: string
865+
uri:
866+
type: string
867+
when:
868+
type: string
869+
type: object
870+
type: object
871+
type: array
872+
required:
873+
- name
874+
- namespace
875+
- outcomes
876+
type: object
783877
secret:
784878
properties:
785879
checkName:

config/crds/troubleshoot.sh_preflights.yaml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,53 @@ spec:
485485
- namespace
486486
- outcomes
487487
type: object
488+
jobStatus:
489+
properties:
490+
checkName:
491+
type: string
492+
exclude:
493+
type: BoolString
494+
name:
495+
type: string
496+
namespace:
497+
type: string
498+
outcomes:
499+
items:
500+
properties:
501+
fail:
502+
properties:
503+
message:
504+
type: string
505+
uri:
506+
type: string
507+
when:
508+
type: string
509+
type: object
510+
pass:
511+
properties:
512+
message:
513+
type: string
514+
uri:
515+
type: string
516+
when:
517+
type: string
518+
type: object
519+
warn:
520+
properties:
521+
message:
522+
type: string
523+
uri:
524+
type: string
525+
when:
526+
type: string
527+
type: object
528+
type: object
529+
type: array
530+
required:
531+
- name
532+
- namespace
533+
- outcomes
534+
type: object
488535
longhorn:
489536
properties:
490537
checkName:
@@ -780,6 +827,53 @@ spec:
780827
- collectorName
781828
- outcomes
782829
type: object
830+
replicasetStatus:
831+
properties:
832+
checkName:
833+
type: string
834+
exclude:
835+
type: BoolString
836+
name:
837+
type: string
838+
namespace:
839+
type: string
840+
outcomes:
841+
items:
842+
properties:
843+
fail:
844+
properties:
845+
message:
846+
type: string
847+
uri:
848+
type: string
849+
when:
850+
type: string
851+
type: object
852+
pass:
853+
properties:
854+
message:
855+
type: string
856+
uri:
857+
type: string
858+
when:
859+
type: string
860+
type: object
861+
warn:
862+
properties:
863+
message:
864+
type: string
865+
uri:
866+
type: string
867+
when:
868+
type: string
869+
type: object
870+
type: object
871+
type: array
872+
required:
873+
- name
874+
- namespace
875+
- outcomes
876+
type: object
783877
secret:
784878
properties:
785879
checkName:

config/crds/troubleshoot.sh_supportbundles.yaml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,53 @@ spec:
516516
- namespace
517517
- outcomes
518518
type: object
519+
jobStatus:
520+
properties:
521+
checkName:
522+
type: string
523+
exclude:
524+
type: BoolString
525+
name:
526+
type: string
527+
namespace:
528+
type: string
529+
outcomes:
530+
items:
531+
properties:
532+
fail:
533+
properties:
534+
message:
535+
type: string
536+
uri:
537+
type: string
538+
when:
539+
type: string
540+
type: object
541+
pass:
542+
properties:
543+
message:
544+
type: string
545+
uri:
546+
type: string
547+
when:
548+
type: string
549+
type: object
550+
warn:
551+
properties:
552+
message:
553+
type: string
554+
uri:
555+
type: string
556+
when:
557+
type: string
558+
type: object
559+
type: object
560+
type: array
561+
required:
562+
- name
563+
- namespace
564+
- outcomes
565+
type: object
519566
longhorn:
520567
properties:
521568
checkName:
@@ -811,6 +858,53 @@ spec:
811858
- collectorName
812859
- outcomes
813860
type: object
861+
replicasetStatus:
862+
properties:
863+
checkName:
864+
type: string
865+
exclude:
866+
type: BoolString
867+
name:
868+
type: string
869+
namespace:
870+
type: string
871+
outcomes:
872+
items:
873+
properties:
874+
fail:
875+
properties:
876+
message:
877+
type: string
878+
uri:
879+
type: string
880+
when:
881+
type: string
882+
type: object
883+
pass:
884+
properties:
885+
message:
886+
type: string
887+
uri:
888+
type: string
889+
when:
890+
type: string
891+
type: object
892+
warn:
893+
properties:
894+
message:
895+
type: string
896+
uri:
897+
type: string
898+
when:
899+
type: string
900+
type: object
901+
type: object
902+
type: array
903+
required:
904+
- name
905+
- namespace
906+
- outcomes
907+
type: object
814908
secret:
815909
properties:
816910
checkName:

pkg/analyze/node_resources.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

pkg/analyze/node_resources_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func Test_compareNodeResourceConditionalToActual(t *testing.T) {
371371
t.Run(test.name, func(t *testing.T) {
372372
req := require.New(t)
373373

374-
actual, err := compareNodeResourceConditionalToActual(test.conditional, test.matchingNodes, test.totalNodeCount)
374+
actual, err := compareNodeResourceConditionalToActual(test.conditional, test.matchingNodes)
375375
if test.isError {
376376
req.Error(err)
377377
} else {

0 commit comments

Comments
 (0)