Skip to content

Commit cc99602

Browse files
authored
Merge pull request #4676 from josedonizetti/warn-if-kvm2-version-is-old
Add warn if kvm driver version is old
2 parents 24bb4f3 + 4cce597 commit cc99602

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

Diff for: cmd/minikube/cmd/start.go

+57
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os/exec"
2727
"os/user"
2828
"path/filepath"
29+
"regexp"
2930
"runtime"
3031
"strconv"
3132
"strings"
@@ -210,6 +211,8 @@ func runStart(cmd *cobra.Command, args []string) {
210211
exit.WithError("Failed to save config", err)
211212
}
212213

214+
validateDriverVersion(viper.GetString(vmDriver))
215+
213216
m, err := machine.NewAPIClient()
214217
if err != nil {
215218
exit.WithError("Failed to get machine client", err)
@@ -850,3 +853,57 @@ func saveConfig(clusterConfig cfg.Config) error {
850853
}
851854
return nil
852855
}
856+
857+
func validateDriverVersion(vmDriver string) {
858+
if vmDriver == constants.DriverKvm2 {
859+
cmd := exec.Command("docker-machine-driver-kvm2", "version")
860+
output, err := cmd.Output()
861+
862+
// we don't want to fail if an error was returned,
863+
// libmachine has a nice message for the user if the driver isn't present
864+
if err != nil {
865+
console.Warning("Error checking driver version: %v", err)
866+
return
867+
}
868+
869+
v := extractVMDriverVersion(string(output))
870+
871+
// if the driver doesn't have return any version, it is really old, we force a upgrade.
872+
if len(v) == 0 {
873+
exit.WithCode(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'. %s", constants.KVMDocumentation)
874+
}
875+
876+
vmDriverVersion, err := semver.Make(v)
877+
if err != nil {
878+
console.Warning("Error parsing vmDriver version: %v", err)
879+
return
880+
}
881+
882+
minikubeVersion, err := version.GetSemverVersion()
883+
if err != nil {
884+
console.Warning("Error parsing minukube version: %v", err)
885+
return
886+
}
887+
888+
if vmDriverVersion.LT(minikubeVersion) {
889+
console.Warning("The 'docker-machine-driver-kvm2' version is old. Please consider upgrading. %s", constants.KVMDocumentation)
890+
}
891+
}
892+
}
893+
894+
// extractVMDriverVersion extracts the driver version.
895+
// KVM and Hyperkit drivers support the 'version' command, that display the information as:
896+
// version: vX.X.X
897+
// commit: XXXX
898+
// This method returns the version 'vX.X.X' or empty if the version isn't found.
899+
func extractVMDriverVersion(s string) string {
900+
versionRegex := regexp.MustCompile(`version:(.*)`)
901+
matches := versionRegex.FindStringSubmatch(s)
902+
903+
if len(matches) != 2 {
904+
return ""
905+
}
906+
907+
v := strings.TrimSpace(matches[1])
908+
return strings.TrimPrefix(v, version.VersionPrefix)
909+
}

Diff for: cmd/minikube/cmd/start_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cmd
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func Test_extractVMDriverVersion(t *testing.T) {
24+
v := extractVMDriverVersion("")
25+
if len(v) != 0 {
26+
t.Error("Expected empty string")
27+
}
28+
29+
v = extractVMDriverVersion("random text")
30+
if len(v) != 0 {
31+
t.Error("Expected empty string")
32+
}
33+
34+
expectedVersion := "1.2.3"
35+
36+
v = extractVMDriverVersion("version: v1.2.3")
37+
if expectedVersion != v {
38+
t.Errorf("Expected version: %s, got: %s", expectedVersion, v)
39+
}
40+
41+
v = extractVMDriverVersion("version: 1.2.3")
42+
if expectedVersion != v {
43+
t.Errorf("Expected version: %s, got: %s", expectedVersion, v)
44+
}
45+
}

Diff for: docs/drivers.md

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ the host PATH:
1616

1717
## KVM2 driver
1818

19+
### KVM2 install
20+
1921
To install the KVM2 driver, first install and configure the prerequisites, namely libvirt 1.3.1 or higher, and qemu-kvm:
2022

2123
* 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`:
7779
minikube config set vm-driver kvm2
7880
```
7981

82+
### KVM2 upgrade
83+
84+
```shell
85+
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 \
86+
&& sudo install docker-machine-driver-kvm2 /usr/local/bin/
87+
```
88+
8089
### KVM2 troubleshoot
8190

8291
If minikube can't start, check if the kvm default network exists.

Diff for: pkg/minikube/constants/constants.go

+5
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,8 @@ const (
431431
// GvisorURL is the url to download gvisor
432432
GvisorURL = "https://storage.googleapis.com/gvisor/releases/nightly/2018-12-07/runsc"
433433
)
434+
435+
const (
436+
// KVMDocumentation the documentation of the KVM driver
437+
KVMDocumentation = "https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver"
438+
)

0 commit comments

Comments
 (0)