Skip to content

Commit 3cdb493

Browse files
author
Moritz Clasmeier
committed
wip
1 parent 451a419 commit 3cdb493

2 files changed

Lines changed: 70 additions & 85 deletions

File tree

cmd/deploy.go

Lines changed: 70 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,17 @@ type configShortCut struct {
3232
settings *deployer.Config
3333
flagType string
3434
applyFn func(val string, settings *deployer.Config) error
35-
stringFn func(settings *deployer.Config) string
36-
current string
3735
}
3836

3937
func newConfigShortCut(
4038
settings *deployer.Config,
4139
flagType string,
4240
applyFn func(val string, settings *deployer.Config) error,
43-
stringFn func(settings *deployer.Config) string,
4441
) *configShortCut {
4542
return &configShortCut{
4643
flagType: flagType,
4744
settings: settings,
4845
applyFn: applyFn,
49-
stringFn: stringFn,
5046
}
5147
}
5248

@@ -55,19 +51,13 @@ func (y *configShortCut) Set(val string) error {
5551
}
5652

5753
func (y *configShortCut) String() string {
58-
return "" // xxx?
54+
return "" //
5955
}
6056

6157
func (y *configShortCut) Type() string {
6258
return y.flagType
6359
}
6460

65-
func stringFnWithDefault(defVal string, pathElements ...string) func(settings *deployer.Config) string {
66-
return func(settings *deployer.Config) string {
67-
return "(internally set)"
68-
}
69-
}
70-
7161
func newConfigShortCutBool(settings *deployer.Config, path string) *configShortCut {
7262
pathElements := strings.Split(path, ".")
7363
applyFn := func(val string, settings *deployer.Config) error {
@@ -84,7 +74,7 @@ func newConfigShortCutBool(settings *deployer.Config, path string) *configShortC
8474
}
8575
return helpers.MapToStruct(u, settings)
8676
}
87-
return newConfigShortCut(settings, "", applyFn, stringFnWithDefault(""))
77+
return newConfigShortCut(settings, "", applyFn)
8878
}
8979

