Merge pull request #3479 from tstromberg/stop-retry

Make "stop" retry on failure.
pull/3483/head
Thomas Strömberg 2018-12-20 19:46:24 -08:00 committed by GitHub
commit ab64cb952e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -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)
}

View File

@ -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())