Skip to content

Commit

Permalink
Add new --all-default-optional flag to enable all optional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmarteaux authored and zegl committed Jul 6, 2023
1 parent fec7ff4 commit 4f4d94b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cmd/kube-score/main.go
Expand Up @@ -13,8 +13,6 @@ import (

"github.com/mattn/go-isatty"
flag "github.com/spf13/pflag"
"golang.org/x/term"

"github.com/zegl/kube-score/config"
ks "github.com/zegl/kube-score/domain"
"github.com/zegl/kube-score/parser"
Expand All @@ -24,6 +22,7 @@ import (
"github.com/zegl/kube-score/renderer/sarif"
"github.com/zegl/kube-score/score"
"github.com/zegl/kube-score/scorecard"
"golang.org/x/term"
)

func main() {
Expand Down Expand Up @@ -112,6 +111,7 @@ func scoreFiles(binName string, args []string) error {
ignoreTests := fs.StringSlice("ignore-test", []string{}, "Disable a test, can be set multiple times")
disableIgnoreChecksAnnotation := fs.Bool("disable-ignore-checks-annotations", false, "Set to true to disable the effect of the 'kube-score/ignore' annotations")
disableOptionalChecksAnnotation := fs.Bool("disable-optional-checks-annotations", false, "Set to true to disable the effect of the 'kube-score/enable' annotations")
allDefaultOptional := fs.Bool("all-default-optional", false, "Set to true to enable all tests")
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.")
setDefault(fs, binName, "score", false)

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

if len(*ignoreTests) > 0 && *allDefaultOptional {
return errors.New("Invalid argument combination. --all-default-optional and --ignore-tests cannot be used together")
}

if *allDefaultOptional {
var addOptionalChecks []string
for _, c := range score.RegisterAllChecks(parser.Empty(), config.Configuration{}).All() {
if c.Optional {
addOptionalChecks = append(addOptionalChecks, c.ID)
}
}
optionalTests = &addOptionalChecks
}

ignoredTests := listToStructMap(ignoreTests)
enabledOptionalTests := listToStructMap(optionalTests)

Expand Down

0 comments on commit 4f4d94b

Please sign in to comment.