diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index 6c3f6ea6150a..03da06be14bd 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -23,6 +23,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" + cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config" cmdUtil "k8s.io/minikube/cmd/util" "k8s.io/minikube/pkg/minikube/cluster" pkg_config "k8s.io/minikube/pkg/minikube/config" @@ -43,7 +44,6 @@ associated files.`, os.Exit(1) } profile := viper.GetString(pkg_config.MachineProfile) - console.OutStyle("deleting-vm", "Deleting %q Kubernetes cluster ...", profile) api, err := machine.NewAPIClient() if err != nil { console.Fatal("Error getting client: %v", err) @@ -51,6 +51,22 @@ associated files.`, } defer api.Close() + cc, err := pkg_config.Load() + if err != nil && !os.IsNotExist(err) { + console.ErrLn("Error loading profile config: %v", err) + } else if err == nil { + kc := cc.KubernetesConfig + bsName := viper.GetString(cmdcfg.Bootstrapper) // Name ? + console.OutStyle("resetting", "Reverting Kubernetes %s using %s ...", kc.KubernetesVersion, bsName) + clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper)) + if err != nil { + if err = clusterBootstrapper.DeleteCluster(kc); err != nil { + console.ErrLn("Failed to delete cluster: %v", err) + } + } + } + + console.OutStyle("deleting-vm", "Deleting %q Kubernetes VM ...", profile) if err = cluster.DeleteHost(api); err != nil { switch err := errors.Cause(err).(type) { case mcnerror.ErrHostDoesNotExist: diff --git a/pkg/minikube/bootstrapper/bootstrapper.go b/pkg/minikube/bootstrapper/bootstrapper.go index fb7f1058d817..6cd961b18d45 100644 --- a/pkg/minikube/bootstrapper/bootstrapper.go +++ b/pkg/minikube/bootstrapper/bootstrapper.go @@ -31,6 +31,7 @@ type Bootstrapper interface { StartCluster(config.KubernetesConfig) error UpdateCluster(config.KubernetesConfig) error RestartCluster(config.KubernetesConfig) error + DeleteCluster(config.KubernetesConfig) error GetClusterLogsTo(follow bool, out io.Writer) error SetupCerts(cfg config.KubernetesConfig) error GetKubeletStatus() (string, error) diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 54016046ee46..1eb4d0fe8fe4 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -253,6 +253,16 @@ func (k *KubeadmBootstrapper) RestartCluster(k8s config.KubernetesConfig) error return nil } +// DeleteCluster removes the components that were started earlier +func (k *KubeadmBootstrapper) DeleteCluster(k8s config.KubernetesConfig) error { + cmd := fmt.Sprintf("sudo kubeadm reset --config %s", constants.KubeadmConfigFile) + if err := k.c.Run(cmd); err != nil { + return errors.Wrapf(err, "running cmd: %s", cmd) + } + + return nil +} + // PullImages downloads images that will be used by RestartCluster func (k *KubeadmBootstrapper) PullImages(k8s config.KubernetesConfig) error { cmd := fmt.Sprintf("sudo kubeadm config images pull --config %s", constants.KubeadmConfigFile) diff --git a/pkg/minikube/console/style.go b/pkg/minikube/console/style.go index 4ad047180084..1380769995b5 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/console/style.go @@ -57,6 +57,7 @@ var styles = map[string]style{ "caching": {Prefix: "๐Ÿคน "}, "starting-vm": {Prefix: "๐Ÿ”ฅ "}, "starting-none": {Prefix: "๐Ÿคน "}, + "resetting": {Prefix: "๐Ÿ”„ "}, "deleting-vm": {Prefix: "๐Ÿ”ฅ "}, "copying": {Prefix: "โœจ "}, "connectivity": {Prefix: "๐Ÿ“ถ "},