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.pull/783/head
parent
d1c77fe30f
commit
1960618ae1
|
@ -108,6 +108,10 @@ var settings = []Setting{
|
||||||
name: config.WantReportErrorPrompt,
|
name: config.WantReportErrorPrompt,
|
||||||
set: SetBool,
|
set: SetBool,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: config.WantKubectlDownloadMsg,
|
||||||
|
set: SetBool,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "dashboard",
|
name: "dashboard",
|
||||||
set: SetBool,
|
set: SetBool,
|
||||||
|
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
configCmd "k8s.io/minikube/cmd/minikube/cmd/config"
|
configCmd "k8s.io/minikube/cmd/minikube/cmd/config"
|
||||||
|
"k8s.io/minikube/cmd/util"
|
||||||
"k8s.io/minikube/pkg/minikube/config"
|
"k8s.io/minikube/pkg/minikube/config"
|
||||||
"k8s.io/minikube/pkg/minikube/constants"
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
"k8s.io/minikube/pkg/minikube/notify"
|
"k8s.io/minikube/pkg/minikube/notify"
|
||||||
|
@ -51,6 +52,7 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
enableUpdateNotification = true
|
enableUpdateNotification = true
|
||||||
|
enableKubectlDownloadMsg = true
|
||||||
)
|
)
|
||||||
|
|
||||||
var viperWhiteList = []string{
|
var viperWhiteList = []string{
|
||||||
|
@ -83,6 +85,9 @@ var RootCmd = &cobra.Command{
|
||||||
if enableUpdateNotification {
|
if enableUpdateNotification {
|
||||||
notify.MaybePrintUpdateTextFromGithub(os.Stdout)
|
notify.MaybePrintUpdateTextFromGithub(os.Stdout)
|
||||||
}
|
}
|
||||||
|
if enableKubectlDownloadMsg {
|
||||||
|
util.MaybePrintKubectlDownloadMsg()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,5 +152,6 @@ func setupViper() {
|
||||||
viper.SetDefault(config.ReminderWaitPeriodInHours, 24)
|
viper.SetDefault(config.ReminderWaitPeriodInHours, 24)
|
||||||
viper.SetDefault(config.WantReportError, false)
|
viper.SetDefault(config.WantReportError, false)
|
||||||
viper.SetDefault(config.WantReportErrorPrompt, true)
|
viper.SetDefault(config.WantReportErrorPrompt, true)
|
||||||
|
viper.SetDefault(config.WantKubectlDownloadMsg, true)
|
||||||
setFlagsUsingViper()
|
setFlagsUsingViper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -165,3 +167,33 @@ func PromptUserForAccept(r io.Reader) bool {
|
||||||
return false
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ Configurable fields:
|
||||||
* ReminderWaitPeriodInHours
|
* ReminderWaitPeriodInHours
|
||||||
* WantReportError
|
* WantReportError
|
||||||
* WantReportErrorPrompt
|
* WantReportErrorPrompt
|
||||||
|
* WantKubectlDownloadMsg
|
||||||
* dashboard
|
* dashboard
|
||||||
* addon-manager
|
* addon-manager
|
||||||
* kube-dns
|
* kube-dns
|
||||||
|
|
|
@ -31,6 +31,7 @@ const (
|
||||||
ReminderWaitPeriodInHours = "ReminderWaitPeriodInHours"
|
ReminderWaitPeriodInHours = "ReminderWaitPeriodInHours"
|
||||||
WantReportError = "WantReportError"
|
WantReportError = "WantReportError"
|
||||||
WantReportErrorPrompt = "WantReportErrorPrompt"
|
WantReportErrorPrompt = "WantReportErrorPrompt"
|
||||||
|
WantKubectlDownloadMsg = "WantKubectlDownloadMsg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configFile interface {
|
type configFile interface {
|
||||||
|
|
Loading…
Reference in New Issue