Skip to content

Commit

Permalink
Warn if hyperkit version is old (#4691)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
josedonizetti authored and sharifelgamal committed Jul 22, 2019
1 parent bcf3597 commit 6a5fbba
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
78 changes: 50 additions & 28 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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},
)
}
}

Expand Down
7 changes: 7 additions & 0 deletions docs/drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 6a5fbba

Please sign in to comment.