Skip to content

Commit 49425ee

Browse files
committed
feat: added options to disable usage of default values (and secret values)
`--disable-default-values` and `--disable-default-secret-values` options supported for: * werf bundle publish * werf converge * werf render Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
1 parent 68c096f commit 49425ee

File tree

7 files changed

+66
-12
lines changed

7 files changed

+66
-12
lines changed

cmd/werf/bundle/export/export.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
122122
common.SetupSetFile(&commonCmdData, cmd)
123123
common.SetupValues(&commonCmdData, cmd)
124124

125+
commonCmdData.SetupDisableDefaultValues(cmd)
126+
125127
common.SetupReportPath(&commonCmdData, cmd)
126128
common.SetupReportFormat(&commonCmdData, cmd)
127129

@@ -322,6 +324,8 @@ func runExport(ctx context.Context, imagesToProcess build.ImagesToProcess) error
322324
ExtraAnnotations: userExtraAnnotations,
323325
ExtraLabels: userExtraLabels,
324326
IgnoreInvalidAnnotationsAndLabels: true,
327+
DisableDefaultValues: *commonCmdData.DisableDefaultValues,
328+
DisableDefaultSecretValues: true,
325329
})
326330

327331
if err := wc.SetEnv(*commonCmdData.Environment); err != nil {

cmd/werf/bundle/publish/publish.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
111111
common.SetupSetFile(&commonCmdData, cmd)
112112
common.SetupValues(&commonCmdData, cmd)
113113

114+
commonCmdData.SetupDisableDefaultValues(cmd)
115+
114116
common.SetupReportPath(&commonCmdData, cmd)
115117
common.SetupReportFormat(&commonCmdData, cmd)
116118

@@ -329,6 +331,8 @@ func runPublish(ctx context.Context, imagesToProcess build.ImagesToProcess) erro
329331
ExtraAnnotations: userExtraAnnotations,
330332
ExtraLabels: userExtraLabels,
331333
IgnoreInvalidAnnotationsAndLabels: true,
334+
DisableDefaultValues: *commonCmdData.DisableDefaultValues,
335+
DisableDefaultSecretValues: true,
332336
})
333337

