Skip to content

Commit

Permalink
Merge pull request #3479 from tstromberg/stop-retry
Browse files Browse the repository at this point in the history
Make "stop" retry on failure.
  • Loading branch information
tstromberg authored Dec 21, 2018
2 parents ad57efb + c250a3b commit ab64cb9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cmd/minikube/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/minikube/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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())
Expand Down

0 comments on commit ab64cb9

Please sign in to comment.