diff --git a/cmd/minikube/cmd/stop.go b/cmd/minikube/cmd/stop.go index 709783091194..a4061162b70c 100644 --- a/cmd/minikube/cmd/stop.go +++ b/cmd/minikube/cmd/stop.go @@ -19,11 +19,13 @@ package cmd import ( "fmt" "os" + "time" "github.com/spf13/cobra" cmdUtil "k8s.io/minikube/cmd/util" "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/machine" + pkgutil "k8s.io/minikube/pkg/util" ) // stopCmd represents the stop command @@ -41,7 +43,10 @@ itself, leaving all files intact. The cluster can be started again with the "sta } defer api.Close() - if err = cluster.StopHost(api); err != nil { + stop := func() (err error) { + return cluster.StopHost(api) + } + if err := pkgutil.RetryAfter(5, stop, 1*time.Second); err != nil { fmt.Println("Error stopping machine: ", err) cmdUtil.MaybeReportErrorAndExit(err) } diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index 08d9f16d13c6..96af0a4d3f3f 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -105,14 +105,14 @@ func StartHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) func StopHost(api libmachine.API) error { host, err := api.Load(cfg.GetMachineName()) if err != nil { - return errors.Wrapf(err, "Error loading host: %s", cfg.GetMachineName()) + return errors.Wrapf(err, "Load: %s", cfg.GetMachineName()) } if err := host.Stop(); err != nil { alreadyInStateError, ok := err.(mcnerror.ErrHostAlreadyInState) if ok && alreadyInStateError.State == state.Stopped { return nil } - return errors.Wrapf(err, "Error stopping host: %s", cfg.GetMachineName()) + return &util.RetriableError{Err: errors.Wrapf(err, "Stop: %s", cfg.GetMachineName())} } return nil } @@ -121,7 +121,7 @@ func StopHost(api libmachine.API) error { func DeleteHost(api libmachine.API) error { host, err := api.Load(cfg.GetMachineName()) if err != nil { - return errors.Wrapf(err, "Error deleting host: %s", cfg.GetMachineName()) + return errors.Wrapf(err, "Load: %s", cfg.GetMachineName()) } m := util.MultiError{} m.Collect(host.Driver.Remove())