Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyperv Delete: call StopHost before removing VM #7160

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
tstromberg marked this conversation as resolved.
Show resolved Hide resolved
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