|
|
|
@ -159,3 +159,38 @@ func multiWordReplace(s string, subname string, sub string) string {
|
|
|
|
|
|
|
|
|
|
return strings.Replace(s, subname, sub, -1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type version struct {
|
|
|
|
|
Server string
|
|
|
|
|
Client string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getKubeVersion() *version {
|
|
|
|
|
ver := new(version)
|
|
|
|
|
// These executables might not be on the user's path.
|
|
|
|
|
_, err := exec.LookPath("kubectl")
|
|
|
|
|
if err != nil {
|
|
|
|
|
s := fmt.Sprintf("Kubernetes version check skipped with error %v", err)
|
|
|
|
|
continueWithError(err, sprintlnWarn(s))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command("kubectl", "version")
|
|
|
|
|
out, err := cmd.Output()
|
|
|
|
|
if err != nil {
|
|
|
|
|
s := fmt.Sprintf("Kubernetes version check skipped, with error getting kubectl version")
|
|
|
|
|
continueWithError(err, sprintlnWarn(s))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clientVerRe := regexp.MustCompile(`Client.*Major:"(\d+)".*Minor:"(\d+)"`)
|
|
|
|
|
svrVerRe := regexp.MustCompile(`Server.*Major:"(\d+)".*Minor:"(\d+)"`)
|
|
|
|
|
|
|
|
|
|
sub := clientVerRe.FindStringSubmatch(string(out))
|
|
|
|
|
ver.Client = sub[1] + "." + sub[2]
|
|
|
|
|
|
|
|
|
|
sub = svrVerRe.FindStringSubmatch(string(out))
|
|
|
|
|
ver.Server = sub[1] + "." + sub[2]
|
|
|
|
|
|
|
|
|
|
return ver
|
|
|
|
|
}
|
|
|
|
|