From 58dedbbb189610242aead3e0a6f3d99357e7483d Mon Sep 17 00:00:00 2001 From: Yanshu Zhao Date: Sat, 2 Jan 2021 08:35:02 +0000 Subject: [PATCH] Delete the existing cluster if guest driver mismatch --- cmd/minikube/cmd/start.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 5e40239fdc..40058f5298 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -668,16 +668,29 @@ func validateSpecifiedDriver(existing *config.ClusterConfig) { return } + out.WarningT("Start deleting cluster {{.name}} with delete-on-failure flag set", out.V{"name": existing.Name}) + if viper.GetBool(deleteOnFailure) { + // Start failed, delete the cluster + profile, err := config.LoadProfile(existing.Name) + if err != nil { + out.ErrT(style.Meh, `"{{.name}}" profile does not exist, trying anyways.`, out.V{"name": existing.Name}) + } + + err = deleteProfile(profile) + if err != nil { + out.WarningT("Failed to delete cluster {{.name}}.", out.V{"name": existing.Name}) + } + } + exit.Advice( reason.GuestDrvMismatch, - `The existing "{{.name}}" cluster was created using the "{{.old}}" driver, which is incompatible with requested "{{.new}}" driver.`, - "Delete the existing '{{.name}}' cluster using: '{{.delcommand}}', or start the existing '{{.name}}' cluster using: '{{.command}} --driver={{.old}}'", + `The existing "{{.name}}" cluster was created using the "{{.old}}" driver, which is incompatible with requested "{{.new}}" driver. Deleted the existing '{{.name}}' cluster.`, + "Start the new '{{.name}}' cluster using: '{{.command}} --driver={{.new}}'", out.V{ - "name": existing.Name, - "new": requested, - "old": old, - "command": mustload.ExampleCmd(existing.Name, "start"), - "delcommand": mustload.ExampleCmd(existing.Name, "delete"), + "name": existing.Name, + "new": requested, + "old": old, + "command": mustload.ExampleCmd(existing.Name, "start"), }, ) }