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,
 | 
			
		||||
		set:  SetBool,
 | 
			
		||||
	},
 | 
			
		||||
	{
 | 
			
		||||
		name: config.WantKubectlDownloadMsg,
 | 
			
		||||
		set:  SetBool,
 | 
			
		||||
	},
 | 
			
		||||
	{
 | 
			
		||||
		name:        "dashboard",
 | 
			
		||||
		set:         SetBool,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,6 +21,7 @@ Configurable fields:
 | 
			
		|||
 * ReminderWaitPeriodInHours
 | 
			
		||||
 * WantReportError
 | 
			
		||||
 * WantReportErrorPrompt
 | 
			
		||||
 * WantKubectlDownloadMsg
 | 
			
		||||
 * dashboard
 | 
			
		||||
 * addon-manager
 | 
			
		||||
 * kube-dns
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,6 +31,7 @@ const (
 | 
			
		|||
	ReminderWaitPeriodInHours = "ReminderWaitPeriodInHours"
 | 
			
		||||
	WantReportError           = "WantReportError"
 | 
			
		||||
	WantReportErrorPrompt     = "WantReportErrorPrompt"
 | 
			
		||||
	WantKubectlDownloadMsg    = "WantKubectlDownloadMsg"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type configFile interface {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue