Skip to content

Commit 679b0c6

Browse files
authored
Merge pull request #7160 from kubernetes/stop-retry
hyperv Delete: call StopHost before removing VM
2 parents 84d3dc3 + 14f8ee3 commit 679b0c6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

cmd/minikube/cmd/delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func deleteProfileDirectory(profile string) {
402402
out.T(out.DeletingHost, `Removing {{.directory}} ...`, out.V{"directory": machineDir})
403403
err := os.RemoveAll(machineDir)
404404
if err != nil {
405-
exit.WithError("Unable to remove machine directory: %v", err)
405+
exit.WithError("Unable to remove machine directory", err)
406406
}
407407
}
408408
}

pkg/minikube/machine/delete.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,26 @@ func DeleteHost(api libmachine.API, machineName string) error {
7575
return mcnerror.ErrHostDoesNotExist{Name: machineName}
7676
}
7777

78-
// This is slow if SSH is not responding, but HyperV hangs otherwise, See issue #2914
78+
// Hyper-V requires special care to avoid ACPI and file locking issues
7979
if host.Driver.DriverName() == driver.HyperV {
80-
if err := trySSHPowerOff(host); err != nil {
81-
glog.Infof("Unable to power off minikube because the host was not found.")
80+
if err := StopHost(api, machineName); err != nil {
81+
glog.Warningf("stop host: %v", err)
8282
}
83-
out.T(out.DeletingHost, "Successfully powered off Hyper-V. minikube driver -- {{.driver}}", out.V{"driver": host.Driver.DriverName()})
83+
// Hack: give the Hyper-V VM more time to stop before deletion
84+
time.Sleep(1 * time.Second)
8485
}
8586

8687
out.T(out.DeletingHost, `Deleting "{{.profile_name}}" in {{.driver_name}} ...`, out.V{"profile_name": machineName, "driver_name": host.DriverName})
8788
if err := host.Driver.Remove(); err != nil {
88-
return errors.Wrap(err, "host remove")
89+
glog.Warningf("remove failed, will retry: %v", err)
90+
time.Sleep(2 * time.Second)
91+
92+
nerr := host.Driver.Remove()
93+
if nerr != nil {
94+
return errors.Wrap(nerr, "host remove retry")
95+
}
8996
}
97+
9098
if err := api.Remove(machineName); err != nil {
9199
return errors.Wrap(err, "api remove")
92100
}

0 commit comments

Comments
 (0)