From 1960618ae122adb4528b2621c454cab1c5284bf8 Mon Sep 17 00:00:00 2001 From: Aaron Prindle Date: Sun, 30 Oct 2016 20:21:56 -0700 Subject: [PATCH] Added check for kubectl to each command (in root.go) This prompts user with kubectl install one-liner for latest kubectl version. Also added config for enable/disable. Still need to add tests. --- cmd/minikube/cmd/config/config.go | 4 ++++ cmd/minikube/cmd/root.go | 6 ++++++ cmd/util/util.go | 32 +++++++++++++++++++++++++++++++ docs/minikube_config.md | 1 + pkg/minikube/config/config.go | 1 + 5 files changed, 44 insertions(+) diff --git a/cmd/minikube/cmd/config/config.go b/cmd/minikube/cmd/config/config.go index 939f694509..6ed1b06d26 100644 --- a/cmd/minikube/cmd/config/config.go +++ b/cmd/minikube/cmd/config/config.go @@ -108,6 +108,10 @@ var settings = []Setting{ name: config.WantReportErrorPrompt, set: SetBool, }, + { + name: config.WantKubectlDownloadMsg, + set: SetBool, + }, { name: "dashboard", set: SetBool, diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index ca172109e3..ca1bdade64 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -28,6 +28,7 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" configCmd "k8s.io/minikube/cmd/minikube/cmd/config" + "k8s.io/minikube/cmd/util" "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/notify" @@ -51,6 +52,7 @@ const ( var ( enableUpdateNotification = true + enableKubectlDownloadMsg = true ) var viperWhiteList = []string{ @@ -83,6 +85,9 @@ var RootCmd = &cobra.Command{ if enableUpdateNotification { notify.MaybePrintUpdateTextFromGithub(os.Stdout) } + if enableKubectlDownloadMsg { + util.MaybePrintKubectlDownloadMsg() + } }, } @@ -147,5 +152,6 @@ func setupViper() { viper.SetDefault(config.ReminderWaitPeriodInHours, 24) viper.SetDefault(config.WantReportError, false) viper.SetDefault(config.WantReportErrorPrompt, true) + viper.SetDefault(config.WantKubectlDownloadMsg, true) setFlagsUsingViper() } diff --git a/cmd/util/util.go b/cmd/util/util.go index b352311efa..8c81a8d2ff 100644 --- a/cmd/util/util.go +++ b/cmd/util/util.go @@ -24,6 +24,8 @@ import ( "io" "net/http" "os" + "os/exec" + "runtime" "strings" "time" @@ -165,3 +167,33 @@ func PromptUserForAccept(r io.Reader) bool { return false } } + +func MaybePrintKubectlDownloadMsg() { + if !viper.GetBool(config.WantKubectlDownloadMsg) { + return + } + verb := "run" + installInstructions := "curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/%s/bin/%s/%s/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/" + if runtime.GOOS == "windows" { + verb = "do" + installInstructions = `download kubectl from: +https://storage.googleapis.com/kubernetes-release/release/%s/bin/%s/%s/kubectl +Add kubectl to your system PATH` + } + + _, err := exec.LookPath("kubectl") + if err != nil { + fmt.Fprintf(os.Stderr, + `======================================== +kubectl could not be found on your path. kubectl is a requirement for using minikube +To install kubectl, please %s the following: + +%s + +To disable this message, run the following: + +minikube config set WantKubectlDownloadMsg false +========================================\n`, + verb, installInstructions, constants.DefaultKubernetesVersion, runtime.GOOS, runtime.GOARCH) + } +} diff --git a/docs/minikube_config.md b/docs/minikube_config.md index 392cd308af..dd209a173f 100644 --- a/docs/minikube_config.md +++ b/docs/minikube_config.md @@ -21,6 +21,7 @@ Configurable fields: * ReminderWaitPeriodInHours * WantReportError * WantReportErrorPrompt + * WantKubectlDownloadMsg * dashboard * addon-manager * kube-dns diff --git a/pkg/minikube/config/config.go b/pkg/minikube/config/config.go index 8a5d55bb8a..2388c5e8fa 100644 --- a/pkg/minikube/config/config.go +++ b/pkg/minikube/config/config.go @@ -31,6 +31,7 @@ const ( ReminderWaitPeriodInHours = "ReminderWaitPeriodInHours" WantReportError = "WantReportError" WantReportErrorPrompt = "WantReportErrorPrompt" + WantKubectlDownloadMsg = "WantKubectlDownloadMsg" ) type configFile interface {