diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 336836a50a12..5c0d274f2953 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -109,7 +109,7 @@ func Execute() { flag.Usage = translate.T(flag.Usage) }) - if runtime.GOOS == "linux" { + if runtime.GOOS != "windows" { // add minikube binaries to the path targetDir := constants.MakeMiniPath("bin") addToPath(targetDir) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 8f5d1982e4cc..8b23f391fe3a 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -289,7 +289,7 @@ func runStart(cmd *cobra.Command, args []string) { validateConfig() validateUser() - validateDriverVersion(driver) + installOrUpdateDriver(driver) k8sVersion, isUpgrade := getKubernetesVersion() config, err := generateCfgFromFlags(cmd, k8sVersion) @@ -1028,62 +1028,26 @@ func saveConfig(clusterCfg *cfg.Config) error { return cfg.CreateProfile(viper.GetString(cfg.MachineProfile), clusterCfg) } -func validateDriverVersion(vmDriver string) { +func installOrUpdateDriver(vmDriver string) { var driverExecutable string - driverDocumentation := fmt.Sprintf("%s%s#driver-installation", constants.DriverDocumentation, vmDriver) - - minikubeVersion, err := version.GetSemverVersion() - if err != nil { - out.WarningT("Error parsing minukube version: {{.error}}", out.V{"error": err}) - return - } - switch vmDriver { case constants.DriverKvm2: driverExecutable = fmt.Sprintf("docker-machine-driver-%s", constants.DriverKvm2) - targetDir := constants.MakeMiniPath("bin") - err := drivers.InstallOrUpdate(driverExecutable, targetDir, minikubeVersion) - if err != nil { - out.WarningT("Error downloading driver: {{.error}}", out.V{"error": err}) - } - return case constants.DriverHyperkit: driverExecutable = fmt.Sprintf("docker-machine-driver-%s", constants.DriverHyperkit) - default: // driver doesn't support version + default: // driver doesn't install or update return } - cmd := exec.Command(driverExecutable, "version") - output, err := cmd.Output() - - // we don't want to fail if an error was returned, - // libmachine has a nice message for the user if the driver isn't present + minikubeVersion, err := version.GetSemverVersion() if err != nil { - out.WarningT("Error checking driver version: {{.error}}", out.V{"error": err}) + out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err}) return } - v := drivers.ExtractVMDriverVersion(string(output)) - - // if the driver doesn't have return any version, it is really old, we force a upgrade. - if len(v) == 0 && !viper.GetBool(force) { - exit.WithCodeT( - exit.Failure, - "The installed version of '{{.driver_executable}}' is obsolete. Upgrade: {{.documentation_url}}", - out.V{"driver_executable": driverExecutable, "documentation_url": driverDocumentation}, - ) - } - - vmDriverVersion, err := semver.Make(v) + targetDir := constants.MakeMiniPath("bin") + err = drivers.InstallOrUpdate(driverExecutable, targetDir, minikubeVersion) if err != nil { - out.WarningT("Error parsing vmDriver version: {{.error}}", out.V{"error": err}) - return - } - - if vmDriverVersion.LT(minikubeVersion) { - out.WarningT( - "The installed version of '{{.driver_executable}}' ({{.driver_version}}) is no longer current. Upgrade: {{.documentation_url}}", - out.V{"driver_executable": driverExecutable, "driver_version": vmDriverVersion, "documentation_url": driverDocumentation}, - ) + out.WarningT("Error downloading driver: {{.error}}", out.V{"error": err}) } } diff --git a/pkg/drivers/drivers.go b/pkg/drivers/drivers.go index 4918dee9c360..c9d256a6b345 100644 --- a/pkg/drivers/drivers.go +++ b/pkg/drivers/drivers.go @@ -17,6 +17,7 @@ limitations under the License. package drivers import ( + "fmt" "io" "io/ioutil" "os" @@ -42,7 +43,8 @@ import ( ) const ( - driverKVMDownloadURL = "https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2" + driverKVMDownloadURL = "https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2" + driverHyperKitDownloadURL = "https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit" ) // GetDiskPath returns the path of the machine disk image @@ -187,17 +189,23 @@ func InstallOrUpdate(driver, destination string, minikubeVersion semver.Version) } func download(driver, destination string) error { - // only support kvm2 for now - if driver != "docker-machine-driver-kvm2" { + // supports kvm2 and hyperkit + if driver != "docker-machine-driver-kvm2" && driver != "docker-machine-driver-hyperkit" { return nil } out.T(out.Happy, "Downloading driver {{.driver}}:", out.V{"driver": driver}) - targetFilepath := path.Join(destination, "docker-machine-driver-kvm2") + targetFilepath := path.Join(destination, driver) os.Remove(targetFilepath) - url := driverKVMDownloadURL + var url string + switch driver { + case "docker-machine-driver-kvm2": + url = driverKVMDownloadURL + case "docker-machine-driver-hyperkit": + url = driverHyperKitDownloadURL + } opts := []getter.ClientOption{getter.WithProgress(util.DefaultProgressBar)} client := &getter.Client{ @@ -216,6 +224,13 @@ func download(driver, destination string) error { return errors.Wrap(err, "chmod error") } + if driver == "docker-machine-driver-hyperkit" { + err := setHyperKitPermissions(targetFilepath) + if err != nil { + return errors.Wrap(err, "setting hyperkit permission") + } + } + return nil } @@ -235,3 +250,22 @@ func ExtractVMDriverVersion(s string) string { v := strings.TrimSpace(matches[1]) return strings.TrimPrefix(v, version.VersionPrefix) } + +func setHyperKitPermissions(driverPath string) error { + msg := fmt.Sprintf("A new hyperkit driver was installed. It needs elevated permissions to run. The following commands will be executed\nsudo chown root:wheel %s\nsudo chmod u+s %s", driverPath, driverPath) + out.T(out.Happy, msg, out.V{}) + + cmd := exec.Command("sudo", "chown", "root:wheel", driverPath) + err := cmd.Run() + if err != nil { + return errors.Wrap(err, "chown root:wheel") + } + + cmd = exec.Command("sudo", "chmod", "u+s", driverPath) + err = cmd.Run() + if err != nil { + return errors.Wrap(err, "chmod u+s") + } + + return nil +} diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 68e70c16dd21..cd63c9999489 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -374,8 +374,3 @@ const ( // GvisorURL is the url to download gvisor GvisorURL = "https://storage.googleapis.com/gvisor/releases/nightly/2019-01-14/runsc" ) - -const ( - // DriverDocumentation the documentation of the KVM driver - DriverDocumentation = "https://minikube.sigs.k8s.io/docs/reference/drivers/" -)