Skip to content

Commit 6d647b0

Browse files
authored
feat: use ENABLE_V3 env var instead of flag (#2401)
* feat: use ENABLE_V3 env var instead of flag * f * f
1 parent 9a0ed6f commit 6d647b0

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

cmd/installer/cli/flags.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func init() {
6565
cobra.AddTemplateFuncs(template.FuncMap{
6666
// usesTargetFlagMenu returns true if the target flag is present and the ENABLE_V3 environment variable is set.
6767
"usesTargetFlagMenu": func(flagSet *pflag.FlagSet) bool {
68-
if os.Getenv("ENABLE_V3") == "1" {
68+
if isV3Enabled() {
6969
return flagSet.Lookup("target") != nil
7070
}
7171
return false
@@ -85,6 +85,10 @@ func init() {
8585
})
8686
}
8787

88+
func isV3Enabled() bool {
89+
return os.Getenv("ENABLE_V3") == "1"
90+
}
91+
8892
func mustSetFlagTargetLinux(flags *pflag.FlagSet, name string) {
8993
mustSetFlagTarget(flags, name, flagAnnotationTargetValueLinux)
9094
}
@@ -100,6 +104,13 @@ func mustSetFlagTarget(flags *pflag.FlagSet, name string, target string) {
100104
}
101105
}
102106

107+
func mustMarkFlagRequired(flags *pflag.FlagSet, name string) {
108+
err := cobra.MarkFlagRequired(flags, name)
109+
if err != nil {
110+
panic(err)
111+
}
112+
}
113+
103114
func mustMarkFlagHidden(flags *pflag.FlagSet, name string) {
104115
err := flags.MarkHidden(name)
105116
if err != nil {

cmd/installer/cli/install.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func InstallCmd(ctx context.Context, appSlug, appTitle string) *cobra.Command {
109109
ki := kubernetesinstallation.New(nil)
110110

111111
short := fmt.Sprintf("Install %s", appTitle)
112-
if os.Getenv("ENABLE_V3") == "1" {
112+
if isV3Enabled() {
113113
short = fmt.Sprintf("Install %s onto Linux or Kubernetes", appTitle)
114114
}
115115

@@ -169,7 +169,7 @@ func InstallCmd(ctx context.Context, appSlug, appTitle string) *cobra.Command {
169169
if err := addInstallAdminConsoleFlags(cmd, &flags); err != nil {
170170
panic(err)
171171
}
172-
if err := addManagerExperienceFlags(cmd, &flags); err != nil {
172+
if err := addManagementConsoleFlags(cmd, &flags); err != nil {
173173
panic(err)
174174
}
175175

@@ -197,15 +197,15 @@ const (
197197
)
198198

199199
func installCmdExample(appSlug string) string {
200-
if os.Getenv("ENABLE_V3") != "1" {
200+
if !isV3Enabled() {
201201
return ""
202202
}
203203

204204
return fmt.Sprintf(installCmdExampleText, appSlug, appSlug)
205205
}
206206

207207
func mustAddInstallFlags(cmd *cobra.Command, flags *InstallCmdFlags) {
208-
enableV3 := os.Getenv("ENABLE_V3") == "1"
208+
enableV3 := isV3Enabled()
209209

210210
normalizeFuncs := []func(f *pflag.FlagSet, name string) pflag.NormalizedName{}
211211

@@ -215,7 +215,7 @@ func mustAddInstallFlags(cmd *cobra.Command, flags *InstallCmdFlags) {
215215
normalizeFuncs = append(normalizeFuncs, fn)
216216
}
217217

218-
linuxFlagSet := newLinuxInstallFlags(flags)
218+
linuxFlagSet := newLinuxInstallFlags(flags, enableV3)
219219
cmd.Flags().AddFlagSet(linuxFlagSet)
220220
if fn := linuxFlagSet.GetNormalizeFunc(); fn != nil {
221221
normalizeFuncs = append(normalizeFuncs, fn)
@@ -241,8 +241,10 @@ func mustAddInstallFlags(cmd *cobra.Command, flags *InstallCmdFlags) {
241241
func newCommonInstallFlags(flags *InstallCmdFlags, enableV3 bool) *pflag.FlagSet {
242242
flagSet := pflag.NewFlagSet("common", pflag.ContinueOnError)
243243

244-
flagSet.StringVar(&flags.target, "target", "linux", "The target platform to install to. Valid options are 'linux' or 'kubernetes'.")
245-
if !enableV3 {
244+
flagSet.StringVar(&flags.target, "target", "", "The target platform to install to. Valid options are 'linux' or 'kubernetes'.")
245+
if enableV3 {
246+
mustMarkFlagRequired(flagSet, "target")
247+
} else {
246248
mustMarkFlagHidden(flagSet, "target")
247249
}
248250

@@ -259,12 +261,12 @@ func newCommonInstallFlags(flags *InstallCmdFlags, enableV3 bool) *pflag.FlagSet
259261
return flagSet
260262
}
261263

262-
func newLinuxInstallFlags(flags *InstallCmdFlags) *pflag.FlagSet {
264+
func newLinuxInstallFlags(flags *InstallCmdFlags, enableV3 bool) *pflag.FlagSet {
263265
flagSet := pflag.NewFlagSet("linux", pflag.ContinueOnError)
264266

265267
// Use the app slug as default data directory only when ENABLE_V3 is set
266268
defaultDataDir := ecv1beta1.DefaultDataDir
267-
if os.Getenv("ENABLE_V3") == "1" {
269+
if enableV3 {
268270
defaultDataDir = filepath.Join("/var/lib", runtimeconfig.AppSlug())
269271
}
270272

@@ -335,30 +337,21 @@ func addInstallAdminConsoleFlags(cmd *cobra.Command, flags *InstallCmdFlags) err
335337
cmd.Flags().StringVar(&flags.adminConsolePassword, "admin-console-password", "", "Password for the Admin Console")
336338
cmd.Flags().IntVar(&flags.adminConsolePort, "admin-console-port", ecv1beta1.DefaultAdminConsolePort, "Port on which the Admin Console will be served")
337339
cmd.Flags().StringVarP(&flags.licenseFile, "license", "l", "", "Path to the license file")
338-
if err := cmd.MarkFlagRequired("license"); err != nil {
339-
panic(err)
340-
}
340+
mustMarkFlagRequired(cmd.Flags(), "license")
341341
cmd.Flags().StringVar(&flags.configValues, "config-values", "", "Path to the config values to use when installing")
342342

343343
return nil
344344
}
345345

346-
func addManagerExperienceFlags(cmd *cobra.Command, flags *InstallCmdFlags) error {
347-
// If the ENABLE_V3 environment variable is set, default to the new manager experience and do
348-
// not hide the new flags.
349-
enableV3 := os.Getenv("ENABLE_V3") == "1"
350-
351-
cmd.Flags().BoolVar(&flags.enableManagerExperience, "manager-experience", enableV3, "Run the browser-based installation experience.")
352-
if err := cmd.Flags().MarkHidden("manager-experience"); err != nil {
353-
return err
354-
}
355-
346+
func addManagementConsoleFlags(cmd *cobra.Command, flags *InstallCmdFlags) error {
356347
cmd.Flags().IntVar(&flags.managerPort, "manager-port", ecv1beta1.DefaultManagerPort, "Port on which the Manager will be served")
357348
cmd.Flags().StringVar(&flags.tlsCertFile, "tls-cert", "", "Path to the TLS certificate file")
358349
cmd.Flags().StringVar(&flags.tlsKeyFile, "tls-key", "", "Path to the TLS key file")
359350
cmd.Flags().StringVar(&flags.hostname, "hostname", "", "Hostname to use for TLS configuration")
360351

361-
if !enableV3 {
352+
// If the ENABLE_V3 environment variable is set, default to the new manager experience and do
353+
// not hide the new flags.
354+
if !isV3Enabled() {
362355
if err := cmd.Flags().MarkHidden("manager-port"); err != nil {
363356
return err
364357
}
@@ -377,8 +370,12 @@ func addManagerExperienceFlags(cmd *cobra.Command, flags *InstallCmdFlags) error
377370
}
378371

379372
func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags, rc runtimeconfig.RuntimeConfig, ki kubernetesinstallation.Installation) error {
373+
if !isV3Enabled() {
374+
flags.target = "linux"
375+
}
376+
380377
if !slices.Contains([]string{"linux", "kubernetes"}, flags.target) {
381-
return fmt.Errorf(`invalid target (must be one of: "linux", "kubernetes")`)
378+
return fmt.Errorf(`invalid --target (must be one of: "linux", "kubernetes")`)
382379
}
383380

384381
if err := preRunInstallCommon(cmd, flags, rc, ki); err != nil {
@@ -396,6 +393,8 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags, rc runtimeconfig.
396393
}
397394

398395
func preRunInstallCommon(cmd *cobra.Command, flags *InstallCmdFlags, rc runtimeconfig.RuntimeConfig, ki kubernetesinstallation.Installation) error {
396+
flags.enableManagerExperience = isV3Enabled()
397+
399398
// license file can be empty for restore
400399
if flags.licenseFile != "" {
401400
b, err := os.ReadFile(flags.licenseFile)

cmd/installer/cli/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func UpdateCmd(ctx context.Context, appSlug, appTitle string) *cobra.Command {
6363
}
6464

6565
cmd.Flags().StringVar(&airgapBundle, "airgap-bundle", "", "Path to the air gap bundle. If set, the installation will complete without internet access.")
66-
cmd.MarkFlagRequired("airgap-bundle")
66+
mustMarkFlagRequired(cmd.Flags(), "airgap-bundle")
6767

6868
return cmd
6969
}

e2e/scripts/install-and-configure-squid.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ create_squid_ssl() {
9292

9393

9494
main() {
95+
apt-get update -y
9596
apt install -y squid-openssl
9697
/usr/lib/squid/security_file_certgen -c -s /opt/ssl.db -M 4MB
9798
mkdir -p /etc/squid/ssl_cert

0 commit comments

Comments
 (0)