From 6a5fbbac3454bd59021b1a74706f7e9d4077cba5 Mon Sep 17 00:00:00 2001 From: Jose Donizetti Date: Mon, 22 Jul 2019 19:35:42 -0300 Subject: [PATCH] Warn if hyperkit version is old (#4691) * Add warn if hyperkit driver version is old * Add hyperkit upgrade documentation * Improve kvm/hyperkit upgrade warn message * Move validateDriverVersion to before downloading ISO * Change executable to use constants --- cmd/minikube/cmd/start.go | 78 ++++++++++++++++++----------- docs/drivers.md | 7 +++ pkg/minikube/constants/constants.go | 4 +- 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 847dbc637..b5a563204 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -210,8 +210,10 @@ var startCmd = &cobra.Command{ // runStart handles the executes the flow of "minikube start" func runStart(cmd *cobra.Command, args []string) { out.T(out.Happy, "minikube {{.version}} on {{.os}} ({{.arch}})", out.V{"version": version.GetVersion(), "os": runtime.GOOS, "arch": runtime.GOARCH}) + validateConfig() validateUser() + validateDriverVersion(viper.GetString(vmDriver)) k8sVersion, isUpgrade := getKubernetesVersion() config, err := generateConfig(cmd, k8sVersion) @@ -235,7 +237,6 @@ func runStart(cmd *cobra.Command, args []string) { exit.WithError("Failed to save config", err) } - validateDriverVersion(viper.GetString(vmDriver)) // exits here in case of --download-only option. handleDownloadOnly(&cacheGroup, k8sVersion) mRunner, preExists, machineAPI, host := startMachine(&config) @@ -904,39 +905,60 @@ func saveConfig(clusterConfig *cfg.Config) error { } func validateDriverVersion(vmDriver string) { - if vmDriver == constants.DriverKvm2 { - cmd := exec.Command("docker-machine-driver-kvm2", "version") - output, err := cmd.Output() + var ( + driverExecutable string + driverDocumentation string + ) + + switch vmDriver { + case constants.DriverKvm2: + driverExecutable = fmt.Sprintf("docker-machine-driver-%s", constants.DriverKvm2) + driverDocumentation = fmt.Sprintf("%s#%s", constants.DriverDocumentation, "kvm2-upgrade") + case constants.DriverHyperkit: + driverExecutable = fmt.Sprintf("docker-machine-driver-%s", constants.DriverHyperkit) + driverDocumentation = fmt.Sprintf("%s#%s", constants.DriverDocumentation, "hyperkit-upgrade") + default: // driver doesn't support version + return + } - // 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 - if err != nil { - out.WarningT("Error checking driver version: {{.error}}", out.V{"error": err}) - return - } + cmd := exec.Command(driverExecutable, "version") + output, err := cmd.Output() - v := extractVMDriverVersion(string(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 + if err != nil { + out.WarningT("Error checking driver version: {{.error}}", out.V{"error": err}) + return + } - // if the driver doesn't have return any version, it is really old, we force a upgrade. - if len(v) == 0 { - exit.WithCodeT(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'. {{.documentation_url}}", out.V{"documentation_url": constants.KVMDocumentation}) - } + v := extractVMDriverVersion(string(output)) - vmDriverVersion, err := semver.Make(v) - if err != nil { - out.WarningT("Error parsing vmDriver version: {{.error}}", out.V{"error": err}) - return - } + // if the driver doesn't have return any version, it is really old, we force a upgrade. + if len(v) == 0 { + exit.WithCodeT( + exit.Failure, + "Please upgrade the '{{.driver_executable}}'. {{.documentation_url}}", + out.V{"driver_executable": driverExecutable, "documentation_url": driverDocumentation}, + ) + } - minikubeVersion, err := version.GetSemverVersion() - if err != nil { - out.WarningT("Error parsing minukube version: {{.error}}", out.V{"error": err}) - return - } + vmDriverVersion, err := semver.Make(v) + if err != nil { + out.WarningT("Error parsing vmDriver version: {{.error}}", out.V{"error": err}) + return + } - if vmDriverVersion.LT(minikubeVersion) { - out.WarningT("The 'docker-machine-driver-kvm2' version is old. Please consider upgrading. {{.documentation_url}}", out.V{"documentation_url": constants.KVMDocumentation}) - } + minikubeVersion, err := version.GetSemverVersion() + if err != nil { + out.WarningT("Error parsing minukube version: {{.error}}", out.V{"error": err}) + return + } + + if vmDriverVersion.LT(minikubeVersion) { + out.WarningT( + "There's a new version for '{{.driver_executable}}'. Please consider upgrading. {{.documentation_url}}", + out.V{"driver_executable": driverExecutable, "documentation_url": driverDocumentation}, + ) } } diff --git a/docs/drivers.md b/docs/drivers.md index ba9e2bff3..6b58bd3f4 100644 --- a/docs/drivers.md +++ b/docs/drivers.md @@ -143,6 +143,13 @@ or, to use hyperkit as a default driver for minikube: minikube config set vm-driver hyperkit ``` +### Hyperkit upgrade + +```shell +curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit \ +&& sudo install -o root -g wheel -m 4755 docker-machine-driver-hyperkit /usr/local/bin/ +``` + ### Hyperkit troubleshoot Make sure you are running the lastest version of your driver. diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 2929079a8..4ade1eac3 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -423,6 +423,6 @@ const ( ) const ( - // KVMDocumentation the documentation of the KVM driver - KVMDocumentation = "https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver" + // DriverDocumentation the documentation of the KVM driver + DriverDocumentation = "https://github.com/kubernetes/minikube/blob/master/docs/drivers.md" ) -- GitLab