Skip to content

Commit 8a4bf13

Browse files
committed
Add warn if kvm driver version is old
1 parent 68c546f commit 8a4bf13

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

cmd/minikube/cmd/start.go

+51
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,51 @@ 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, libmachine has a nice message for the user if
863+
// 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 len(v) == 0 {
872+
exit.WithCode(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'.")
873+
}
874+
875+
vmDriverVersion, err := semver.Make(v)
876+
if err != nil {
877+
console.Warning("Error parsing vmDriver version: %v", err)
878+
return
879+
}
880+
881+
minikubeVersion, err := version.GetSemverVersion()
882+
if err != nil {
883+
console.Warning("Error parsing minukube version: %v", err)
884+
return
885+
}
886+
887+
if vmDriverVersion.LT(minikubeVersion) {
888+
console.Warning("The 'docker-machine-driver-kvm2' version is old. Please consider upgrading.")
889+
}
890+
}
891+
}
892+
893+
func extractVMDriverVersion(s string) string {
894+
versionRegex := regexp.MustCompile(`version:(.*)`)
895+
matches := versionRegex.FindStringSubmatch(s)
896+
897+
if len(matches) != 2 {
898+
return ""
899+
}
900+
901+
v := strings.TrimSpace(matches[1])
902+
return strings.TrimPrefix(v, version.VersionPrefix)
903+
}

cmd/minikube/cmd/start_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2016 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+
}

0 commit comments

Comments
 (0)