Skip to content

Commit

Permalink
Improve stop unset
Browse files Browse the repository at this point in the history
  • Loading branch information
medyagh committed Jun 27, 2019
1 parent cd11465 commit b810234
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions cmd/minikube/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/docker/machine/libmachine/mcnerror"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
cmdUtil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube/cluster"
pkg_config "k8s.io/minikube/pkg/minikube/config"
Expand All @@ -44,7 +43,8 @@ itself, leaving all files intact. The cluster can be started again with the "sta

// runStop handles the executes the flow of "minikube stop"
func runStop(cmd *cobra.Command, args []string) {
profile := viper.GetString(pkg_config.MachineProfile)
profile := pkg_config.GetMachineName()

api, err := machine.NewAPIClient()
if err != nil {
exit.WithError("Error getting client", err)
Expand All @@ -64,9 +64,15 @@ func runStop(cmd *cobra.Command, args []string) {
return err
}
}
err = pkgutil.UnsetCurrentContext(constants.KubeconfigPath, profile)
if err != nil {
exit.WithError("Failed to unset the kubernetes current-context", err)
}

if err := pkgutil.RetryAfter(3, stop, 5*time.Second); err != nil {
exit.WithError("Unable to stop VM", err)
}

if !nonexistent {
console.OutStyle(console.Stopped, "%q stopped.", profile)
}
Expand All @@ -75,11 +81,6 @@ func runStop(cmd *cobra.Command, args []string) {
console.OutStyle(console.WarningType, "Unable to kill mount process: %s", err)
}

machineName := pkg_config.GetMachineName()
err = pkgutil.UnsetCurrentContext(constants.KubeconfigPath, machineName)
if err != nil {
exit.WithError("update config", err)
}
}
func init() {
RootCmd.AddCommand(stopCmd)
Expand Down
6 changes: 3 additions & 3 deletions test/integration/start_stop_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestStartStop(t *testing.T) {
}

checkStop := func() error {
r.RunCommand("stop", true)
r.RunCommand("stop", false)
err := r.CheckStatusNoFail(state.Stopped.String())
if err == nil {
// kubecctl's current-context after minikube stop
Expand All @@ -101,8 +101,8 @@ func TestStartStop(t *testing.T) {
return err
}

if err := util.Retry(t, checkStop, 13*time.Second, 3); err != nil {
t.Fatalf("timed out while checking stopped status: %v", err)
if err := util.Retry(t, checkStop, 7*time.Second, 3); err != nil {
t.Fatalf("Timed out checking stopped status: %v", err)
}

r.Start(test.args...)
Expand Down

0 comments on commit b810234

Please sign in to comment.