|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"strings"
|
|
|
|
@ -32,6 +31,7 @@ func init() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
|
logAction("starting verification")
|
|
|
|
|
checkFailed := false
|
|
|
|
|
if !sshCheck() {
|
|
|
|
|
checkFailed = true
|
|
|
|
@ -49,7 +49,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
|
if checkFailed {
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(`✔`, "all prerequisites checks passed")
|
|
|
|
|
logSuccess("all prerequisites checks passed")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -60,7 +60,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
|
if checkFailed {
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(`✔`, "all checks passed")
|
|
|
|
|
logSuccess("all checks passed")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -69,10 +69,10 @@ func sshCheck() bool {
|
|
|
|
|
for _, cmd := range []string{"ssh-keygen", "ssh-keyscan"} {
|
|
|
|
|
_, err := exec.LookPath(cmd)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, cmd, "not found")
|
|
|
|
|
logFailure("%s not found", cmd)
|
|
|
|
|
ok = false
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Println(`✔`, cmd, "found")
|
|
|
|
|
logSuccess("%s found", cmd)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -82,94 +82,94 @@ func sshCheck() bool {
|
|
|
|
|
func kubectlCheck(version string) bool {
|
|
|
|
|
_, err := exec.LookPath("kubectl")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kubectl not found")
|
|
|
|
|
logFailure("kubectl not found")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output, err := execCommand("kubectl version --client --short | awk '{ print $3 }'")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kubectl version can't be determined")
|
|
|
|
|
logFailure("kubectl version can't be determined")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v, err := semver.ParseTolerant(output)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kubectl version can't be parsed")
|
|
|
|
|
logFailure("kubectl version can't be parsed")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rng, _ := semver.ParseRange(version)
|
|
|
|
|
if !rng(v) {
|
|
|
|
|
fmt.Println(`✗`, "kubectl version must be", version)
|
|
|
|
|
logFailure("kubectl version must be %s", version)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println(`✔`, "kubectl", v.String(), version)
|
|
|
|
|
logSuccess("kubectl %s %s", v.String(), version)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func kustomizeCheck(version string) bool {
|
|
|
|
|
_, err := exec.LookPath("kustomize")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kustomize not found")
|
|
|
|
|
logFailure("kustomize not found")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output, err := execCommand("kustomize version --short | awk '{ print $1 }' | cut -c2-")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kustomize version can't be determined")
|
|
|
|
|
logFailure("kustomize version can't be determined")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if strings.Contains(output, "kustomize/") {
|
|
|
|
|
output, err = execCommand("kustomize version --short | awk '{ print $1 }' | cut -c12-")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kustomize version can't be determined")
|
|
|
|
|
logFailure("kustomize version can't be determined")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v, err := semver.ParseTolerant(output)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kustomize version can't be parsed")
|
|
|
|
|
logFailure("kustomize version can't be parsed")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rng, _ := semver.ParseRange(version)
|
|
|
|
|
if !rng(v) {
|
|
|
|
|
fmt.Println(`✗`, "kustomize version must be", version)
|
|
|
|
|
logFailure("kustomize version must be %s", version)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println(`✔`, "kustomize", v.String(), version)
|
|
|
|
|
logSuccess("kustomize %s %s", v.String(), version)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func kubernetesCheck(version string) bool {
|
|
|
|
|
client, err := kubernetesClient()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kubernetes client initialization failed", err.Error())
|
|
|
|
|
logFailure("kubernetes client initialization failed: %s", err.Error())
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ver, err := client.Discovery().ServerVersion()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kubernetes API call failed", err.Error())
|
|
|
|
|
logFailure("kubernetes API call failed %s", err.Error())
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v, err := semver.ParseTolerant(ver.String())
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(`✗`, "kubernetes version can't be determined")
|
|
|
|
|
logFailure("kubernetes version can't be determined")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rng, _ := semver.ParseRange(version)
|
|
|
|
|
if !rng(v) {
|
|
|
|
|
fmt.Println(`✗`, "kubernetes version must be", version)
|
|
|
|
|
logFailure("kubernetes version must be %s", version)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println(`✔`, "kubernetes", v.String(), version)
|
|
|
|
|
logSuccess("kubernetes %s %s", v.String(), version)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|