From b810234154e7520878a574da653e9af684676988 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Thu, 27 Jun 2019 13:12:51 -0700 Subject: [PATCH] Improve stop unset --- cmd/minikube/cmd/stop.go | 15 ++++++++------- test/integration/start_stop_delete_test.go | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/minikube/cmd/stop.go b/cmd/minikube/cmd/stop.go index aa72ee11149d..140f64cedc7e 100644 --- a/cmd/minikube/cmd/stop.go +++ b/cmd/minikube/cmd/stop.go @@ -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" @@ -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) @@ -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) } @@ -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) diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index 56e89391275f..2d123de2c0da 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -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 @@ -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...)