Fix crash when the cluster doesn't exist
parent
45e5265c35
commit
bf4f77a780
|
@ -17,11 +17,11 @@ limitations under the License.
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/docker/machine/libmachine/mcnerror"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/docker/machine/libmachine/mcnerror"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
|
||||
|
@ -69,7 +69,7 @@ func runDelete(cmd *cobra.Command, args []string) {
|
|||
if err = cluster.DeleteHost(api); err != nil {
|
||||
switch err := 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": err.Name})
|
||||
default:
|
||||
exit.WithError("Failed to delete cluster", err)
|
||||
}
|
||||
|
|
|
@ -275,6 +275,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 {
|
||||
|
|
Loading…
Reference in New Issue