From 2cee97280427f15e93e9021ace39ee33667c781e Mon Sep 17 00:00:00 2001 From: Deepjyoti Mondal Date: Thu, 20 Jun 2019 07:43:16 +0530 Subject: [PATCH] Provide warning message for unnecessary sudo If minikube is started with root privilege and vm-driver is not hyperV or none, then a warning message is displayed. --- cmd/minikube/cmd/start.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index fd45b867190d..3b39c09a30e5 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -23,6 +23,7 @@ import ( "net" "os" "os/exec" + "os/user" "path/filepath" "runtime" "strconv" @@ -172,6 +173,15 @@ func runStart(cmd *cobra.Command, args []string) { console.OutStyle(console.Happy, "minikube %s on %s (%s)", version.GetVersion(), runtime.GOOS, runtime.GOARCH) validateConfig() + currentUser, err := user.Current() + + // Display warning if minikube is being started with root and vmDriver is not HyperV + if err != nil { + glog.Errorf("Error getting the current user: %v", err) + } else if currentUser.Name == "root" && !(viper.GetString(vmDriver) == "hyperv" || viper.GetString(vmDriver) == "none") { + console.OutStyle(console.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.") + } + oldConfig, err := cfg.Load() if err != nil && !os.IsNotExist(err) { exit.WithCode(exit.Data, "Unable to load config: %v", err)