1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-12-23 15:18:07 +00:00

Read kubernetes version from environment (#390)

* Read kubernetes version from environment

Set kubernetes version to the value of the environment variable `KUBE_BENCH_VERSION` if it is defined and the flag `--version` is not specified on the kube-bench command line.

The command line flag `--version` takes precedence of the environment variable `KUBE_BENCH_VERSION` if both are defined.

* Add info about KUBE_BENCH_VERSION to README
This commit is contained in:
Abubakr-Sadik Nii Nai Davis 2019-08-27 08:04:11 +00:00 committed by Liz Rice
parent a3b8ba58ad
commit 92df9cb36c
2 changed files with 13 additions and 2 deletions

View File

@ -47,6 +47,9 @@ node type and the version of kubernetes a cluster is running. This behaviour
can be overridden by specifying the `master` or `node` subcommand and the can be overridden by specifying the `master` or `node` subcommand and the
`--version` flag on the command line. `--version` flag on the command line.
The kubernetes version can also be set with the KUBE_BENCH_VERSION environment variable.
The value of `--version` takes precedence over the value of KUBE_BENCH_VERSION.
For example: For example:
run kube-bench against a master with version auto-detection: run kube-bench against a master with version auto-detection:

View File

@ -130,8 +130,16 @@ func initConfig() {
viper.AddConfigPath(cfgDir) // adding ./cfg as first search path viper.AddConfigPath(cfgDir) // adding ./cfg as first search path
} }
// Read flag values from environment variables.
// Precedence: Command line flags take precedence over environment variables.
viper.SetEnvPrefix(envVarsPrefix) viper.SetEnvPrefix(envVarsPrefix)
viper.AutomaticEnv() // read in environment variables that match viper.AutomaticEnv()
if kubeVersion == "" {
if env := viper.Get("version"); env != nil {
kubeVersion = env.(string)
}
}
// If a config file is found, read it in. // If a config file is found, read it in.
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {