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

Fix crash when deleting the cluster but it doesn't exist #4980

Merged
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
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 @@ -78,7 +79,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 @@ -280,6 +280,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