1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-11-25 17:38:21 +00:00

Fix the --exit-code flag doesn't work when run with subcommand (#1084)

This commit is contained in:
Huang Huang 2022-01-23 15:40:59 +08:00 committed by GitHub
parent 9119968940
commit d232ae0fb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 4 deletions

View File

@ -16,6 +16,7 @@ package cmd
import ( import (
"fmt" "fmt"
"os"
"github.com/aquasecurity/kube-bench/check" "github.com/aquasecurity/kube-bench/check"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -36,6 +37,7 @@ var masterCmd = &cobra.Command{
filename := loadConfig(check.MASTER, bv) filename := loadConfig(check.MASTER, bv)
runChecks(check.MASTER, filename, detecetedKubeVersion) runChecks(check.MASTER, filename, detecetedKubeVersion)
writeOutput(controlsCollection) writeOutput(controlsCollection)
os.Exit(exitCodeSelection(controlsCollection))
}, },
Deprecated: "this command will be retired soon. Please use the `run` command with `--targets=master` instead.", Deprecated: "this command will be retired soon. Please use the `run` command with `--targets=master` instead.",
} }

View File

@ -16,6 +16,7 @@ package cmd
import ( import (
"fmt" "fmt"
"os"
"github.com/aquasecurity/kube-bench/check" "github.com/aquasecurity/kube-bench/check"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -36,6 +37,7 @@ var nodeCmd = &cobra.Command{
filename := loadConfig(check.NODE, bv) filename := loadConfig(check.NODE, bv)
runChecks(check.NODE, filename, detecetedKubeVersion) runChecks(check.NODE, filename, detecetedKubeVersion)
writeOutput(controlsCollection) writeOutput(controlsCollection)
os.Exit(exitCodeSelection(controlsCollection))
}, },
Deprecated: "this command will be retired soon. Please use the `run` command with `--targets=node` instead.", Deprecated: "this command will be retired soon. Please use the `run` command with `--targets=node` instead.",
} }

View File

@ -136,8 +136,7 @@ var RootCmd = &cobra.Command{
} }
writeOutput(controlsCollection) writeOutput(controlsCollection)
exitCode := exitCodeSelection(controlsCollection) os.Exit(exitCodeSelection(controlsCollection))
os.Exit(exitCode)
}, },
} }

View File

@ -54,13 +54,15 @@ var runCmd = &cobra.Command{
path := filepath.Join(cfgDir, bv) path := filepath.Join(cfgDir, bv)
err = mergeConfig(path) err = mergeConfig(path)
if err != nil { if err != nil {
fmt.Printf("Error in mergeConfig: %v\n", err) exitWithError(fmt.Errorf("Error in mergeConfig: %v\n", err))
} }
err = run(targets, bv) err = run(targets, bv)
if err != nil { if err != nil {
fmt.Printf("Error in run: %v\n", err) exitWithError(fmt.Errorf("Error in run: %v\n", err))
} }
os.Exit(exitCodeSelection(controlsCollection))
}, },
} }