diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index eeba8e3e703a..99e11bb5c16b 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -54,10 +54,13 @@ associated files.`, cc, err := pkg_config.Load() if err != nil && !os.IsNotExist(err) { console.ErrLn("Error loading profile config: %v", err) - } else if err == nil { + } + + // In the case of "none", we want to uninstall Kubernetes as there is no VM to delete + if err == nil && cc.MachineConfig.VMDriver == "none" { kc := cc.KubernetesConfig - bsName := viper.GetString(cmdcfg.Bootstrapper) // Name ? - console.OutStyle("resetting", "Reverting Kubernetes %s using %s ...", kc.KubernetesVersion, bsName) + bsName := viper.GetString(cmdcfg.Bootstrapper) + console.OutStyle("resetting", "Uninstalling 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 { @@ -66,7 +69,6 @@ associated files.`, } } - 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: @@ -75,8 +77,6 @@ associated files.`, console.Fatal("Failed to delete VM: %v", err) os.Exit(1) } - } else { - console.OutStyle("crushed", "VM deleted.") } if err := cmdUtil.KillMountProcess(); err != nil { @@ -91,7 +91,7 @@ associated files.`, console.Fatal("Failed to remove profile: %v", err) os.Exit(1) } - console.Success("Removed %q profile!", profile) + console.OutStyle("crushed", "The %q cluster is now deleted. I hope you are happy.", profile) }, } diff --git a/cmd/minikube/cmd/stop.go b/cmd/minikube/cmd/stop.go index b4eeadebfee3..43868ce6bd22 100644 --- a/cmd/minikube/cmd/stop.go +++ b/cmd/minikube/cmd/stop.go @@ -40,8 +40,6 @@ var stopCmd = &cobra.Command{ itself, leaving all files intact. The cluster can be started again with the "start" command.`, Run: func(cmd *cobra.Command, args []string) { profile := viper.GetString(pkg_config.MachineProfile) - console.OutStyle("stopping", "Stopping %q Kubernetes cluster...", profile) - api, err := machine.NewAPIClient() if err != nil { console.Fatal("Error getting client: %v", err) diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index 23d7a90c1dc9..08a34b0defac 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -125,12 +125,34 @@ func StartHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) return h, nil } -// StopHost stops the host VM. +// tryPowerOff runs the poweroff command on the guest VM to speed up deletion +func tryPowerOff(h *host.Host) { + if h.Driver.DriverName() == "none" { + return + } + s, err := h.Driver.GetState() + if err != nil { + glog.Warningf("unable to get state: %v", err) + return + } + if s != state.Running { + glog.Infof("host is in state %s", s) + return + } + + console.OutStyle("shutdown", "Powering off %q via SSH ...", cfg.GetMachineName()) + out, err := h.RunSSHCommand("sudo poweroff") + // poweroff always results in an error, since the host disconnects. + glog.Infof("poweroff result: out=%s, err=%v", out, err) +} + +// StopHost stops the host VM, saving state to disk. func StopHost(api libmachine.API) error { host, err := api.Load(cfg.GetMachineName()) if err != nil { return errors.Wrapf(err, "load") } + console.OutStyle("stopping", "Stopping %q in %s ...", cfg.GetMachineName(), host.DriverName) if err := host.Stop(); err != nil { alreadyInStateError, ok := err.(mcnerror.ErrHostAlreadyInState) if ok && alreadyInStateError.State == state.Stopped { @@ -147,6 +169,8 @@ func DeleteHost(api libmachine.API) error { if err != nil { return errors.Wrap(err, "load") } + tryPowerOff(host) + console.OutStyle("deleting-host", "Deleting %q from %s ...", cfg.GetMachineName(), host.DriverName) if err := host.Driver.Remove(); err != nil { return errors.Wrap(err, "host remove") } diff --git a/pkg/minikube/console/style.go b/pkg/minikube/console/style.go index 9816eebe6c41..dca35c60f3f5 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/console/style.go @@ -58,7 +58,7 @@ var styles = map[string]style{ "starting-vm": {Prefix: "๐Ÿ”ฅ "}, "starting-none": {Prefix: "๐Ÿคน "}, "resetting": {Prefix: "๐Ÿ”„ "}, - "deleting-vm": {Prefix: "๐Ÿ”ฅ "}, + "deleting-host": {Prefix: "๐Ÿ”ฅ "}, "copying": {Prefix: "โœจ "}, "connectivity": {Prefix: "๐Ÿ“ถ "}, "internet": {Prefix: "๐ŸŒ "}, @@ -70,6 +70,7 @@ var styles = map[string]style{ "containerd": {Prefix: "๐Ÿ“ฆ "}, "permissions": {Prefix: "๐Ÿ”‘ "}, "enabling": {Prefix: "๐Ÿ”Œ "}, + "shutdown": {Prefix: "๐Ÿ›‘ "}, "pulling": {Prefix: "๐Ÿšœ "}, "verifying": {Prefix: "๐Ÿค” "}, "verifying-noline": {Prefix: "๐Ÿค” ", OmitNewline: true},