Skip to content
Permalink
Browse files
feat: added options to disable usage of default values (and secret va…
…lues)

`--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>
  • Loading branch information
distorhead committed Oct 17, 2022
1 parent 68c096f commit 49425ee48e3dcacecdea61d6582a7c246809ba8e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
@@ -122,6 +122,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
common.SetupSetFile(&commonCmdData, cmd)
common.SetupValues(&commonCmdData, cmd)

commonCmdData.SetupDisableDefaultValues(cmd)

common.SetupReportPath(&commonCmdData, cmd)
common.SetupReportFormat(&commonCmdData, cmd)

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

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
@@ -111,6 +111,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
common.SetupSetFile(&commonCmdData, cmd)
common.SetupValues(&commonCmdData, cmd)

commonCmdData.SetupDisableDefaultValues(cmd)

common.SetupReportPath(&commonCmdData, cmd)
common.SetupReportFormat(&commonCmdData, cmd)

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

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
@@ -30,13 +30,15 @@ type CmdData struct {
HooksStatusProgressPeriodSeconds *int64
ReleasesHistoryMax *int

SetDockerConfigJsonValue *bool
Set *[]string
SetString *[]string
Values *[]string
SetFile *[]string
SecretValues *[]string
IgnoreSecretKey *bool
SetDockerConfigJsonValue *bool
Set *[]string
SetString *[]string
Values *[]string
SetFile *[]string
SecretValues *[]string
IgnoreSecretKey *bool
DisableDefaultValues *bool
DisableDefaultSecretValues *bool

WithoutImages *bool
Repo *RepoData
@@ -104,3 +106,13 @@ func (cmdData *CmdData) SetupWithoutImages(cmd *cobra.Command) {
cmdData.WithoutImages = new(bool)
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)")
}

func (cmdData *CmdData) SetupDisableDefaultValues(cmd *cobra.Command) {
cmdData.DisableDefaultValues = new(bool)
cmd.Flags().BoolVarP(cmdData.DisableDefaultValues, "disable-default-values", "", false, `Do not use values from the default .helm/values.yaml file`)
}

func (cmdData *CmdData) SetupDisableDefaultSecretValues(cmd *cobra.Command) {
cmdData.DisableDefaultSecretValues = new(bool)
cmd.Flags().BoolVarP(cmdData.DisableDefaultSecretValues, "disable-default-secret-values", "", false, `Do not use secret values from the default .helm/secret-values.yaml file`)
}
@@ -155,6 +155,9 @@ werf converge --repo registry.mydomain.com/web --env production`,
common.SetupSecretValues(&commonCmdData, cmd)
common.SetupIgnoreSecretKey(&commonCmdData, cmd)

commonCmdData.SetupDisableDefaultValues(cmd)
commonCmdData.SetupDisableDefaultSecretValues(cmd)

common.SetupReportPath(&commonCmdData, cmd)
common.SetupReportFormat(&commonCmdData, cmd)

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

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
@@ -132,6 +132,9 @@ func NewCmd(ctx context.Context) *cobra.Command {
common.SetupSecretValues(&commonCmdData, cmd)
common.SetupIgnoreSecretKey(&commonCmdData, cmd)

commonCmdData.SetupDisableDefaultValues(cmd)
commonCmdData.SetupDisableDefaultSecretValues(cmd)

common.SetupReportPath(&commonCmdData, cmd)
common.SetupReportFormat(&commonCmdData, cmd)

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

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
@@ -32,6 +32,7 @@ type BundleOptions struct {
ExtraAnnotations map[string]string
ExtraLabels map[string]string
IgnoreInvalidAnnotationsAndLabels bool
DisableDefaultValues bool
}

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
ChartExtenderServiceValuesData: helpers.NewChartExtenderServiceValuesData(),
ChartExtenderContextData: helpers.NewChartExtenderContextData(ctx),
secretsManager: secretsManager,
DisableDefaultValues: opts.DisableDefaultValues,
}

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

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

bundle.HelmChart.Values = nil
if bundle.DisableDefaultValues {
logboek.Context(bundle.ChartExtenderContext).Info().LogF("Disable default werf chart values\n")
bundle.HelmChart.Values = nil
}

return nil
}

@@ -34,8 +34,9 @@ type WerfChartOptions struct {
ExtraAnnotations map[string]string
ExtraLabels map[string]string
BuildChartDependenciesOpts command_helpers.BuildChartDependenciesOptions
DisableSecrets bool
IgnoreInvalidAnnotationsAndLabels bool
DisableDefaultValues bool
DisableDefaultSecretValues bool
}

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
SecretValueFiles: opts.SecretValueFiles,
HelmEnvSettings: helmEnvSettings,
RegistryClient: registryClient,
DisableSecrets: opts.DisableSecrets,

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

ChartExtenderServiceValuesData: helpers.NewChartExtenderServiceValuesData(),
ChartExtenderContextData: helpers.NewChartExtenderContextData(ctx),

DisableDefaultValues: opts.DisableDefaultValues,
DisableDefaultSecretValues: opts.DisableDefaultSecretValues,
}

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

GiterminismManager giterminism_manager.Interface
SecretsManager *secrets_manager.SecretsManager
@@ -97,9 +101,14 @@ func (wc *WerfChart) ChartCreated(c *chart.Chart) error {
// ChartLoaded method for the chart.Extender interface
func (wc *WerfChart) ChartLoaded(files []*chart.ChartExtenderBufferedFile) error {
if wc.SecretsManager != nil {
if wc.DisableDefaultSecretValues {
logboek.Context(wc.ChartExtenderContext).Info().LogF("Disable default werf chart secret values\n")
}

if err := wc.SecretsRuntimeData.DecodeAndLoadSecrets(wc.ChartExtenderContext, files, wc.ChartDir, wc.GiterminismManager.ProjectDir(), wc.SecretsManager, secrets.DecodeAndLoadSecretsOptions{
GiterminismManager: wc.GiterminismManager,
CustomSecretValueFiles: wc.SecretValueFiles,
GiterminismManager: wc.GiterminismManager,
CustomSecretValueFiles: wc.SecretValueFiles,
WithoutDefaultSecretValues: wc.DisableDefaultSecretValues,
}); err != nil {
return fmt.Errorf("error decoding secrets: %w", err)
}
@@ -117,6 +126,11 @@ func (wc *WerfChart) ChartLoaded(files []*chart.ChartExtenderBufferedFile) error
Data: []byte(helpers.ChartTemplateHelpers),
})

if wc.DisableDefaultValues {
logboek.Context(wc.ChartExtenderContext).Info().LogF("Disable default werf chart values\n")
wc.HelmChart.Values = nil
}

return nil
}

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

0 comments on commit 49425ee

Please sign in to comment.