Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "stop" retry on failure. #3479

Merged
merged 1 commit into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we lose context here? I'd have to see the code to understand that this Load: ... error was at Stopping time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, there is no contextual difference between "Error loading host" and "Load".

}
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())
tstromberg marked this conversation as resolved.
Show resolved Hide resolved
}
m := util.MultiError{}
m.Collect(host.Driver.Remove())
Expand Down