Skip to content

Commit

Permalink
Merge pull request #3665 from tstromberg/sudo-poweroff
Browse files Browse the repository at this point in the history
Run poweroff before delete, only call uninstall if driver is None
  • Loading branch information
tstromberg authored Feb 14, 2019
2 parents c29ef66 + eb00fdb commit 10d8487
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
14 changes: 7 additions & 7 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand All @@ -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 {
Expand All @@ -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)
},
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/minikube/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion pkg/minikube/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/console/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "🌐 "},
Expand All @@ -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},
Expand Down

0 comments on commit 10d8487

Please sign in to comment.