Skip to content

Commit 4f4d94b

Browse files
kmarteauxzegl
authored andcommitted
Add new --all-default-optional flag to enable all optional tests
1 parent fec7ff4 commit 4f4d94b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cmd/kube-score/main.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313

1414
"github.com/mattn/go-isatty"
1515
flag "github.com/spf13/pflag"
16-
"golang.org/x/term"
17-
1816
"github.com/zegl/kube-score/config"
1917
ks "github.com/zegl/kube-score/domain"
2018
"github.com/zegl/kube-score/parser"
@@ -24,6 +22,7 @@ import (
2422
"github.com/zegl/kube-score/renderer/sarif"
2523
"github.com/zegl/kube-score/score"
2624
"github.com/zegl/kube-score/scorecard"
25+
"golang.org/x/term"
2726
)
2827

2928
func main() {
@@ -112,6 +111,7 @@ func scoreFiles(binName string, args []string) error {
112111
ignoreTests := fs.StringSlice("ignore-test", []string{}, "Disable a test, can be set multiple times")
113112
disableIgnoreChecksAnnotation := fs.Bool("disable-ignore-checks-annotations", false, "Set to true to disable the effect of the 'kube-score/ignore' annotations")
114113
disableOptionalChecksAnnotation := fs.Bool("disable-optional-checks-annotations", false, "Set to true to disable the effect of the 'kube-score/enable' annotations")
114+
allDefaultOptional := fs.Bool("all-default-optional", false, "Set to true to enable all tests")
115115
kubernetesVersion := fs.String("kubernetes-version", "v1.18", "Setting the kubernetes-version will affect the checks ran against the manifests. Set this to the version of Kubernetes that you're using in production for the best results.")
116116
setDefault(fs, binName, "score", false)
117117

@@ -169,6 +169,20 @@ Use "-" as filename to read from STDIN.`, execName(binName))
169169
allFilePointers = append(allFilePointers, namedReader{Reader: fp, name: filename})
170170
}
171171

172+
if len(*ignoreTests) > 0 && *allDefaultOptional {
173+
return errors.New("Invalid argument combination. --all-default-optional and --ignore-tests cannot be used together")
174+
}
175+
176+
if *allDefaultOptional {
177+
var addOptionalChecks []string
178+
for _, c := range score.RegisterAllChecks(parser.Empty(), config.Configuration{}).All() {
179+
if c.Optional {
180+
addOptionalChecks = append(addOptionalChecks, c.ID)
181+
}
182+
}
183+
optionalTests = &addOptionalChecks
184+
}
185+
172186
ignoredTests := listToStructMap(ignoreTests)
173187
enabledOptionalTests := listToStructMap(optionalTests)
174188

0 commit comments

Comments
 (0)