Skip to content

Commit

Permalink
fix(post-renderer): non-strict labels and annotations validation in w…
Browse files Browse the repository at this point in the history
…erf's post-renderer

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed May 18, 2022
1 parent 1ba1a31 commit 18dd510
Show file tree
Hide file tree
Showing 17 changed files with 748 additions and 101 deletions.
6 changes: 4 additions & 2 deletions cmd/werf/bundle/apply/apply.go
Expand Up @@ -185,8 +185,10 @@ func runApply() error {
}

bundle, err := chart_extender.NewBundle(ctx, bundleTmpDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.BundleOptions{
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
BuildChartDependenciesOpts: command_helpers.BuildChartDependenciesOptions{IgnoreInvalidAnnotationsAndLabels: true},
IgnoreInvalidAnnotationsAndLabels: true,
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
})
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/werf/bundle/export/export.go
Expand Up @@ -296,8 +296,9 @@ func runExport(ctx context.Context) error {
}

wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
IgnoreInvalidAnnotationsAndLabels: true,
})

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/werf/bundle/publish/publish.go
Expand Up @@ -327,8 +327,9 @@ func runPublish(ctx context.Context) error {
}

wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
IgnoreInvalidAnnotationsAndLabels: true,
})

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
Expand Down
7 changes: 5 additions & 2 deletions cmd/werf/bundle/render/render.go
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/werf/werf/pkg/deploy/helm"
"github.com/werf/werf/pkg/deploy/helm/chart_extender"
"github.com/werf/werf/pkg/deploy/helm/chart_extender/helpers"
"github.com/werf/werf/pkg/deploy/helm/command_helpers"
"github.com/werf/werf/pkg/storage"
"github.com/werf/werf/pkg/werf"
"github.com/werf/werf/pkg/werf/global_warnings"
Expand Down Expand Up @@ -186,8 +187,10 @@ func runRender(ctx context.Context) error {
}

bundle, err := chart_extender.NewBundle(ctx, bundleDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.BundleOptions{
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
BuildChartDependenciesOpts: command_helpers.BuildChartDependenciesOptions{IgnoreInvalidAnnotationsAndLabels: false},
IgnoreInvalidAnnotationsAndLabels: false,
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
})
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions cmd/werf/converge/converge.go
Expand Up @@ -376,9 +376,10 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
}

wc := chart_extender.NewWerfChart(ctx, giterminismManager, secretsManager, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{
SecretValueFiles: common.GetSecretValues(&commonCmdData),
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
SecretValueFiles: common.GetSecretValues(&commonCmdData),
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
IgnoreInvalidAnnotationsAndLabels: true,
})

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/werf/dismiss/dismiss.go
Expand Up @@ -203,7 +203,9 @@ func runDismiss(ctx context.Context) error {
return fmt.Errorf("unable to create helm registry client: %w", err)
}

wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{})
wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{
IgnoreInvalidAnnotationsAndLabels: true,
})

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/werf/helm/helm.go
Expand Up @@ -43,11 +43,11 @@ func NewCmd() *cobra.Command {

ctx := common.GetContext()

wc := chart_extender.NewWerfChartStub(ctx)
wc := chart_extender.NewWerfChartStub(ctx, false)

loader.GlobalLoadOptions = &loader.LoadOptions{
ChartExtender: wc,
SubchartExtenderFactoryFunc: func() chart.ChartExtender { return chart_extender.NewWerfChartStub(ctx) },
SubchartExtenderFactoryFunc: func() chart.ChartExtender { return chart_extender.NewWerfChartStub(ctx, false) },
}

os.Setenv("HELM_EXPERIMENTAL_OCI", "1")
Expand Down
11 changes: 8 additions & 3 deletions cmd/werf/render/render.go
Expand Up @@ -58,6 +58,10 @@ func NewCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
ctx := common.GetContext()

global_warnings.SuppressGlobalWarnings = true
if *commonCmdData.LogVerbose || *commonCmdData.LogDebug {
global_warnings.SuppressGlobalWarnings = false
}
defer global_warnings.PrintGlobalWarnings(ctx)

if err := common.ProcessLogOptions(&commonCmdData); err != nil {
Expand Down Expand Up @@ -331,9 +335,10 @@ func runRender(ctx context.Context) error {
}

wc := chart_extender.NewWerfChart(ctx, giterminismManager, secretsManager, chartDir, helm_v3.Settings, helmRegistryClientHandler, chart_extender.WerfChartOptions{
SecretValueFiles: common.GetSecretValues(&commonCmdData),
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
SecretValueFiles: common.GetSecretValues(&commonCmdData),
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
IgnoreInvalidAnnotationsAndLabels: false,
})

if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
Expand Down
9 changes: 5 additions & 4 deletions pkg/deploy/helm/chart_extender/bundle.go
Expand Up @@ -24,9 +24,10 @@ import (
)

type BundleOptions struct {
BuildChartDependenciesOpts command_helpers.BuildChartDependenciesOptions
ExtraAnnotations map[string]string
ExtraLabels map[string]string
BuildChartDependenciesOpts command_helpers.BuildChartDependenciesOptions
ExtraAnnotations map[string]string
ExtraLabels map[string]string
IgnoreInvalidAnnotationsAndLabels bool
}

func NewBundle(ctx context.Context, dir string, helmEnvSettings *cli.EnvSettings, registryClient *registry.Client, opts BundleOptions) (*Bundle, error) {
Expand All @@ -39,7 +40,7 @@ func NewBundle(ctx context.Context, dir string, helmEnvSettings *cli.EnvSettings
ChartExtenderContextData: helpers.NewChartExtenderContextData(ctx),
}

extraAnnotationsAndLabelsPostRenderer := helm.NewExtraAnnotationsAndLabelsPostRenderer(nil, nil)
extraAnnotationsAndLabelsPostRenderer := helm.NewExtraAnnotationsAndLabelsPostRenderer(nil, nil, opts.IgnoreInvalidAnnotationsAndLabels)

if dataMap, err := readBundleJsonMap(filepath.Join(bundle.Dir, "extra_annotations.json")); err != nil {
return nil, err
Expand Down
Expand Up @@ -77,7 +77,7 @@ func GetPreparedChartDependenciesDir(ctx context.Context, metadataFile, metadata
tmpDepsDir := fmt.Sprintf("%s.tmp.%s", depsDir, uuid.NewV4().String())

buildChartDependenciesOpts.LoadOptions = &loader.LoadOptions{
ChartExtender: NewWerfChartStub(ctx),
ChartExtender: NewWerfChartStub(ctx, buildChartDependenciesOpts.IgnoreInvalidAnnotationsAndLabels),
SubchartExtenderFactoryFunc: nil,
}

Expand Down
19 changes: 12 additions & 7 deletions pkg/deploy/helm/chart_extender/werf_chart.go
Expand Up @@ -31,11 +31,12 @@ import (
)

type WerfChartOptions struct {
SecretValueFiles []string
ExtraAnnotations map[string]string
ExtraLabels map[string]string
BuildChartDependenciesOpts command_helpers.BuildChartDependenciesOptions
DisableSecrets bool
SecretValueFiles []string
ExtraAnnotations map[string]string
ExtraLabels map[string]string
BuildChartDependenciesOpts command_helpers.BuildChartDependenciesOptions
DisableSecrets bool
IgnoreInvalidAnnotationsAndLabels 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 {
Expand All @@ -49,7 +50,7 @@ func NewWerfChart(ctx context.Context, giterminismManager giterminism_manager.In
GiterminismManager: giterminismManager,
SecretsManager: secretsManager,

extraAnnotationsAndLabelsPostRenderer: helm.NewExtraAnnotationsAndLabelsPostRenderer(nil, nil),
extraAnnotationsAndLabelsPostRenderer: helm.NewExtraAnnotationsAndLabelsPostRenderer(nil, nil, opts.IgnoreInvalidAnnotationsAndLabels),

ChartExtenderServiceValuesData: helpers.NewChartExtenderServiceValuesData(),
ChartExtenderContextData: helpers.NewChartExtenderContextData(ctx),
Expand Down Expand Up @@ -394,5 +395,9 @@ func (wc *WerfChart) CreateNewBundle(ctx context.Context, destDir, chartVersion
}
}

return NewBundle(ctx, destDir, wc.HelmEnvSettings, wc.RegistryClient, BundleOptions{BuildChartDependenciesOpts: wc.BuildChartDependenciesOpts})
return NewBundle(ctx, destDir, wc.HelmEnvSettings, wc.RegistryClient, BundleOptions{
BuildChartDependenciesOpts: wc.BuildChartDependenciesOpts,
IgnoreInvalidAnnotationsAndLabels: wc.extraAnnotationsAndLabelsPostRenderer.IgnoreInvalidAnnotationsAndLabels,
},
)
}
4 changes: 2 additions & 2 deletions pkg/deploy/helm/chart_extender/werf_chart_stub.go
Expand Up @@ -17,9 +17,9 @@ import (
"github.com/werf/werf/pkg/deploy/secrets_manager"
)

func NewWerfChartStub(ctx context.Context) *WerfChartStub {
func NewWerfChartStub(ctx context.Context, ignoreInvalidAnnotationsAndLabels bool) *WerfChartStub {
return &WerfChartStub{
extraAnnotationsAndLabelsPostRenderer: helm.NewExtraAnnotationsAndLabelsPostRenderer(nil, nil),
extraAnnotationsAndLabelsPostRenderer: helm.NewExtraAnnotationsAndLabelsPostRenderer(nil, nil, ignoreInvalidAnnotationsAndLabels),
ChartExtenderContextData: helpers.NewChartExtenderContextData(ctx),
}
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/deploy/helm/command_helpers/build_chart_dependencies.go
Expand Up @@ -18,10 +18,11 @@ import (
)

type BuildChartDependenciesOptions struct {
Keyring string
SkipUpdate bool
Verify downloader.VerificationStrategy
LoadOptions *loader.LoadOptions
Keyring string
SkipUpdate bool
Verify downloader.VerificationStrategy
LoadOptions *loader.LoadOptions
IgnoreInvalidAnnotationsAndLabels bool
}

func BuildChartDependenciesInDir(ctx context.Context, chartFile, chartLockFile *chart.ChartExtenderBufferedFile, targetDir string, helmEnvSettings *cli.EnvSettings, registryClient *registry.Client, opts BuildChartDependenciesOptions) error {
Expand Down

0 comments on commit 18dd510

Please sign in to comment.