Skip to content

Commit

Permalink
Merge pull request #147 from aquasecurity/version-fix
Browse files Browse the repository at this point in the history
Shouldn't need kubelet or kubectl if version specified
  • Loading branch information
lizrice authored Jul 28, 2018
2 parents 668a9e1 + ccc2b6c commit b1e41d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func runChecks(nodetype check.NodeType) {
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 {
exitWithError(fmt.Errorf("can't find %s controls file in %s: %v", nodetype, cfgDir, err))
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func getConfigFilePath(specifiedVersion string, runningVersion string, filename
fileVersion = runningVersion
}

glog.V(2).Info(fmt.Sprintf("Looking for config for version %s", fileVersion))

for {
path = filepath.Join(cfgDir, fileVersion)
file := filepath.Join(path, string(filename))
Expand Down Expand Up @@ -265,19 +267,19 @@ func multiWordReplace(s string, subname string, sub string) string {
return strings.Replace(s, subname, sub, -1)
}

func getKubeVersion() string {
func getKubeVersion() (string, error) {
// These executables might not be on the user's path.
_, err := exec.LookPath("kubectl")

if err != nil {
_, err = exec.LookPath("kubelet")
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 {
Expand Down

0 comments on commit b1e41d3

Please # to comment.