From e065c02394620ae9522c004f8ed0307d6f22dba3 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Thu, 22 Oct 2020 20:58:47 +0200 Subject: [PATCH] include fixes from code review --- cmd/minikube/cmd/start.go | 2 +- pkg/minikube/command/exec_runner.go | 26 +++++++++++--------------- pkg/minikube/driver/driver.go | 7 +------ 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index edf350ab04be..ee5d3a0fbf0b 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -795,7 +795,7 @@ func validateUser(drvName string) { if !viper.GetBool(interactive) { test := exec.Command("sudo", "-n", "echo", "-n") if err := test.Run(); err != nil { - exit.Message(reason.Usage, `sudo requires a password, and --interactive=false`) + exit.Message(reason.DrvNeedsRoot, `sudo requires a password, and --interactive=false`) } } return diff --git a/pkg/minikube/command/exec_runner.go b/pkg/minikube/command/exec_runner.go index 66bd63591b65..6e5caf5708a2 100644 --- a/pkg/minikube/command/exec_runner.go +++ b/pkg/minikube/command/exec_runner.go @@ -91,15 +91,8 @@ func (e *execRunner) Copy(f assets.CopyableFile) error { dst := path.Join(f.GetTargetDir(), f.GetTargetName()) if _, err := os.Stat(dst); err == nil { klog.Infof("found %s, removing ...", dst) - switch runtime.GOOS { - case "linux": - if _, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst)); err != nil { - return errors.Wrapf(err, "error removing file %s", dst) - } - default: - if err := os.Remove(dst); err != nil { - return errors.Wrapf(err, "error removing file %s", dst) - } + if err := e.Remove(f); err != nil { + return errors.Wrapf(err, "error removing file %s", dst) } } @@ -147,11 +140,14 @@ func (e *execRunner) Copy(f assets.CopyableFile) error { func (e *execRunner) Remove(f assets.CopyableFile) error { dst := filepath.Join(f.GetTargetDir(), f.GetTargetName()) klog.Infof("rm: %s", dst) - switch runtime.GOOS { - case "linux": - _, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst)) - return err - default: - return os.Remove(dst) + if err := os.Remove(dst); err != nil { + if !os.IsPermission(err) { + return err + } + _, err = e.RunCmd(exec.Command("sudo", "rm", "-f", dst)) + if err != nil { + return err + } } + return nil } diff --git a/pkg/minikube/driver/driver.go b/pkg/minikube/driver/driver.go index 0dd37bfec97a..3bde60e3165d 100644 --- a/pkg/minikube/driver/driver.go +++ b/pkg/minikube/driver/driver.go @@ -143,12 +143,7 @@ func BareMetal(name string) bool { // NeedsRoot returns true if driver needs to run with root privileges func NeedsRoot(name string) bool { - switch runtime.GOOS { - case "linux": - return false - default: - return name == None - } + return false } // NeedsPortForward returns true if driver is unable provide direct IP connectivity