From dabf272f33526d001c54d862104cfbfbd2e63ce2 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Wed, 3 Jul 2019 17:03:18 -0300 Subject: [PATCH 1/6] Add warn if kvm driver version is old --- cmd/minikube/cmd/start.go | 51 ++++++++++++++++++++++++++++++++++ cmd/minikube/cmd/start_test.go | 45 ++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 cmd/minikube/cmd/start_test.go diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 2ac3e52a72d3..07b096bbf728 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -26,6 +26,7 @@ import ( "os/exec" "os/user" "path/filepath" + "regexp" "runtime" "strconv" "strings" @@ -210,6 +211,8 @@ func runStart(cmd *cobra.Command, args []string) { exit.WithError("Failed to save config", err) } + validateDriverVersion(viper.GetString(vmDriver)) + m, err := machine.NewAPIClient() if err != nil { exit.WithError("Failed to get machine client", err) @@ -850,3 +853,51 @@ func saveConfig(clusterConfig cfg.Config) error { } return nil } + +func validateDriverVersion(vmDriver string) { + if vmDriver == constants.DriverKvm2 { + cmd := exec.Command("docker-machine-driver-kvm2", "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 + if err != nil { + console.Warning("Error checking driver version: %v", err) + return + } + + v := extractVMDriverVersion(string(output)) + + if len(v) == 0 { + exit.WithCode(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'.") + } + + vmDriverVersion, err := semver.Make(v) + if err != nil { + console.Warning("Error parsing vmDriver version: %v", err) + return + } + + minikubeVersion, err := version.GetSemverVersion() + if err != nil { + console.Warning("Error parsing minukube version: %v", err) + return + } + + if vmDriverVersion.LT(minikubeVersion) { + console.Warning("The 'docker-machine-driver-kvm2' version is old. Please consider upgrading.") + } + } +} + +func extractVMDriverVersion(s string) string { + versionRegex := regexp.MustCompile(`version:(.*)`) + matches := versionRegex.FindStringSubmatch(s) + + if len(matches) != 2 { + return "" + } + + v := strings.TrimSpace(matches[1]) + return strings.TrimPrefix(v, version.VersionPrefix) +} diff --git a/cmd/minikube/cmd/start_test.go b/cmd/minikube/cmd/start_test.go new file mode 100644 index 000000000000..fc97b968873c --- /dev/null +++ b/cmd/minikube/cmd/start_test.go @@ -0,0 +1,45 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "testing" +) + +func Test_extractVMDriverVersion(t *testing.T) { + v := extractVMDriverVersion("") + if len(v) != 0 { + t.Error("Expected empty string") + } + + v = extractVMDriverVersion("random text") + if len(v) != 0 { + t.Error("Expected empty string") + } + + expectedVersion := "1.2.3" + + v = extractVMDriverVersion("version: v1.2.3") + if expectedVersion != v { + t.Errorf("Expected version: %s, got: %s", expectedVersion, v) + } + + v = extractVMDriverVersion("version: 1.2.3") + if expectedVersion != v { + t.Errorf("Expected version: %s, got: %s", expectedVersion, v) + } +} From f61d62647a34c87330a93613d4fae742512bb085 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Wed, 3 Jul 2019 17:11:30 -0300 Subject: [PATCH 2/6] Add comment about kvm2 force upgrade --- cmd/minikube/cmd/start.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 07b096bbf728..0c441b57028b 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -859,8 +859,8 @@ func validateDriverVersion(vmDriver string) { cmd := exec.Command("docker-machine-driver-kvm2", "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 + // 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 { console.Warning("Error checking driver version: %v", err) return @@ -868,6 +868,7 @@ func validateDriverVersion(vmDriver string) { v := extractVMDriverVersion(string(output)) + // if the driver doesn't have return any version, it is really old, we force a upgrade. if len(v) == 0 { exit.WithCode(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'.") } From d7a30e118fd19338c72366e2d7f803c7568c2262 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Thu, 4 Jul 2019 09:55:54 -0300 Subject: [PATCH 3/6] Fix start_test.go copyright --- cmd/minikube/cmd/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 0c441b57028b..dcf493d1b73f 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -1,5 +1,5 @@ /* -Copyright 2016 The Kubernetes Authors All rights reserved. +Copyright 2019 The Kubernetes Authors All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 5f84ae3cd2c62d4348aeecbdbd4e3cbdfb36958a Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Thu, 4 Jul 2019 10:01:26 -0300 Subject: [PATCH 4/6] Add extractVMDriverVersion documentation --- cmd/minikube/cmd/start.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index dcf493d1b73f..b0cefc4414f7 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -891,6 +891,11 @@ func validateDriverVersion(vmDriver string) { } } +// extractVMDriverVersion extracts the driver version. +// KVM and Hyperkit drivers support the `version` command, that display the information as: +// version: vX.X.X +// commit: XXXX +// This method returns the version 'vX.X.X' or empty if the version isn't found. func extractVMDriverVersion(s string) string { versionRegex := regexp.MustCompile(`version:(.*)`) matches := versionRegex.FindStringSubmatch(s) From 9210b96ee8eb3b857f8b341db8eb37b6f68830aa Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Thu, 4 Jul 2019 10:16:39 -0300 Subject: [PATCH 5/6] Add upgrade documentation to kvm version warn --- cmd/minikube/cmd/start.go | 8 ++++---- cmd/minikube/cmd/start_test.go | 2 +- pkg/minikube/constants/constants.go | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index b0cefc4414f7..57e0c0b8280f 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The Kubernetes Authors All rights reserved. +Copyright 2016 The Kubernetes Authors All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -870,7 +870,7 @@ func validateDriverVersion(vmDriver string) { // if the driver doesn't have return any version, it is really old, we force a upgrade. if len(v) == 0 { - exit.WithCode(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'.") + exit.WithCode(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'. %s", constants.KVMDocumentation) } vmDriverVersion, err := semver.Make(v) @@ -886,13 +886,13 @@ func validateDriverVersion(vmDriver string) { } if vmDriverVersion.LT(minikubeVersion) { - console.Warning("The 'docker-machine-driver-kvm2' version is old. Please consider upgrading.") + console.Warning("The 'docker-machine-driver-kvm2' version is old. Please consider upgrading. %s", constants.KVMDocumentation) } } } // extractVMDriverVersion extracts the driver version. -// KVM and Hyperkit drivers support the `version` command, that display the information as: +// KVM and Hyperkit drivers support the 'version' command, that display the information as: // version: vX.X.X // commit: XXXX // This method returns the version 'vX.X.X' or empty if the version isn't found. diff --git a/cmd/minikube/cmd/start_test.go b/cmd/minikube/cmd/start_test.go index fc97b968873c..446091c17f0e 100644 --- a/cmd/minikube/cmd/start_test.go +++ b/cmd/minikube/cmd/start_test.go @@ -1,5 +1,5 @@ /* -Copyright 2016 The Kubernetes Authors All rights reserved. +Copyright 2019 The Kubernetes Authors All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 6f4fd5f2d4d7..934ba428cf4d 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -431,3 +431,8 @@ const ( // GvisorURL is the url to download gvisor GvisorURL = "https://storage.googleapis.com/gvisor/releases/nightly/2018-12-07/runsc" ) + +const ( + // KVMDocumentation the documentation of the KVM driver + KVMDocumentation = "https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver" +) From 4cce597c9d585c858d64af74c6ece375572bfbc4 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Thu, 4 Jul 2019 17:21:36 -0300 Subject: [PATCH 6/6] Add upgrade section kvm documentation --- docs/drivers.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/drivers.md b/docs/drivers.md index c13c0806a5cb..103b7ec565da 100644 --- a/docs/drivers.md +++ b/docs/drivers.md @@ -16,6 +16,8 @@ the host PATH: ## KVM2 driver +### KVM2 install + To install the KVM2 driver, first install and configure the prerequisites, namely libvirt 1.3.1 or higher, and qemu-kvm: * Debian or Ubuntu 18.x: `sudo apt install libvirt-clients libvirt-daemon-system qemu-kvm` @@ -77,6 +79,13 @@ or, to use kvm2 as a default driver for `minikube start`: minikube config set vm-driver kvm2 ``` +### KVM2 upgrade + +```shell +curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 \ + && sudo install docker-machine-driver-kvm2 /usr/local/bin/ +``` + ### KVM2 troubleshoot If minikube can't start, check if the kvm default network exists.