diff --git a/cmd/werf/helm/lint.go b/cmd/werf/helm/lint.go index 6f3c828e0d..ca22191abb 100644 --- a/cmd/werf/helm/lint.go +++ b/cmd/werf/helm/lint.go @@ -5,23 +5,32 @@ import ( "os" "github.com/spf13/cobra" - "helm.sh/helm/v3/cmd/helm" + helm_v3 "helm.sh/helm/v3/cmd/helm" "helm.sh/helm/v3/pkg/action" "github.com/werf/werf/cmd/werf/common" "github.com/werf/werf/pkg/deploy/helm/chart_extender" + "github.com/werf/werf/pkg/deploy/helm/chart_extender/helpers" ) var lintCmdData common.CmdData func NewLintCmd(actionConfig *action.Configuration, wc *chart_extender.WerfChartStub) *cobra.Command { cmd := helm_v3.NewLintCmd(os.Stdout) + SetupRenderRelatedWerfChartParams(cmd, &lintCmdData) + common.SetupEnvironment(&lintCmdData, cmd) oldRunE := cmd.RunE cmd.RunE = func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() + // NOTICE: This is temporary approach to use `werf helm lint` in pipelines correctly — respect --env / WERF_ENV param, + // NOTICE: which is typically set by the `werf ci-env` command. + if *lintCmdData.Environment != "" { + wc.SetStubServiceValuesOverrides(helpers.GetEnvServiceValues(*lintCmdData.Environment)) + } + if err := InitRenderRelatedWerfChartParams(ctx, &lintCmdData, wc); err != nil { return fmt.Errorf("unable to init werf chart: %w", err) } diff --git a/cmd/werf/render/render.go b/cmd/werf/render/render.go index 22d7655a33..94f087aadd 100644 --- a/cmd/werf/render/render.go +++ b/cmd/werf/render/render.go @@ -391,6 +391,7 @@ func runRender(ctx context.Context) error { Namespace: namespace, Env: *commonCmdData.Environment, IsStub: isStub, + DisableEnvStub: true, StubImagesNames: stubImagesNames, SetDockerConfigJsonValue: *commonCmdData.SetDockerConfigJsonValue, DockerConfigPath: *commonCmdData.DockerConfig, diff --git a/pkg/deploy/helm/chart_extender/helpers/service_values.go b/pkg/deploy/helm/chart_extender/helpers/service_values.go index e6de5d6517..3acd4e5a28 100644 --- a/pkg/deploy/helm/chart_extender/helpers/service_values.go +++ b/pkg/deploy/helm/chart_extender/helpers/service_values.go @@ -37,13 +37,22 @@ type ServiceValuesOptions struct { Env string IsStub bool StubImagesNames []string - CommitHash string - CommitDate *time.Time + // disable env stub used in the werf-render command + DisableEnvStub bool + CommitHash string + CommitDate *time.Time SetDockerConfigJsonValue bool DockerConfigPath string } +func GetEnvServiceValues(env string) map[string]interface{} { + return map[string]interface{}{ + "werf": map[string]interface{}{"env": env}, + "global": map[string]interface{}{"env": env}, + } +} + func GetServiceValues(ctx context.Context, projectName, repo string, imageInfoGetters []*image.InfoGetter, opts ServiceValuesOptions) (map[string]interface{}, error) { globalInfo := map[string]interface{}{ "werf": map[string]interface{}{ @@ -70,7 +79,7 @@ func GetServiceValues(ctx context.Context, projectName, repo string, imageInfoGe if opts.Env != "" { globalInfo["env"] = opts.Env werfInfo["env"] = opts.Env - } else if opts.IsStub { + } else if opts.IsStub && !opts.DisableEnvStub { globalInfo["env"] = "" werfInfo["env"] = "" } diff --git a/pkg/deploy/helm/chart_extender/werf_chart_stub.go b/pkg/deploy/helm/chart_extender/werf_chart_stub.go index 841323ac45..862c0fd050 100644 --- a/pkg/deploy/helm/chart_extender/werf_chart_stub.go +++ b/pkg/deploy/helm/chart_extender/werf_chart_stub.go @@ -31,6 +31,7 @@ type WerfChartStub struct { SecretValueFiles []string extraAnnotationsAndLabelsPostRenderer *helm.ExtraAnnotationsAndLabelsPostRenderer + stubServiceValuesOverrides map[string]interface{} stubServiceValues map[string]interface{} *secrets.SecretsRuntimeData @@ -105,6 +106,7 @@ func (wc *WerfChartStub) ChartDependenciesLoaded() error { // MakeValues method for the chart.Extender interface func (wc *WerfChartStub) MakeValues(inputVals map[string]interface{}) (map[string]interface{}, error) { vals := make(map[string]interface{}) + chartutil.CoalesceTables(vals, wc.stubServiceValuesOverrides) chartutil.CoalesceTables(vals, wc.stubServiceValues) chartutil.CoalesceTables(vals, wc.SecretsRuntimeData.DecodedSecretValues) chartutil.CoalesceTables(vals, inputVals) @@ -138,3 +140,7 @@ func (wc *WerfChartStub) ReadFile(filePath string) (bool, []byte, error) { func (wc *WerfChartStub) SetStubServiceValues(vals map[string]interface{}) { wc.stubServiceValues = vals } + +func (wc *WerfChartStub) SetStubServiceValuesOverrides(vals map[string]interface{}) { + wc.stubServiceValuesOverrides = vals +}