Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run poweroff before delete, only call uninstall if driver is None #3665

Merged
merged 4 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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