From f33ac4c221aebfd27ae23c8d0bd72944f7331f29 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Mon, 20 Jul 2020 15:26:18 -0700 Subject: [PATCH 1/2] regenerate config on retry --- cmd/minikube/cmd/node_add.go | 2 +- cmd/minikube/cmd/node_start.go | 2 +- cmd/minikube/cmd/start.go | 10 ++++++---- cmd/minikube/cmd/start_flags.go | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/minikube/cmd/node_add.go b/cmd/minikube/cmd/node_add.go index de1ce7f92d57..32989ff29c7b 100644 --- a/cmd/minikube/cmd/node_add.go +++ b/cmd/minikube/cmd/node_add.go @@ -64,7 +64,7 @@ var nodeAddCmd = &cobra.Command{ } if err := node.Add(cc, n, false); err != nil { - _, err := maybeDeleteAndRetry(*cc, n, nil, err) + _, err := maybeDeleteAndRetry(cc, n, nil, err) if err != nil { exit.WithError("failed to add node", err) } diff --git a/cmd/minikube/cmd/node_start.go b/cmd/minikube/cmd/node_start.go index 47c6553ac2c7..aa80cc271ebf 100644 --- a/cmd/minikube/cmd/node_start.go +++ b/cmd/minikube/cmd/node_start.go @@ -69,7 +69,7 @@ var nodeStartCmd = &cobra.Command{ _, err = node.Start(s, false) if err != nil { - _, err := maybeDeleteAndRetry(*cc, *n, nil, err) + _, err := maybeDeleteAndRetry(cc, *n, nil, err) if err != nil { node.MaybeExitWithAdvice(err) exit.WithError("failed to start node", err) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index c3029a63768c..6b2a4c950888 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -282,7 +282,7 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing * func startWithDriver(starter node.Starter, existing *config.ClusterConfig) (*kubeconfig.Settings, error) { kubeconfig, err := node.Start(starter, true) if err != nil { - kubeconfig, err = maybeDeleteAndRetry(*starter.Cfg, *starter.Node, starter.ExistingAddons, err) + kubeconfig, err = maybeDeleteAndRetry(starter.Cfg, *starter.Node, starter.ExistingAddons, err) if err != nil { return nil, err } @@ -411,7 +411,7 @@ 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, error) { +func maybeDeleteAndRetry(cc *config.ClusterConfig, n config.Node, existingAddons map[string]bool, originalErr error) (*kubeconfig.Settings, error) { if viper.GetBool(deleteOnFailure) { out.WarningT("Node {{.name}} failed to start, deleting and trying again.", out.V{"name": n.Name}) // Start failed, delete the cluster and try again @@ -425,15 +425,17 @@ func maybeDeleteAndRetry(cc config.ClusterConfig, n config.Node, existingAddons out.WarningT("Failed to delete cluster {{.name}}, proceeding with retry anyway.", out.V{"name": cc.Name}) } + // Re-generate the cluster config, just in case the failure was related to an old config format + upgradeExistingConfig(cc) var kubeconfig *kubeconfig.Settings for _, n := range cc.Nodes { - r, p, m, h, err := node.Provision(&cc, &n, n.ControlPlane, false) + r, p, m, h, err := node.Provision(cc, &n, n.ControlPlane, false) s := node.Starter{ Runner: r, PreExists: p, MachineAPI: m, Host: h, - Cfg: &cc, + Cfg: cc, Node: &n, ExistingAddons: existingAddons, } diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index c24bd6fad5db..c6a448d021ab 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -217,7 +217,7 @@ func ClusterFlagValue() string { // generateClusterConfig generate a config.ClusterConfig based on flags or existing cluster config func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k8sVersion string, drvName string) (config.ClusterConfig, config.Node, error) { var cc config.ClusterConfig - if existing != nil { // create profile config first time + if existing != nil { cc = updateExistingConfigFromFlags(cmd, existing) } else { glog.Info("no existing cluster config was found, will generate one from the flags ") From c4cad39fac70dae7a00a74a19b483551e077dfbb Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Tue, 21 Jul 2020 12:02:09 -0700 Subject: [PATCH 2/2] properly regenerate config --- cmd/minikube/cmd/node_add.go | 2 +- cmd/minikube/cmd/node_start.go | 2 +- cmd/minikube/cmd/start.go | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/minikube/cmd/node_add.go b/cmd/minikube/cmd/node_add.go index 32989ff29c7b..ab7e422a835a 100644 --- a/cmd/minikube/cmd/node_add.go +++ b/cmd/minikube/cmd/node_add.go @@ -64,7 +64,7 @@ var nodeAddCmd = &cobra.Command{ } if err := node.Add(cc, n, false); err != nil { - _, err := maybeDeleteAndRetry(cc, n, nil, err) + _, err := maybeDeleteAndRetry(cmd, *cc, n, nil, err) if err != nil { exit.WithError("failed to add node", err) } diff --git a/cmd/minikube/cmd/node_start.go b/cmd/minikube/cmd/node_start.go index aa80cc271ebf..bfc8431218ff 100644 --- a/cmd/minikube/cmd/node_start.go +++ b/cmd/minikube/cmd/node_start.go @@ -69,7 +69,7 @@ var nodeStartCmd = &cobra.Command{ _, err = node.Start(s, false) if err != nil { - _, err := maybeDeleteAndRetry(cc, *n, nil, err) + _, err := maybeDeleteAndRetry(cmd, *cc, *n, nil, err) if err != nil { node.MaybeExitWithAdvice(err) exit.WithError("failed to start node", err) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 6b2a4c950888..cb109f852c13 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -200,7 +200,7 @@ func runStart(cmd *cobra.Command, args []string) { } } - kubeconfig, err := startWithDriver(starter, existing) + kubeconfig, err := startWithDriver(cmd, starter, existing) if err != nil { node.MaybeExitWithAdvice(err) exit.WithError("failed to start node", err) @@ -279,10 +279,10 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing * }, nil } -func startWithDriver(starter node.Starter, existing *config.ClusterConfig) (*kubeconfig.Settings, error) { +func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config.ClusterConfig) (*kubeconfig.Settings, error) { kubeconfig, err := node.Start(starter, true) if err != nil { - kubeconfig, err = maybeDeleteAndRetry(starter.Cfg, *starter.Node, starter.ExistingAddons, err) + kubeconfig, err = maybeDeleteAndRetry(cmd, *starter.Cfg, *starter.Node, starter.ExistingAddons, err) if err != nil { return nil, err } @@ -411,31 +411,31 @@ 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, error) { +func maybeDeleteAndRetry(cmd *cobra.Command, existing config.ClusterConfig, n config.Node, existingAddons map[string]bool, originalErr error) (*kubeconfig.Settings, error) { if viper.GetBool(deleteOnFailure) { out.WarningT("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) + profile, err := config.LoadProfile(existing.Name) if err != nil { - out.ErrT(out.Meh, `"{{.name}}" profile does not exist, trying anyways.`, out.V{"name": cc.Name}) + out.ErrT(out.Meh, `"{{.name}}" profile does not exist, trying anyways.`, out.V{"name": existing.Name}) } err = deleteProfile(profile) if err != nil { - out.WarningT("Failed to delete cluster {{.name}}, proceeding with retry anyway.", out.V{"name": cc.Name}) + out.WarningT("Failed to delete cluster {{.name}}, proceeding with retry anyway.", out.V{"name": existing.Name}) } // Re-generate the cluster config, just in case the failure was related to an old config format - upgradeExistingConfig(cc) + cc := updateExistingConfigFromFlags(cmd, &existing) var kubeconfig *kubeconfig.Settings for _, n := range cc.Nodes { - r, p, m, h, err := node.Provision(cc, &n, n.ControlPlane, false) + r, p, m, h, err := node.Provision(&cc, &n, n.ControlPlane, false) s := node.Starter{ Runner: r, PreExists: p, MachineAPI: m, Host: h, - Cfg: cc, + Cfg: &cc, Node: &n, ExistingAddons: existingAddons, }