diff --git a/cmd/master.go b/cmd/master.go index 99d9cb3..590d978 100644 --- a/cmd/master.go +++ b/cmd/master.go @@ -16,6 +16,7 @@ package cmd import ( "fmt" + "os" "github.com/aquasecurity/kube-bench/check" "github.com/spf13/cobra" @@ -36,6 +37,7 @@ var masterCmd = &cobra.Command{ filename := loadConfig(check.MASTER, bv) runChecks(check.MASTER, filename, detecetedKubeVersion) writeOutput(controlsCollection) + os.Exit(exitCodeSelection(controlsCollection)) }, Deprecated: "this command will be retired soon. Please use the `run` command with `--targets=master` instead.", } diff --git a/cmd/node.go b/cmd/node.go index 5672297..63e8e28 100644 --- a/cmd/node.go +++ b/cmd/node.go @@ -16,6 +16,7 @@ package cmd import ( "fmt" + "os" "github.com/aquasecurity/kube-bench/check" "github.com/spf13/cobra" @@ -36,6 +37,7 @@ var nodeCmd = &cobra.Command{ filename := loadConfig(check.NODE, bv) runChecks(check.NODE, filename, detecetedKubeVersion) writeOutput(controlsCollection) + os.Exit(exitCodeSelection(controlsCollection)) }, Deprecated: "this command will be retired soon. Please use the `run` command with `--targets=node` instead.", } diff --git a/cmd/root.go b/cmd/root.go index 785d021..ebfaa67 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -136,8 +136,7 @@ var RootCmd = &cobra.Command{ } writeOutput(controlsCollection) - exitCode := exitCodeSelection(controlsCollection) - os.Exit(exitCode) + os.Exit(exitCodeSelection(controlsCollection)) }, } diff --git a/cmd/run.go b/cmd/run.go index db92fe7..8dd3922 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -54,13 +54,15 @@ var runCmd = &cobra.Command{ path := filepath.Join(cfgDir, bv) err = mergeConfig(path) if err != nil { - fmt.Printf("Error in mergeConfig: %v\n", err) + exitWithError(fmt.Errorf("Error in mergeConfig: %v\n", err)) } err = run(targets, bv) if err != nil { - fmt.Printf("Error in run: %v\n", err) + exitWithError(fmt.Errorf("Error in run: %v\n", err)) } + + os.Exit(exitCodeSelection(controlsCollection)) }, }