Merge pull request #147 from aquasecurity/version-fix

Shouldn't need kubelet or kubectl if version specified
pull/148/head v0.0.20
Liz Rice 6 years ago committed by GitHub
commit b1e41d345f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,7 +44,11 @@ func runChecks(nodetype check.NodeType) {
file = federatedFile file = federatedFile
} }
path, err := getConfigFilePath(kubeVersion, getKubeVersion(), file) runningVersion, err := getKubeVersion()
if err != nil && kubeVersion == "" {
exitWithError(fmt.Errorf("Version check failed: %s\nAlternatively, you can specify the version with --version", err))
}
path, err := getConfigFilePath(kubeVersion, runningVersion, file)
if err != nil { if err != nil {
exitWithError(fmt.Errorf("can't find %s controls file in %s: %v", nodetype, cfgDir, err)) exitWithError(fmt.Errorf("can't find %s controls file in %s: %v", nodetype, cfgDir, err))
} }

@ -129,6 +129,8 @@ func getConfigFilePath(specifiedVersion string, runningVersion string, filename
fileVersion = runningVersion fileVersion = runningVersion
} }
glog.V(2).Info(fmt.Sprintf("Looking for config for version %s", fileVersion))
for { for {
path = filepath.Join(cfgDir, fileVersion) path = filepath.Join(cfgDir, fileVersion)
file := filepath.Join(path, string(filename)) file := filepath.Join(path, string(filename))
@ -265,19 +267,19 @@ func multiWordReplace(s string, subname string, sub string) string {
return strings.Replace(s, subname, sub, -1) return strings.Replace(s, subname, sub, -1)
} }
func getKubeVersion() string { func getKubeVersion() (string, error) {
// These executables might not be on the user's path. // These executables might not be on the user's path.
_, err := exec.LookPath("kubectl") _, err := exec.LookPath("kubectl")
if err != nil { if err != nil {
_, err = exec.LookPath("kubelet") _, err = exec.LookPath("kubelet")
if err != nil { if err != nil {
exitWithError(fmt.Errorf("Version check failed: need kubectl or kubelet binaries to get kubernetes version.\nAlternately, you can specify the version with --version")) return "", fmt.Errorf("need kubectl or kubelet binaries to get kubernetes version")
} }
return getKubeVersionFromKubelet() return getKubeVersionFromKubelet(), nil
} }
return getKubeVersionFromKubectl() return getKubeVersionFromKubectl(), nil
} }
func getKubeVersionFromKubectl() string { func getKubeVersionFromKubectl() string {

Loading…
Cancel
Save