提交 d8151730 编写于 作者: S Sharif Elgamal

retry anytime node.Start fails, not just in minikube start

上级 673922c8
......@@ -18,10 +18,8 @@ package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
......@@ -56,7 +54,7 @@ var nodeAddCmd = &cobra.Command{
}
if err := node.Add(cc, n); err != nil {
exit.WithError("Error adding node to cluster", err)
maybeDeleteAndRetry(*cc, n, nil, err)
}
out.T(out.Ready, "Successfully added {{.name}} to {{.cluster}}!", out.V{"name": name, "cluster": cc.Name})
......@@ -64,13 +62,10 @@ var nodeAddCmd = &cobra.Command{
}
func init() {
//We should figure out which minikube start flags to actually import
nodeAddCmd.Flags().BoolVar(&cp, "control-plane", false, "If true, the node added will also be a control plane in addition to a worker.")
nodeAddCmd.Flags().BoolVar(&worker, "worker", true, "If true, the added node will be marked for work. Defaults to true.")
//We should figure out which of these flags to actually import
startCmd.Flags().Visit(
func(f *pflag.Flag) {
nodeAddCmd.Flags().AddFlag(f)
},
)
nodeAddCmd.Flags().Bool(deleteOnFailure, false, "If set, delete the current cluster if start fails and try again. Defaults to false.")
nodeCmd.AddCommand(nodeAddCmd)
}
......@@ -49,15 +49,15 @@ var nodeStartCmd = &cobra.Command{
exit.WithError("retrieving node", err)
}
// Start it up baby
_, err = node.Start(*cc, *n, nil, false)
if err != nil {
exit.WithError("starting node", err)
maybeDeleteAndRetry(*cc, *n, nil, err)
}
},
}
func init() {
nodeStartCmd.Flags().String("name", "", "The name of the node to start")
nodeStartCmd.Flags().Bool(deleteOnFailure, false, "If set, delete the current cluster if start fails and try again. Defaults to false.")
nodeCmd.AddCommand(nodeStartCmd)
}
......@@ -356,24 +356,8 @@ func runStart(cmd *cobra.Command, args []string) {
}
kubeconfig, err := node.Start(cc, n, existingAddons, true)
if err != nil && viper.GetBool(deleteOnFailure) {
out.T(out.Warning, "Node {{.name}} failed to start, deleting and trying again.", out.V{"name": n.Name})
// Start failed, delete the cluster and try again
profile, err := config.LoadProfile(cc.Name)
if err != nil {
out.ErrT(out.Meh, `"{{.name}}" profile does not exist, trying anyways.`, out.V{"name": cc.Name})
}
err = deleteProfile(profile)
if err != nil {
out.WarningT("Failed to delete cluster {{.name}}, proceeding with retry anyway.", out.V{"name": cc.Name})
}
kubeconfig, err = node.Start(cc, n, existingAddons, true)
if err != nil {
// Ok we failed again, let's bail
exit.WithError("Start failed after cluster deletion", err)
}
if err != nil {
kubeconfig = maybeDeleteAndRetry(cc, n, existingAddons, err)
}
numNodes := viper.GetInt(nodes)
......@@ -488,6 +472,38 @@ func showKubectlInfo(kcs *kubeconfig.Settings, k8sVersion string, machineName st
return nil
}
func maybeDeleteAndRetry(cc config.ClusterConfig, n config.Node, existingAddons map[string]bool, originalErr error) *kubeconfig.Settings {
if viper.GetBool(deleteOnFailure) {
out.T(out.Warning, "Node {{.name}} failed to start, deleting and trying again.", out.V{"name": n.Name})
// Start failed, delete the cluster and try again
profile, err := config.LoadProfile(cc.Name)
if err != nil {
out.ErrT(out.Meh, `"{{.name}}" profile does not exist, trying anyways.`, out.V{"name": cc.Name})
}
err = deleteProfile(profile)
if err != nil {
out.WarningT("Failed to delete cluster {{.name}}, proceeding with retry anyway.", out.V{"name": cc.Name})
}
var kubeconfig *kubeconfig.Settings
for _, v := range cc.Nodes {
k, err := node.Start(cc, v, existingAddons, v.ControlPlane)
if v.ControlPlane {
kubeconfig = k
}
if err != nil {
// Ok we failed again, let's bail
exit.WithError("Start failed after cluster deletion", err)
}
}
return kubeconfig
}
// Don't delete the cluster unless they ask
exit.WithError("startup failed", originalErr)
return nil
}
func selectDriver(existing *config.ClusterConfig) registry.DriverState {
// Technically unrelated, but important to perform before detection
driver.SetLibvirtURI(viper.GetString(kvmQemuURI))
......
......@@ -39,7 +39,6 @@ func Add(cc *config.ClusterConfig, n config.Node) error {
return errors.Wrap(err, "save node")
}
// TODO: Start should return an error rather than calling exit!
_, err := Start(*cc, n, nil, false)
return err
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册