Skip to content

Commit

Permalink
Merge pull request #4676 from josedonizetti/warn-if-kvm2-version-is-old
Browse files Browse the repository at this point in the history
Add warn if kvm driver version is old
  • Loading branch information
medyagh authored Jul 5, 2019
2 parents 24bb4f3 + 4cce597 commit cc99602
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
57 changes: 57 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os/exec"
"os/user"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -850,3 +853,57 @@ 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 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'. %s", constants.KVMDocumentation)
}

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. %s", constants.KVMDocumentation)
}
}
}

// 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)

if len(matches) != 2 {
return ""
}

v := strings.TrimSpace(matches[1])
return strings.TrimPrefix(v, version.VersionPrefix)
}
45 changes: 45 additions & 0 deletions cmd/minikube/cmd/start_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
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.
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)
}
}
9 changes: 9 additions & 0 deletions docs/drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit cc99602

Please sign in to comment.