9080
func addBoolFlag(cmd *cobra.Command, val pflag.Value, name, usage string) {
@@ -129,9 +119,9 @@ Examples:
129119

130120
addBoolFlag(cmd, newConfigShortCutBool(settings, "operator.deployViaOlm"), "olm", "Deploy operator via OLM (requires OLM installed)")
131121
addBoolFlag(cmd, newConfigShortCutBool(settings, "roxie.konfluxImages"), "konflux", "Use Konflux images")
132-
addBoolFlag(cmd, newConfigShortCut(settings, "bool", deployOperatorApplyFn, stringFnWithDefault("false", "operator", "skipDeployment")), "deploy-operator", "Whether to deploy and manage the operator")
122+
addBoolFlag(cmd, newConfigShortCut(settings, "bool", deployOperatorApplyFn), "deploy-operator", "Whether to deploy and manage the operator")
133123
addBoolFlag(cmd, newConfigShortCutBool(settings, "central.portForwarding"), "port-forwarding", "Enable localhost port-forward for Central")
134-
addBoolFlag(cmd, newConfigShortCut(settings, "bool", pauseReconciliationApplyFn, stringFnWithDefault("false", "central", "pauseReconciliation")), "pause-reconciliation", "Pause reconciliation after deployment")
124+
addBoolFlag(cmd, newConfigShortCut(settings, "bool", pauseReconciliationApplyFn), "pause-reconciliation", "Pause reconciliation after deployment")
135125
cmd.Flags().VarP(newConfigShortCut(settings, "file",
136126
func(filename string, settings *deployer.Config) error {
137127
if filename == "-" {
@@ -147,7 +137,6 @@ Examples:
147137
}
148138
return settings.MergeInUnstructured(obj)
149139
},
150-
func(settings *deployer.Config) string { return "" },
151140
), "config", "c", "Path to YAML config file")
152141
cmd.Flags().Var(newConfigShortCut(settings, "exposure",
153142
func(val string, settings *deployer.Config) error {
@@ -158,7 +147,6 @@ Examples:
158147
settings.Central.Exposure = exposure
159148
return nil
160149
},
161-
func(settings *deployer.Config) string { return "" },
162150
), "exposure", "Central exposure backend (loadbalancer, none)")
163151
cmd.Flags().Var(newConfigShortCut(settings, "resource-profile",
164152
func(val string, settings *deployer.Config) error {
@@ -170,95 +158,93 @@ Examples:
170158
settings.SecuredCluster.ResourceProfile = valParsed
171159
return nil
172160
},
173-
func(settings *deployer.Config) string { return "" },
174161
), "resources", fmt.Sprintf("Resource sizing preset (%s)", types.ResourceProfilesJoined()))
175162
cmd.Flags().StringVar(&shell, "shell", "", "Shell to spawn after Central deployment")
176163
cmd.Flags().StringVar(&envrc, "envrc", "", "Write environment to file instead of spawning sub-shell")
177164

178-
cmd.Flags().Var(newConfigShortCut(settings, "set-expression", func(expr string, settings *deployer.Config) error {
179-
key, yamlValue, found := strings.Cut(expr, "=")
180-
if !found {
181-
return fmt.Errorf("invalid set expression '%s': expected format 'key.path=value'", expr)
182-
}
183-
var val interface{}
184-
if err := yaml.Unmarshal([]byte(yamlValue), &val); err != nil {
185-
return fmt.Errorf("failed to unmarshal value '%s' for key '%s': %w", yamlValue, key, err)
186-
}
187-
pathElements := strings.Split(key, ".")
188-
u, err := helpers.StructToMap(settings)
189-
if err != nil {
190-
return err
191-
}
192-
if err := unstructured.SetNestedField(u, val, pathElements...); err != nil {
193-
return err
194-
}
195-
return helpers.MapToStruct(u, settings)
196-
},
197-
func(settings *deployer.Config) string { return "" },
165+
cmd.Flags().Var(newConfigShortCut(settings, "set-expression",
166+
func(expr string, settings *deployer.Config) error {
167+
key, yamlValue, found := strings.Cut(expr, "=")
168+
if !found {
169+
return fmt.Errorf("invalid set expression '%s': expected format 'key.path=value'", expr)
170+
}
171+
var val interface{}
172+
if err := yaml.Unmarshal([]byte(yamlValue), &val); err != nil {
173+
return fmt.Errorf("failed to unmarshal value '%s' for key '%s': %w", yamlValue, key, err)
174+
}
175+
pathElements := strings.Split(key, ".")
176+
u, err := helpers.StructToMap(settings)
177+
if err != nil {
178+
return err
179+
}
180+
if err := unstructured.SetNestedField(u, val, pathElements...); err != nil {
181+
return err
182+
}
183+
return helpers.MapToStruct(u, settings)
184+
},
198185
), "set", "Set expressions, e.g. securedCluster.spec.clusterName=sensor")
199186

200-
addBoolFlag(cmd, newConfigShortCut(settings, "bool", func(_ string, settings *deployer.Config) error {
201-
settings.Central.Namespace = sharedNamespace
202-
settings.SecuredCluster.Namespace = sharedNamespace
203-
return nil
204-
},
205-
func(settings *deployer.Config) string { return "" },
187+
addBoolFlag(cmd, newConfigShortCut(settings, "bool",
188+
func(_ string, settings *deployer.Config) error {
189+
settings.Central.Namespace = sharedNamespace
190+
settings.SecuredCluster.Namespace = sharedNamespace
191+
return nil
192+
},
206193
), "single-namespace", "Deploy all components in a single namespace ('stackrox')")
207-
cmd.Flags().VarP(newConfigShortCut(settings, "version", func(mainImageTag string, settings *deployer.Config) error {
208-
settings.Roxie.Version = mainImageTag
209-
return nil
210-
},
211-
func(settings *deployer.Config) string { return "" },
194+
cmd.Flags().VarP(newConfigShortCut(settings, "version",
195+
func(mainImageTag string, settings *deployer.Config) error {
196+
settings.Roxie.Version = mainImageTag
197+
return nil
198+
},
212199
), "tag", "t", "Main image tag to use for deployment (takes precedence over MAIN_IMAGE_TAG environment variable)")
213-
cmd.Flags().Var(newConfigShortCut(settings, "feature-flags", func(featureFlagExpr string, settings *deployer.Config) error {
214-
featureFlags, err := deployer.ParseFeatureFlags([]string{featureFlagExpr})
215-
if err != nil {
216-
return fmt.Errorf("parsing feature flags: %w", err)
217-
}
218-
for k, v := range featureFlags {
219-
settings.Roxie.FeatureFlags[k] = v
220-
}
221-
return nil
222-
},
223-
func(settings *deployer.Config) string { return "" },
200+
cmd.Flags().Var(newConfigShortCut(settings, "feature-flags",
201+
func(featureFlagExpr string, settings *deployer.Config) error {
202+
featureFlags, err := deployer.ParseFeatureFlags([]string{featureFlagExpr})
203+
if err != nil {
204+
return fmt.Errorf("parsing feature flags: %w", err)
205+
}
206+
for k, v := range featureFlags {
207+
settings.Roxie.FeatureFlags[k] = v
208+
}
209+
return nil
210+
},
224211
), "features", "Feature flag settings (e.g., +ROX_FOO,-ROX_BAR,ROX_BAZ=true)")
225-
cmd.Flags().Var(newConfigShortCut(settings, "duration", func(val string, settings *deployer.Config) error {
226-
duration, err := time.ParseDuration(val)
227-
if err != nil {
228-
return err
229-
}
230-
settings.Central.DeployTimeout = duration
231-
return nil
212+
cmd.Flags().Var(newConfigShortCut(settings, "duration",
213+
func(val string, settings *deployer.Config) error {
214+
duration, err := time.ParseDuration(val)
215+
if err != nil {
216+
return err
217+
}
218+
settings.Central.DeployTimeout = duration
219+
return nil
232220

233-
},
234-
func(settings *deployer.Config) string { return "" },
221+
},
235222
), "central-wait", "maximum wait time for central to become ready (e.g., 5m, 10m)")
236-
cmd.Flags().Var(newConfigShortCut(settings, "duration", func(val string, settings *deployer.Config) error {
237-
duration, err := time.ParseDuration(val)
238-
if err != nil {
239-
return err
240-
}
241-
settings.SecuredCluster.DeployTimeout = duration
242-
return nil
223+
cmd.Flags().Var(newConfigShortCut(settings, "duration",
224+
func(val string, settings *deployer.Config) error {
225+
duration, err := time.ParseDuration(val)
226+
if err != nil {
227+
return err
228+
}
229+
settings.SecuredCluster.DeployTimeout = duration
230+
return nil
243231

244-
},
245-
func(settings *deployer.Config) string { return "" },
232+
},
246233
), "secured-cluster-wait", "maximum wait time for secured cluster to become ready (e.g., 5m, 10m)")
247234

248-
addBoolFlag(cmd, newConfigShortCut(settings, "bool", func(_ string, settings *deployer.Config) error {
249-
settings.Central.EarlyReadiness = true
250-
settings.SecuredCluster.EarlyReadiness = true
251-
return nil
252-
},
253-
func(settings *deployer.Config) string { return "" },
235+
addBoolFlag(cmd, newConfigShortCut(settings, "bool",
236+
func(_ string, settings *deployer.Config) error {
237+
settings.Central.EarlyReadiness = true
238+
settings.SecuredCluster.EarlyReadiness = true
239+
return nil
240+
},
254241
), "early-readiness", "Only wait for essential workloads (central/sensor) to be ready")
255242

256243
cmd.Flags().Var(newConfigShortCut(settings, "early-readiness",
257244
func(val string, settings *deployer.Config) error {
258245

259246
return nil
260247
},
261-
func(settings *deployer.Config) string { return "" },
262248
), "", "")
263249

264250
// Make --override an alias for --config, for backwards compatibility.

cmd/teardown.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func newTeardownCmd(settings *deployer.Config) *cobra.Command {
2929
settings.SecuredCluster.Namespace = sharedNamespace
3030
return nil
3131
},
32-
func(settings *deployer.Config) string { return "" },
3332
), "single-namespace", "Deploy all components in a single namespace ('stackrox')")
3433

3534
return cmd

0 commit comments

Comments
 (0)