Skip to content

Commit

Permalink
Merge pull request #4980 from blueelvis/4459-delete-even-if-vm-doesnt…
Browse files Browse the repository at this point in the history
…-exist

Fix crash when deleting the cluster but it doesn't exist
  • Loading branch information
tstromberg authored Sep 23, 2019
2 parents 1c8bfe3 + b14d83f commit 213f93d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"path/filepath"
"strconv"

"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/mcnerror"
"github.com/golang/glog"
ps "github.com/mitchellh/go-ps"
"github.com/pkg/errors"

"github.com/docker/machine/libmachine"
"github.com/spf13/cobra"
"github.com/spf13/viper"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
Expand Down Expand Up @@ -79,7 +80,7 @@ func runDelete(cmd *cobra.Command, args []string) {
if err = cluster.DeleteHost(api); err != nil {
switch errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist:
out.T(out.Meh, `"{{.name}}" cluster does not exist`, out.V{"name": profile})
out.T(out.Meh, `"{{.name}}" cluster does not exist. Proceeding ahead with cleanup.`, out.V{"name": profile})
default:
out.T(out.FailureType, "Failed to delete cluster: {{.error}}", out.V{"error": err})
out.T(out.Notice, `You may need to manually remove the "{{.name}}" VM from your hypervisor`, out.V{"name": profile})
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ func DeleteHost(api libmachine.API) error {
if err != nil {
return errors.Wrap(err, "load")
}

// Get the status of the host. Ensure that it exists before proceeding ahead.
status, err := GetHostStatus(api)
if err != nil {
exit.WithCodeT(exit.Failure, "Unable to get the status of the cluster.")
}
if status == state.None.String() {
return mcnerror.ErrHostDoesNotExist{Name: host.Name}
}

// This is slow if SSH is not responding, but HyperV hangs otherwise, See issue #2914
if host.Driver.DriverName() == constants.DriverHyperv {
if err := trySSHPowerOff(host); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions site/content/en/docs/Contributing/building.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ make

Note: On Windows, this will only work in Git Bash or other terminals that support bash commands.

You can also build platform specific executables like below:
1. `make windows` will build the binary for Windows platform
2. `make linux` will build the binary for Linux platform
3. `make darwin` will build the binary for Darwin/Mac platform

## Compiling minikube using Docker

To cross-compile to/from different operating systems:
Expand Down

0 comments on commit 213f93d

Please sign in to comment.