Skip to content

Commit

Permalink
Merge pull request #7160 from kubernetes/stop-retry
Browse files Browse the repository at this point in the history
hyperv Delete: call StopHost before removing VM
  • Loading branch information
tstromberg authored Mar 23, 2020
2 parents 84d3dc3 + 14f8ee3 commit 679b0c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func deleteProfileDirectory(profile string) {
out.T(out.DeletingHost, `Removing {{.directory}} ...`, out.V{"directory": machineDir})
err := os.RemoveAll(machineDir)
if err != nil {
exit.WithError("Unable to remove machine directory: %v", err)
exit.WithError("Unable to remove machine directory", err)
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions pkg/minikube/machine/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,26 @@ func DeleteHost(api libmachine.API, machineName string) error {
return mcnerror.ErrHostDoesNotExist{Name: machineName}
}

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

out.T(out.DeletingHost, `Deleting "{{.profile_name}}" in {{.driver_name}} ...`, out.V{"profile_name": machineName, "driver_name": host.DriverName})
if err := host.Driver.Remove(); err != nil {
return errors.Wrap(err, "host remove")
glog.Warningf("remove failed, will retry: %v", err)
time.Sleep(2 * time.Second)

nerr := host.Driver.Remove()
if nerr != nil {
return errors.Wrap(nerr, "host remove retry")
}
}

if err := api.Remove(machineName); err != nil {
return errors.Wrap(err, "api remove")
}
Expand Down

0 comments on commit 679b0c6

Please sign in to comment.