From 50fce51da7f231b02668af4a4bb34bf6dbdf0e04 Mon Sep 17 00:00:00 2001 From: Yoav Rotem Date: Tue, 2 Mar 2021 16:27:34 +0200 Subject: [PATCH] Fix fallback to default version (#834) * Fix fallback to default version In some cases kube-bench will crush instead of fallback to default version. Fix it to only log that couldn't auto-detect version and used default. * Fix case with fallback to default version --- cmd/common_test.go | 2 +- cmd/util.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/common_test.go b/cmd/common_test.go index 048ed4b..eefe501 100644 --- a/cmd/common_test.go +++ b/cmd/common_test.go @@ -358,7 +358,7 @@ func TestGetBenchmarkVersion(t *testing.T) { succeed bool }{ {n: "both versions", kubeVersion: "1.11", benchmarkVersion: "cis-1.3", exp: "cis-1.3", callFn: withNoPath, v: viper.New(), succeed: false}, - {n: "no version-missing-kubectl", kubeVersion: "", benchmarkVersion: "", v: viperWithData, exp: "", callFn: withNoPath, succeed: false}, + {n: "no version-missing-kubectl", kubeVersion: "", benchmarkVersion: "", v: viperWithData, exp: "cis-1.6", callFn: withNoPath, succeed: true}, {n: "no version-fakeKubectl", kubeVersion: "", benchmarkVersion: "", v: viperWithData, exp: "cis-1.5", callFn: withFakeKubectl, succeed: true}, {n: "kubeVersion", kubeVersion: "1.15", benchmarkVersion: "", v: viperWithData, exp: "cis-1.5", callFn: withNoPath, succeed: true}, {n: "ocpVersion310", kubeVersion: "ocp-3.10", benchmarkVersion: "", v: viperWithData, exp: "rh-0.7", callFn: withNoPath, succeed: true}, diff --git a/cmd/util.go b/cmd/util.go index d2a1baf..e143a12 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -304,7 +304,9 @@ func getKubeVersion() (*KubeVersion, error) { } glog.Warning(missingKubectlKubeletMessage) - return nil, fmt.Errorf("unable to find the programs kubectl or kubelet in the PATH") + glog.V(1).Info("unable to find the programs kubectl or kubelet in the PATH") + glog.V(1).Infof("Cant detect version, assuming default %s", defaultKubeVersion) + return &KubeVersion{baseVersion: defaultKubeVersion}, nil } return getKubeVersionFromKubelet(), nil }