|
|
@ -4,14 +4,15 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/blang/semver"
|
|
|
|
"github.com/blang/semver"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var checkCmd = &cobra.Command{
|
|
|
|
var checkCmd = &cobra.Command{
|
|
|
|
Use: "check --pre",
|
|
|
|
Use: "check",
|
|
|
|
Short: "Check for potential problems",
|
|
|
|
Short: "Check requirements",
|
|
|
|
Long: `
|
|
|
|
Long: `
|
|
|
|
The check command will perform a series of checks to validate that
|
|
|
|
The check command will perform a series of checks to validate that
|
|
|
|
the local environment is configured correctly.`,
|
|
|
|
the local environment is configured correctly.`,
|
|
|
@ -31,6 +32,10 @@ func init() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
|
|
|
|
if !sshCheck() {
|
|
|
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !kubectlCheck(">=1.14.0") {
|
|
|
|
if !kubectlCheck(">=1.14.0") {
|
|
|
|
os.Exit(1)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -52,9 +57,9 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func checkLocal() bool {
|
|
|
|
func sshCheck() bool {
|
|
|
|
ok := true
|
|
|
|
ok := true
|
|
|
|
for _, cmd := range []string{"kubectl", "kustomize"} {
|
|
|
|
for _, cmd := range []string{"ssh-keygen", "ssh-keyscan"} {
|
|
|
|
_, err := exec.LookPath(cmd)
|
|
|
|
_, err := exec.LookPath(cmd)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(`✗`, cmd, "not found")
|
|
|
|
fmt.Println(`✗`, cmd, "not found")
|
|
|
@ -82,7 +87,7 @@ func kubectlCheck(version string) bool {
|
|
|
|
|
|
|
|
|
|
|
|
v, err := semver.ParseTolerant(output)
|
|
|
|
v, err := semver.ParseTolerant(output)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(`✗`, "kubectl version can't be determined")
|
|
|
|
fmt.Println(`✗`, "kubectl version can't be parsed")
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -109,9 +114,17 @@ func kustomizeCheck(version string) bool {
|
|
|
|
return false
|
|
|
|
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")
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v, err := semver.ParseTolerant(output)
|
|
|
|
v, err := semver.ParseTolerant(output)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(`✗`, "kustomize version can't be determined")
|
|
|
|
fmt.Println(`✗`, "kustomize version can't be parsed")
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|