Skip to content

Commit

Permalink
fix: reset fails on worker nodes after an upgrade (#1356)
Browse files Browse the repository at this point in the history
* fix: reset fails on worker nodes after an upgrade

* feedback
  • Loading branch information
emosbaugh authored Oct 21, 2024
1 parent a581c4f commit f6e2521
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
18 changes: 17 additions & 1 deletion cmd/embedded-cluster/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func getLocalArtifactMirrorPortFlag(runtimeConfig *ecv1beta1.RuntimeConfigSpec)
}
}

func getDataDirFlag(runtimeConfig *ecv1beta1.RuntimeConfigSpec) cli.Flag {
func getDataDirFlagWithDefault(runtimeConfig *ecv1beta1.RuntimeConfigSpec) *cli.StringFlag {
return &cli.StringFlag{
Name: "data-dir",
Usage: "Path to the data directory",
Expand All @@ -74,3 +74,19 @@ func getDataDirFlag(runtimeConfig *ecv1beta1.RuntimeConfigSpec) cli.Flag {
},
}
}

func getDataDirFlag(runtimeConfig *ecv1beta1.RuntimeConfigSpec) *cli.StringFlag {
return &cli.StringFlag{
Name: "data-dir",
Usage: "Path to the data directory (default discovered from the cluster)",
Hidden: false,
Action: func(c *cli.Context, s string) error {
if s == "" {
return nil
}
logrus.Debugf("Setting data dir to %s from flag", s)
runtimeConfig.DataDir = s
return nil
},
}
}
2 changes: 1 addition & 1 deletion cmd/embedded-cluster/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func installCommand() *cli.Command {
Name: "airgap-bundle",
Usage: "Path to the air gap bundle. If set, the installation will complete without internet access.",
},
getDataDirFlag(runtimeConfig),
getDataDirFlagWithDefault(runtimeConfig),
&cli.StringFlag{
Name: "license",
Aliases: []string{"l"},
Expand Down
2 changes: 1 addition & 1 deletion cmd/embedded-cluster/materialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func materializeCommand() *cli.Command {
Usage: "Materialize embedded assets into the data directory",
Hidden: true,
Flags: []cli.Flag{
getDataDirFlag(runtimeConfig),
getDataDirFlagWithDefault(runtimeConfig),
},
Before: func(c *cli.Context) error {
if os.Getuid() != 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/embedded-cluster/preflights.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func installRunPreflightsCommand() *cli.Command {
Usage: "Disable interactive prompts.",
Value: false,
},
getDataDirFlag(runtimeConfig),
getDataDirFlagWithDefault(runtimeConfig),
getAdminConsolePortFlag(runtimeConfig),
getLocalArtifactMirrorPortFlag(runtimeConfig),
},
Expand Down
10 changes: 5 additions & 5 deletions cmd/embedded-cluster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ func discoverKubeconfigPath(ctx context.Context, runtimeConfig *ecv1beta1.Runtim
// discoverBestProvider discovers the provider from the cluster (if it's up) and will fall back to
// the flag, the filesystem, or the default.
func discoverBestProvider(ctx context.Context, runtimeConfig *ecv1beta1.RuntimeConfigSpec) *defaults.Provider {
// Use the data dir from the data-dir flag if it's set
if runtimeConfig.DataDir != "" {
return defaults.NewProviderFromRuntimeConfig(runtimeConfig)
}

// It's possible that the cluster is not up
provider, err := getProviderFromCluster(ctx)
if err == nil {
return provider
}

// Use the data dir from the data-dir flag if it's set
if runtimeConfig.DataDir != "" {
return defaults.NewProviderFromRuntimeConfig(runtimeConfig)
}

// Otherwise, fall back to the filesystem
provider, err = defaults.NewProviderFromFilesystem()
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/embedded-cluster/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ func restoreCommand() *cli.Command {
Name: "airgap-bundle",
Usage: "Path to the air gap bundle. If set, the restore will complete without internet access.",
},
getDataDirFlag(runtimeConfig),
getDataDirFlagWithDefault(runtimeConfig),
&cli.StringFlag{
Name: "local-artifact-mirror-port",
Usage: "Port on which the Local Artifact Mirror will be served. If left empty, the port will be retrieved from the snapshot.",
Expand Down

0 comments on commit f6e2521

Please sign in to comment.