Skip to content

Commit 1a676ed

Browse files
authored
Merge pull request #21576 from medyagh/verify_aux_driver
verify aux drivers installed correctly and exit nicely if not
2 parents 1af8bdc + 50d4032 commit 1a676ed

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed

cmd/minikube/cmd/start.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@ func updateDriver(driverName string) {
534534
if err != nil {
535535
out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err})
536536
} else if err := auxdriver.InstallOrUpdate(driverName, localpath.MakeMiniPath("bin"), v, viper.GetBool(interactive), viper.GetBool(autoUpdate)); err != nil {
537+
if errors.Is(err, auxdriver.ErrAuxDriverVersionCommandFailed) {
538+
exit.Error(reason.DrvAuxNotHealthy, "Aux driver "+driverName, err)
539+
}
540+
if errors.Is(err, auxdriver.ErrAuxDriverVersionNotinPath) {
541+
exit.Error(reason.DrvAuxNotHealthy, "Aux driver"+driverName, err)
542+
} //if failed to update but not a fatal error, log it and continue (old version might still work)
537543
out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": driverName, "error": err})
538544
}
539545
}

pkg/minikube/driver/auxdriver/install.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ import (
3838
"k8s.io/minikube/pkg/util/lock"
3939
)
4040

41+
func newAuxUnthealthyError(path string) error {
42+
return fmt.Errorf(`failed to execute auxiliary version command "%s --version"`, path)
43+
}
44+
45+
func newAuxNotFoundError(name, path string) error {
46+
return fmt.Errorf("auxiliary driver %s not found in path %s", name, path)
47+
}
48+
49+
// ErrAuxDriverVersionCommandFailed indicates the aux driver 'version' command failed to run
50+
var ErrAuxDriverVersionCommandFailed error
51+
52+
// ErrAuxDriverVersionNotinPath was not found in PATH
53+
var ErrAuxDriverVersionNotinPath error
54+
4155
// InstallOrUpdate downloads driver if it is not present, or updates it if there's a newer version
4256
func InstallOrUpdate(name string, directory string, v semver.Version, interactive bool, autoUpdate bool) error {
4357
if name != driver.KVM2 && name != driver.HyperKit {
@@ -65,7 +79,14 @@ func InstallOrUpdate(name string, directory string, v semver.Version, interactiv
6579
return err
6680
}
6781
}
68-
return fixDriverPermissions(name, path, interactive)
82+
if err := fixDriverPermissions(name, path, interactive); err != nil {
83+
return err
84+
}
85+
86+
if _, err := validateDriver(executable, minAcceptableDriverVersion(name, v)); err != nil {
87+
return err
88+
}
89+
return nil
6990
}
7091

