|
|
@ -4,12 +4,8 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
|
|
|
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
|
|
|
|
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var checkCmd = &cobra.Command{
|
|
|
|
var checkCmd = &cobra.Command{
|
|
|
@ -17,24 +13,16 @@ var checkCmd = &cobra.Command{
|
|
|
|
Short: "Check for potential problems",
|
|
|
|
Short: "Check for potential problems",
|
|
|
|
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 and Kubernetes cluster are configured correctly.`,
|
|
|
|
the local environment is configured correctly.`,
|
|
|
|
Example: ` check --pre`,
|
|
|
|
Example: ` check --pre`,
|
|
|
|
RunE: runCheckCmd,
|
|
|
|
RunE: runCheckCmd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
kubeconfig string
|
|
|
|
checkPre bool
|
|
|
|
checkPre bool
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
if home := homeDir(); home != "" {
|
|
|
|
|
|
|
|
checkCmd.Flags().StringVarP(&kubeconfig, "kubeconfig", "", filepath.Join(home, ".kube", "config"),
|
|
|
|
|
|
|
|
"path to the kubeconfig file")
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
checkCmd.Flags().StringVarP(&kubeconfig, "kubeconfig", "", "",
|
|
|
|
|
|
|
|
"absolute path to the kubeconfig file")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
checkCmd.Flags().BoolVarP(&checkPre, "pre", "", false,
|
|
|
|
checkCmd.Flags().BoolVarP(&checkPre, "pre", "", false,
|
|
|
|
"only run pre-installation checks")
|
|
|
|
"only run pre-installation checks")
|
|
|
|
|
|
|
|
|
|
|
@ -58,13 +46,6 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func homeDir() string {
|
|
|
|
|
|
|
|
if h := os.Getenv("HOME"); h != "" {
|
|
|
|
|
|
|
|
return h
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return os.Getenv("USERPROFILE") // windows
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func checkLocal() bool {
|
|
|
|
func checkLocal() bool {
|
|
|
|
ok := true
|
|
|
|
ok := true
|
|
|
|
for _, cmd := range []string{"kubectl", "kustomize"} {
|
|
|
|
for _, cmd := range []string{"kubectl", "kustomize"} {
|
|
|
@ -80,13 +61,7 @@ func checkLocal() bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func checkRemote() bool {
|
|
|
|
func checkRemote() bool {
|
|
|
|
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
|
|
|
|
client, err := NewKubernetesClient()
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(`✗`, "kubernetes client initialization failed", err.Error())
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client, err := kubernetes.NewForConfig(config)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(`✗`, "kubernetes client initialization failed", err.Error())
|
|
|
|
fmt.Println(`✗`, "kubernetes client initialization failed", err.Error())
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|