Skip to content

Commit 942234d

Browse files
author
Pavan Sokke Nagaraj
authored
Add strict flag to Analyzers and ResultAnalyzers (#539)
* add strict flag to Analyzer/AnalyzerMeta and regenerate schemas and controller-gen code * map analyzer strict to result * Update stdout for human and json format * fix review comment * update interactive result * update interactive results * Update types.go * Update upload_results.go * print strict when only true
1 parent 0a2ed01 commit 942234d

17 files changed

+576
-20
lines changed

cmd/preflight/cli/interactive_results.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func drawPreflightTable(analyzeResults []*analyzerunner.AnalyzeResult) {
139139

140140
for i, analyzeResult := range analyzeResults {
141141
title := analyzeResult.Title
142+
if analyzeResult.Strict {
143+
title = title + fmt.Sprintf(" (Strict: %t)", analyzeResult.Strict)
144+
}
142145
if analyzeResult.IsPass {
143146
title = fmt.Sprintf("✔ %s", title)
144147
} else if analyzeResult.IsWarn {
@@ -255,6 +258,10 @@ func save(preflightName string, outputPath string, analyzeResults []*analyzerunn
255258
result = result + fmt.Sprintf("URI: %s\n", analyzeResult.URI)
256259
}
257260

261+
if analyzeResult.Strict {
262+
result = result + fmt.Sprintf("Strict: %t\n", analyzeResult.Strict)
263+
}
264+
258265
result = result + "\n------------\n"
259266

260267
results = results + result

cmd/preflight/cli/stdout_results.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func showStdoutResultsJSON(preflightName string, analyzeResults []*analyzerunner
4242
Title string `json:"title"`
4343
Message string `json:"message"`
4444
URI string `json:"uri,omitempty"`
45+
Strict bool `json:"strict,omitempty"`
4546
}
4647
type Output struct {
4748
Pass []ResultOutput `json:"pass,omitempty"`
@@ -62,6 +63,10 @@ func showStdoutResultsJSON(preflightName string, analyzeResults []*analyzerunner
6263
URI: analyzeResult.URI,
6364
}
6465

66+
if analyzeResult.Strict {
67+
resultOutput.Strict = analyzeResult.Strict
68+
}
69+
6570
if analyzeResult.IsPass {
6671
output.Pass = append(output.Pass, resultOutput)
6772
} else if analyzeResult.IsWarn {
@@ -91,6 +96,13 @@ func outputResult(analyzeResult *analyzerunner.AnalyzeResult) bool {
9196
} else if analyzeResult.IsFail {
9297
fmt.Printf(" --- FAIL: %s\n", analyzeResult.Title)
9398
fmt.Printf(" --- %s\n", analyzeResult.Message)
99+
}
100+
101+
if analyzeResult.Strict {
102+
fmt.Printf(" --- Strict: %t\n", analyzeResult.Strict)
103+
}
104+
105+
if analyzeResult.IsFail {
94106
return true
95107
}
96108
return false

cmd/preflight/cli/upload_results.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func uploadResults(uri string, analyzeResults []*analyzerunner.AnalyzeResult) er
1717
}
1818
for _, analyzeResult := range analyzeResults {
1919
uploadPreflightResult := &preflight.UploadPreflightResult{
20+
Strict: analyzeResult.Strict,
2021
IsFail: analyzeResult.IsFail,
2122
IsWarn: analyzeResult.IsWarn,
2223
IsPass: analyzeResult.IsPass,

config/crds/troubleshoot.sh_analyzers.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ spec:
8181
type: object
8282
type: object
8383
type: array
84+
strict:
85+
type: BoolString
8486
required:
8587
- namespace
8688
- outcomes
@@ -127,6 +129,8 @@ spec:
127129
type: object
128130
type: object
129131
type: array
132+
strict:
133+
type: BoolString
130134
required:
131135
- outcomes
132136
type: object
@@ -168,6 +172,8 @@ spec:
168172
type: object
169173
type: object
170174
type: array
175+
strict:
176+
type: BoolString
171177
required:
172178
- outcomes
173179
type: object
@@ -215,6 +221,8 @@ spec:
215221
type: object
216222
type: object
217223
type: array
224+
strict:
225+
type: BoolString
218226
required:
219227
- configMapName
220228
- namespace
@@ -258,6 +266,8 @@ spec:
258266
type: object
259267
type: object
260268
type: array
269+
strict:
270+
type: BoolString
261271
required:
262272
- outcomes
263273
type: object
@@ -301,6 +311,8 @@ spec:
301311
type: object
302312
type: object
303313
type: array
314+
strict:
315+
type: BoolString
304316
required:
305317
- customResourceDefinitionName
306318
- outcomes
@@ -351,6 +363,8 @@ spec:
351363
type: object
352364
type: object
353365
type: array
366+
strict:
367+
type: BoolString
354368
required:
355369
- name
356370
- outcomes
@@ -393,6 +407,8 @@ spec:
393407
type: object
394408
type: object
395409
type: array
410+
strict:
411+
type: BoolString
396412
required:
397413
- outcomes
398414
type: object
@@ -436,6 +452,8 @@ spec:
436452
type: array
437453
registryName:
438454
type: string
455+
strict:
456+
type: BoolString
439457
required:
440458
- outcomes
441459
- registryName
@@ -482,6 +500,8 @@ spec:
482500
type: object
483501
type: object
484502
type: array
503+
strict:
504+
type: BoolString
485505
required:
486506
- ingressName
487507
- namespace
@@ -533,6 +553,8 @@ spec:
533553
type: object
534554
type: object
535555
type: array
556+
strict:
557+
type: BoolString
536558
required:
537559
- name
538560
- outcomes
@@ -579,6 +601,8 @@ spec:
579601
type: object
580602
type: object
581603
type: array
604+
strict:
605+
type: BoolString
582606
required:
583607
- namespace
584608
- outcomes
@@ -625,6 +649,8 @@ spec:
625649
type: object
626650
type: object
627651
type: array
652+
strict:
653+
type: BoolString
628654
required:
629655
- collectorName
630656
- outcomes
@@ -693,6 +719,8 @@ spec:
693719
type: object
694720
type: object
695721
type: array
722+
strict:
723+
type: BoolString
696724
required:
697725
- outcomes
698726
type: object
@@ -738,6 +766,8 @@ spec:
738766
type: object
739767
type: object
740768
type: array
769+
strict:
770+
type: BoolString
741771
required:
742772
- collectorName
743773
- outcomes
@@ -784,6 +814,8 @@ spec:
784814
type: object
785815
type: object
786816
type: array
817+
strict:
818+
type: BoolString
787819
required:
788820
- collectorName
789821
- outcomes
@@ -828,6 +860,8 @@ spec:
828860
type: object
829861
type: object
830862
type: array
863+
strict:
864+
type: BoolString
831865
required:
832866
- collectorName
833867
- outcomes
@@ -882,6 +916,8 @@ spec:
882916
items:
883917
type: string
884918
type: array
919+
strict:
920+
type: BoolString
885921
required:
886922
- name
887923
- outcomes
@@ -931,6 +967,8 @@ spec:
931967
type: array
932968
secretName:
933969
type: string
970+
strict:
971+
type: BoolString
934972
required:
935973
- namespace
936974
- outcomes
@@ -982,6 +1020,8 @@ spec:
9821020
type: object
9831021
type: object
9841022
type: array
1023+
strict:
1024+
type: BoolString
9851025
required:
9861026
- name
9871027
- outcomes
@@ -1026,6 +1066,8 @@ spec:
10261066
type: array
10271067
storageClassName:
10281068
type: string
1069+
strict:
1070+
type: BoolString
10291071
required:
10301072
- outcomes
10311073
- storageClassName
@@ -1068,6 +1110,8 @@ spec:
10681110
type: object
10691111
type: object
10701112
type: array
1113+
strict:
1114+
type: BoolString
10711115
required:
10721116
- outcomes
10731117
type: object
@@ -1119,6 +1163,8 @@ spec:
11191163
type: string
11201164
regexGroups:
11211165
type: string
1166+
strict:
1167+
type: BoolString
11221168
required:
11231169
- outcomes
11241170
type: object
@@ -1130,6 +1176,8 @@ spec:
11301176
type: BoolString
11311177
reportFileGlob:
11321178
type: string
1179+
strict:
1180+
type: BoolString
11331181
required:
11341182
- reportFileGlob
11351183
type: object

0 commit comments

Comments
 (0)