7192
// fixDriverPermissions fixes the permissions on a driver
@@ -117,12 +138,17 @@ func validateDriver(executable string, v semver.Version) (string, error) {
117138
klog.Infof("Validating %s, PATH=%s", executable, os.Getenv("PATH"))
118139
path, err := exec.LookPath(executable)
119140
if err != nil {
120-
return path, err
141+
klog.Warningf("driver not in path : %s, %v", path, err.Error())
142+
ErrAuxDriverVersionNotinPath = newAuxNotFoundError(executable, path)
143+
return path, ErrAuxDriverVersionNotinPath
121144
}
122145

123-
output, err := exec.Command(path, "version").Output()
146+
cmd := exec.Command(path, "version")
147+
output, err := cmd.CombinedOutput()
124148
if err != nil {
125-
return path, err
149+
klog.Warningf("%s failed: %v: %s", cmd, err, output)
150+
ErrAuxDriverVersionCommandFailed = newAuxUnthealthyError(path)
151+
return path, ErrAuxDriverVersionCommandFailed
126152
}
127153

128154
ev := extractDriverVersion(string(output))

pkg/minikube/reason/reason.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ var (
318318
DrvNotFound = Kind{ID: "DRV_NOT_FOUND", ExitCode: ExDriverNotFound}
319319
// minikube could not find a valid driver
320320
DrvNotDetected = Kind{ID: "DRV_NOT_DETECTED", ExitCode: ExDriverNotFound}
321+
// aux drivers (kvm or hyperkit) were not found
322+
DrvAuxNotNotFound = Kind{ID: "DRV_AUX_NOT_FOUND", ExitCode: ExDriverNotFound}
323+
// aux drivers (kvm or hyperkit) were found but not healthy
324+
DrvAuxNotHealthy = Kind{ID: "DRV_AUX_NOT_HEALTHY", ExitCode: ExDriverError}
321325
// minikube found drivers but none were ready to use
322326
DrvNotHealthy = Kind{ID: "DRV_NOT_HEALTHY", ExitCode: ExDriverNotFound}
323327
// minikube found the docker driver but the docker service was not running

test/integration/driver_install_or_update_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ func TestKVMDriverInstallOrUpdate(t *testing.T) {
5151
name string
5252
path string
5353
}{
54-
{name: "driver-without-version-support", path: filepath.Join(*testdataDir, "kvm2-driver-without-version")},
5554
{name: "driver-with-older-version", path: filepath.Join(*testdataDir, "kvm2-driver-older-version")},
5655
}
5756

5857
originalPath := os.Getenv("PATH")
5958
defer os.Setenv("PATH", originalPath)
6059

6160
for _, tc := range tests {
62-
dir := t.TempDir()
61+
tempDLDir := t.TempDir()
6362

6463
pwd, err := os.Getwd()
6564
if err != nil {
@@ -70,9 +69,19 @@ func TestKVMDriverInstallOrUpdate(t *testing.T) {
7069

7170
_, err = os.Stat(filepath.Join(path, "docker-machine-driver-kvm2"))
7271
if err != nil {
73-
t.Fatalf("Expected driver to exist. test: %s, got: %v", tc.name, err)
72+
t.Fatalf("Expected test data driver to exist. test: %s, got: %v", tc.name, err)
73+
}
74+
75+
// copy test data driver into the temp download dir so we can point PATH to it for before/after install
76+
src := filepath.Join(path, "docker-machine-driver-kvm2")
77+
dst := filepath.Join(tempDLDir, "docker-machine-driver-kvm2")
78+
if err = CopyFile(src, dst, false); err != nil {
79+
t.Fatalf("Failed to copy test data driver to temp dir. test: %s, got: %v", tc.name, err)
7480
}
7581

82+
// point to the copied driver for the rest of the test
83+
path = tempDLDir
84+
7685
// change permission to allow driver to be executable
7786
err = os.Chmod(filepath.Join(path, "docker-machine-driver-kvm2"), 0700)
7887
if err != nil {
@@ -82,17 +91,17 @@ func TestKVMDriverInstallOrUpdate(t *testing.T) {
8291
os.Setenv("PATH", fmt.Sprintf("%s:%s", path, originalPath))
8392

8493
// NOTE: This should be a real version, as it impacts the downloaded URL
85-
newerVersion, err := semver.Make("1.3.0")
94+
newerVersion, err := semver.Make("1.37.0")
8695
if err != nil {
8796
t.Fatalf("Expected new semver. test: %v, got: %v", tc.name, err)
8897
}
8998

90-
err = auxdriver.InstallOrUpdate("kvm2", dir, newerVersion, true, true)
99+
err = auxdriver.InstallOrUpdate("kvm2", tempDLDir, newerVersion, true, true)
91100
if err != nil {
92101
t.Fatalf("Failed to update driver to %v. test: %s, got: %v", newerVersion, tc.name, err)
93102
}
94103

95-
_, err = os.Stat(filepath.Join(dir, "docker-machine-driver-kvm2"))
104+
_, err = os.Stat(filepath.Join(tempDLDir, "docker-machine-driver-kvm2"))
96105
if err != nil {
97106
t.Fatalf("Expected driver to be download. test: %s, got: %v", tc.name, err)
98107
}
Binary file not shown.

0 commit comments

Comments
 (0)