334338
if err := wc.SetEnv(*commonCmdData.Environment); err != nil {

cmd/werf/common/cmd_data.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ type CmdData struct {
3030
HooksStatusProgressPeriodSeconds *int64
3131
ReleasesHistoryMax *int
3232

33-
SetDockerConfigJsonValue *bool
34-
Set *[]string
35-
SetString *[]string
36-
Values *[]string
37-
SetFile *[]string
38-
SecretValues *[]string
39-
IgnoreSecretKey *bool
33+
SetDockerConfigJsonValue *bool
34+
Set *[]string
35+
SetString *[]string
36+
Values *[]string
37+
SetFile *[]string
38+
SecretValues *[]string
39+
IgnoreSecretKey *bool
40+
DisableDefaultValues *bool
41+
DisableDefaultSecretValues *bool
4042

4143
WithoutImages *bool
4244
Repo *RepoData
@@ -104,3 +106,13 @@ func (cmdData *CmdData) SetupWithoutImages(cmd *cobra.Command) {
104106
cmdData.WithoutImages = new(bool)
105107
cmd.Flags().BoolVarP(cmdData.WithoutImages, "without-images", "", util.GetBoolEnvironmentDefaultFalse("WERF_WITHOUT_IMAGES"), "Disable building of images defined in the werf.yaml (if any) and usage of such images in the .helm/templates ($WERF_WITHOUT_IMAGES or false by default — e.g. enable all images defined in the werf.yaml by default)")
106108
}
109+
110+
func (cmdData *CmdData) SetupDisableDefaultValues(cmd *cobra.Command) {
111+
cmdData.DisableDefaultValues = new(bool)
112+
cmd.Flags().BoolVarP(cmdData.DisableDefaultValues, "disable-default-values", "", false, `Do not use values from the default .helm/values.yaml file`)
113+
}
114+
115+
func (cmdData *CmdData) SetupDisableDefaultSecretValues(cmd *cobra.Command) {
116+
cmdData.DisableDefaultSecretValues = new(bool)
117+
cmd.Flags().BoolVarP(cmdData.DisableDefaultSecretValues, "disable-default-secret-values", "", false, `Do not use secret values from the default .helm/secret-values.yaml file`)
118+
}

cmd/werf/converge/converge.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ werf converge --repo registry.mydomain.com/web --env production`,
155155
common.SetupSecretValues(&commonCmdData, cmd)
156156
common.SetupIgnoreSecretKey(&commonCmdData, cmd)
157157

158+
commonCmdData.SetupDisableDefaultValues(cmd)
159+
commonCmdData.SetupDisableDefaultSecretValues(cmd)
160+
158161
common.SetupReportPath(&commonCmdData, cmd)
159162
common.SetupReportFormat(&commonCmdData, cmd)
160163

@@ -405,6 +408,8 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
405408
ExtraAnnotations: userExtraAnnotations,
406409
ExtraLabels: userExtraLabels,
407410
IgnoreInvalidAnnotationsAndLabels: true,
411+
DisableDefaultValues: *commonCmdData.DisableDefaultValues,
412+
DisableDefaultSecretValues: *commonCmdData.DisableDefaultSecretValues,
408413
})
409414

410415
if err := wc.SetEnv(*commonCmdData.Environment); err != nil {

cmd/werf/render/render.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func NewCmd(ctx context.Context) *cobra.Command {
132132
common.SetupSecretValues(&commonCmdData, cmd)
133133
common.SetupIgnoreSecretKey(&commonCmdData, cmd)
134134

135+
commonCmdData.SetupDisableDefaultValues(cmd)
136+
commonCmdData.SetupDisableDefaultSecretValues(cmd)
137+
135138
common.SetupReportPath(&commonCmdData, cmd)
136139
common.SetupReportFormat(&commonCmdData, cmd)
137140

@@ -374,6 +377,8 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error
374377
ExtraAnnotations: userExtraAnnotations,
375378
ExtraLabels: userExtraLabels,
376379
IgnoreInvalidAnnotationsAndLabels: false,
380+
DisableDefaultValues: *commonCmdData.DisableDefaultValues,
381+
DisableDefaultSecretValues: *commonCmdData.DisableDefaultSecretValues,
377382
})
378383

379384
if err := wc.SetEnv(*commonCmdData.Environment); err != nil {

pkg/deploy/helm/chart_extender/bundle.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type BundleOptions struct {
3232
ExtraAnnotations map[string]string
3333
ExtraLabels map[string]string
3434
IgnoreInvalidAnnotationsAndLabels bool
35+
DisableDefaultValues bool
3536
}
3637

3738
func NewBundle(ctx context.Context, dir string, helmEnvSettings *cli.EnvSettings, registryClient *registry.Client, secretsManager *secrets_manager.SecretsManager, opts BundleOptions) (*Bundle, error) {
@@ -44,6 +45,7 @@ func NewBundle(ctx context.Context, dir string, helmEnvSettings *cli.EnvSettings
4445
ChartExtenderServiceValuesData: helpers.NewChartExtenderServiceValuesData(),
4546
ChartExtenderContextData: helpers.NewChartExtenderContextData(ctx),
4647
secretsManager: secretsManager,
48+
DisableDefaultValues: opts.DisableDefaultValues,
4749
}
4850

4951
extraAnnotationsAndLabelsPostRenderer := helm.NewExtraAnnotationsAndLabelsPostRenderer(nil, nil, opts.IgnoreInvalidAnnotationsAndLabels)
@@ -78,6 +80,7 @@ type Bundle struct {
7880
HelmEnvSettings *cli.EnvSettings
7981
RegistryClient *registry.Client
8082
BuildChartDependenciesOpts command_helpers.BuildChartDependenciesOptions
83+
DisableDefaultValues bool
8184

8285
extraAnnotationsAndLabelsPostRenderer *helm.ExtraAnnotationsAndLabelsPostRenderer
8386
secretsManager *secrets_manager.SecretsManager
@@ -123,6 +126,12 @@ func (bundle *Bundle) ChartLoaded(files []*chart.ChartExtenderBufferedFile) erro
123126
}
124127
}
125128

129+
bundle.HelmChart.Values = nil
130+
if bundle.DisableDefaultValues {
131+
logboek.Context(bundle.ChartExtenderContext).Info().LogF("Disable default werf chart values\n")
132+
bundle.HelmChart.Values = nil
133+
}
134+
126135
return nil
127136
}
128137

pkg/deploy/helm/chart_extender/werf_chart.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ type WerfChartOptions struct {
3434
ExtraAnnotations map[string]string
3535
ExtraLabels map[string]string
3636
BuildChartDependenciesOpts command_helpers.BuildChartDependenciesOptions
37-
DisableSecrets bool
3837
IgnoreInvalidAnnotationsAndLabels bool
38+
DisableDefaultValues bool
39+
DisableDefaultSecretValues bool
3940
}
4041

4142
func NewWerfChart(ctx context.Context, giterminismManager giterminism_manager.Interface, secretsManager *secrets_manager.SecretsManager, chartDir string, helmEnvSettings *cli.EnvSettings, registryClient *registry.Client, opts WerfChartOptions) *WerfChart {
@@ -44,7 +45,6 @@ func NewWerfChart(ctx context.Context, giterminismManager giterminism_manager.In
4445
SecretValueFiles: opts.SecretValueFiles,
4546
HelmEnvSettings: helmEnvSettings,
4647
RegistryClient: registryClient,
47-
DisableSecrets: opts.DisableSecrets,
4848

4949
GiterminismManager: giterminismManager,
5050
SecretsManager: secretsManager,
@@ -53,6 +53,9 @@ func NewWerfChart(ctx context.Context, giterminismManager giterminism_manager.In
5353

5454
ChartExtenderServiceValuesData: helpers.NewChartExtenderServiceValuesData(),
5555
ChartExtenderContextData: helpers.NewChartExtenderContextData(ctx),
56+
57+
DisableDefaultValues: opts.DisableDefaultValues,
58+
DisableDefaultSecretValues: opts.DisableDefaultSecretValues,
5659
}
5760

5861
wc.extraAnnotationsAndLabelsPostRenderer.Add(opts.ExtraAnnotations, opts.ExtraLabels)
@@ -74,7 +77,8 @@ type WerfChart struct {
7477
HelmEnvSettings *cli.EnvSettings
7578
RegistryClient *registry.Client
7679
BuildChartDependenciesOpts command_helpers.BuildChartDependenciesOptions
77-
DisableSecrets bool
80+
DisableDefaultValues bool
81+
DisableDefaultSecretValues bool
7882

7983
GiterminismManager giterminism_manager.Interface
8084
SecretsManager *secrets_manager.SecretsManager
@@ -97,9 +101,14 @@ func (wc *WerfChart) ChartCreated(c *chart.Chart) error {
97101
// ChartLoaded method for the chart.Extender interface
98102
func (wc *WerfChart) ChartLoaded(files []*chart.ChartExtenderBufferedFile) error {
99103
if wc.SecretsManager != nil {
104+
if wc.DisableDefaultSecretValues {
105+
logboek.Context(wc.ChartExtenderContext).Info().LogF("Disable default werf chart secret values\n")
106+
}
107+
100108
if err := wc.SecretsRuntimeData.DecodeAndLoadSecrets(wc.ChartExtenderContext, files, wc.ChartDir, wc.GiterminismManager.ProjectDir(), wc.SecretsManager, secrets.DecodeAndLoadSecretsOptions{
101-
GiterminismManager: wc.GiterminismManager,
102-
CustomSecretValueFiles: wc.SecretValueFiles,
109+
GiterminismManager: wc.GiterminismManager,
110+
CustomSecretValueFiles: wc.SecretValueFiles,
111+
WithoutDefaultSecretValues: wc.DisableDefaultSecretValues,
103112
}); err != nil {
104113
return fmt.Errorf("error decoding secrets: %w", err)
105114
}
@@ -117,6 +126,11 @@ func (wc *WerfChart) ChartLoaded(files []*chart.ChartExtenderBufferedFile) error
117126
Data: []byte(helpers.ChartTemplateHelpers),
118127
})
119128

129+
if wc.DisableDefaultValues {
130+
logboek.Context(wc.ChartExtenderContext).Info().LogF("Disable default werf chart values\n")
131+
wc.HelmChart.Values = nil
132+
}
133+
120134
return nil
121135
}
122136

@@ -390,6 +404,7 @@ func (wc *WerfChart) CreateNewBundle(ctx context.Context, destDir, chartVersion
390404
return NewBundle(ctx, destDir, wc.HelmEnvSettings, wc.RegistryClient, wc.SecretsManager, BundleOptions{
391405
BuildChartDependenciesOpts: wc.BuildChartDependenciesOpts,
392406
IgnoreInvalidAnnotationsAndLabels: wc.extraAnnotationsAndLabelsPostRenderer.IgnoreInvalidAnnotationsAndLabels,
407+
DisableDefaultValues: wc.DisableDefaultValues,
393408
})
394409
}
395410

0 commit comments

Comments
 (0)