Skip to content

Commit 280c251

Browse files
Merge pull request #8782 from sharifelgamal/regen-config
regenerate config on retry
2 parents f04a6a0 + c4cad39 commit 280c251

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

cmd/minikube/cmd/node_add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var nodeAddCmd = &cobra.Command{
6464
}
6565

6666
if err := node.Add(cc, n, false); err != nil {
67-
_, err := maybeDeleteAndRetry(*cc, n, nil, err)
67+
_, err := maybeDeleteAndRetry(cmd, *cc, n, nil, err)
6868
if err != nil {
6969
exit.WithError("failed to add node", err)
7070
}

cmd/minikube/cmd/node_start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var nodeStartCmd = &cobra.Command{
6969

7070
_, err = node.Start(s, false)
7171
if err != nil {
72-
_, err := maybeDeleteAndRetry(*cc, *n, nil, err)
72+
_, err := maybeDeleteAndRetry(cmd, *cc, *n, nil, err)
7373
if err != nil {
7474
node.MaybeExitWithAdvice(err)
7575
exit.WithError("failed to start node", err)

cmd/minikube/cmd/start.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func runStart(cmd *cobra.Command, args []string) {
200200
}
201201
}
202202

203-
kubeconfig, err := startWithDriver(starter, existing)
203+
kubeconfig, err := startWithDriver(cmd, starter, existing)
204204
if err != nil {
205205
node.MaybeExitWithAdvice(err)
206206
exit.WithError("failed to start node", err)
@@ -279,10 +279,10 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
279279
}, nil
280280
}
281281

282-
func startWithDriver(starter node.Starter, existing *config.ClusterConfig) (*kubeconfig.Settings, error) {
282+
func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config.ClusterConfig) (*kubeconfig.Settings, error) {
283283
kubeconfig, err := node.Start(starter, true)
284284
if err != nil {
285-
kubeconfig, err = maybeDeleteAndRetry(*starter.Cfg, *starter.Node, starter.ExistingAddons, err)
285+
kubeconfig, err = maybeDeleteAndRetry(cmd, *starter.Cfg, *starter.Node, starter.ExistingAddons, err)
286286
if err != nil {
287287
return nil, err
288288
}
@@ -411,20 +411,22 @@ func showKubectlInfo(kcs *kubeconfig.Settings, k8sVersion string, machineName st
411411
return nil
412412
}
413413

414-
func maybeDeleteAndRetry(cc config.ClusterConfig, n config.Node, existingAddons map[string]bool, originalErr error) (*kubeconfig.Settings, error) {
414+
func maybeDeleteAndRetry(cmd *cobra.Command, existing config.ClusterConfig, n config.Node, existingAddons map[string]bool, originalErr error) (*kubeconfig.Settings, error) {
415415
if viper.GetBool(deleteOnFailure) {
416416
out.WarningT("Node {{.name}} failed to start, deleting and trying again.", out.V{"name": n.Name})
417417
// Start failed, delete the cluster and try again
418-
profile, err := config.LoadProfile(cc.Name)
418+
profile, err := config.LoadProfile(existing.Name)
419419
if err != nil {
420-
out.ErrT(out.Meh, `"{{.name}}" profile does not exist, trying anyways.`, out.V{"name": cc.Name})
420+
out.ErrT(out.Meh, `"{{.name}}" profile does not exist, trying anyways.`, out.V{"name": existing.Name})
421421
}
422422

423423
err = deleteProfile(profile)
424424
if err != nil {
425-
out.WarningT("Failed to delete cluster {{.name}}, proceeding with retry anyway.", out.V{"name": cc.Name})
425+
out.WarningT("Failed to delete cluster {{.name}}, proceeding with retry anyway.", out.V{"name": existing.Name})
426426
}
427427

428+
// Re-generate the cluster config, just in case the failure was related to an old config format
429+
cc := updateExistingConfigFromFlags(cmd, &existing)
428430
var kubeconfig *kubeconfig.Settings
429431
for _, n := range cc.Nodes {
430432
r, p, m, h, err := node.Provision(&cc, &n, n.ControlPlane, false)

cmd/minikube/cmd/start_flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func ClusterFlagValue() string {
217217
// generateClusterConfig generate a config.ClusterConfig based on flags or existing cluster config
218218
func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k8sVersion string, drvName string) (config.ClusterConfig, config.Node, error) {
219219
var cc config.ClusterConfig
220-
if existing != nil { // create profile config first time
220+
if existing != nil {
221221
cc = updateExistingConfigFromFlags(cmd, existing)
222222
} else {
223223
glog.Info("no existing cluster config was found, will generate one from the flags ")

0 commit comments

Comments
 (0)