Skip to content
Permalink
Browse files
fix(helm): restore 'werf helm *' commands behavior for an env value
* `werf helm *` commands set stub empty string into .Values.global.env and .Values.werf.env.
* `werf helm lint` command respects --env / WERF_ENV param to allow more correct usage in CI/CD params due to the lack of `werf lint` command.
* `werf render` command behaves the same way as `werf converge` command: set .Values.global.env and .Values.werf.env to nil (not empty string).

Closes #4659

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Sep 1, 2022
1 parent 3008ae4 commit 528a7064f33aab27a49192ba8497620298b88d26
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
@@ -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)
}
@@ -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,
@@ -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"] = ""
}
@@ -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
}

0 comments on commit 528a706

Please sign in to comment.