Fix crash when the cluster doesn't exist

pull/4980/head
Pranav Jituri 2019-08-05 01:22:18 +05:30
parent 45e5265c35
commit bf4f77a780
No known key found for this signature in database
GPG Key ID: 009BB1DF4550490B
2 changed files with 13 additions and 3 deletions

View File

@ -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)
}

View File

@ -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 {