From 8891439cdc50b36c88a37214428d27f684b5b09e Mon Sep 17 00:00:00 2001 From: Thomas Loubiou Date: Wed, 4 Dec 2024 11:51:21 +0100 Subject: [PATCH] fix: inject global values in Chartify (#1805) * fix: inject global values in Chartify Signed-off-by: Thomas Loubiou * test: add integration tests for template --values Signed-off-by: Thomas Loubiou --------- Signed-off-by: Thomas Loubiou --- pkg/app/app.go | 1 + pkg/state/state.go | 5 ++ test/integration/test-cases/chartify.sh | 10 +-- .../chartify/input/extra-values.yaml | 3 + .../chartify/output/template-values | 61 +++++++++++++++++++ 5 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 test/integration/test-cases/chartify/input/extra-values.yaml create mode 100644 test/integration/test-cases/chartify/output/template-values diff --git a/pkg/app/app.go b/pkg/app/app.go index 7d0e0e11..a99e79fa 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -250,6 +250,7 @@ func (a *App) Template(c TemplateConfigProvider) error { Concurrency: c.Concurrency(), IncludeTransitiveNeeds: c.IncludeNeeds(), Set: c.Set(), + Values: c.Values(), KubeVersion: c.KubeVersion(), }, func() { ok, errs = a.template(run, c) diff --git a/pkg/state/state.go b/pkg/state/state.go index 629372ce..6c954faf 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -1127,6 +1127,7 @@ type ChartPrepareOptions struct { Concurrency int KubeVersion string Set []string + Values []string // Delete wait DeleteWait bool DeleteTimeout int @@ -1294,6 +1295,10 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre chartifyOpts.KubeVersion = st.getKubeVersion(release, opts.KubeVersion) chartifyOpts.ApiVersions = st.getApiVersions(release) + if opts.Values != nil { + chartifyOpts.ValuesFiles = append(opts.Values, chartifyOpts.ValuesFiles...) + } + // https://github.com/helmfile/helmfile/pull/867 // https://github.com/helmfile/helmfile/issues/895 var flags []string diff --git a/test/integration/test-cases/chartify.sh b/test/integration/test-cases/chartify.sh index 581e2d00..963fbbd6 100644 --- a/test/integration/test-cases/chartify.sh +++ b/test/integration/test-cases/chartify.sh @@ -12,16 +12,18 @@ fi chartify_tmp=$(mktemp -d) chartify_template_reverse=${chartify_tmp}/chartify.template.log - test_start "helmfile template with chartify" info "Comparing template/chartify" -${helmfile} -f ${chartify_case_input_dir}/${config_file} template > ${chartify_template_reverse} || fail "\"helmfile template\" shouldn't fail" +${helmfile} -f ${chartify_case_input_dir}/${config_file} template >${chartify_template_reverse} || fail "\"helmfile template\" shouldn't fail" ./dyff between -bs ${chartify_case_output_dir}/template ${chartify_template_reverse} || fail "\"helmfile template\" should be consistent" info "Comparing template/chartify with set" -${helmfile} -f ${chartify_case_input_dir}/${config_file} template --set image.tag=v2 > ${chartify_template_reverse} || fail "\"helmfile template\" shouldn't fail" +${helmfile} -f ${chartify_case_input_dir}/${config_file} template --set image.tag=v2 >${chartify_template_reverse} || fail "\"helmfile template\" shouldn't fail" ./dyff between -bs ${chartify_case_output_dir}/template-set ${chartify_template_reverse} || fail "\"helmfile template\" should be consistent" +info "Comparing template/chartify with values" +${helmfile} -f ${chartify_case_input_dir}/${config_file} template --values "./extra-values.yaml" >${chartify_template_reverse} || fail "\"helmfile template\" shouldn't fail" +./dyff between -bs ${chartify_case_output_dir}/template-values ${chartify_template_reverse} || fail "\"helmfile template\" should be consistent" -test_pass "helmfile template with chartify" \ No newline at end of file +test_pass "helmfile template with chartify" diff --git a/test/integration/test-cases/chartify/input/extra-values.yaml b/test/integration/test-cases/chartify/input/extra-values.yaml new file mode 100644 index 00000000..6c94f108 --- /dev/null +++ b/test/integration/test-cases/chartify/input/extra-values.yaml @@ -0,0 +1,3 @@ +--- +image: + tag: v3 diff --git a/test/integration/test-cases/chartify/output/template-values b/test/integration/test-cases/chartify/output/template-values new file mode 100644 index 00000000..f34afa09 --- /dev/null +++ b/test/integration/test-cases/chartify/output/template-values @@ -0,0 +1,61 @@ +--- +# Source: httpbin/templates/patched_resources.yaml +apiVersion: v1 +kind: Service +metadata: + labels: + app: httpbin + chart: httpbin-0.1.0 + heritage: Helm + release: httpbin + name: httpbin-httpbin +spec: + ports: + - name: httpbin + port: 8000 + protocol: TCP + targetPort: 8000 + selector: + app: httpbin + release: httpbin + type: LoadBalancer +--- +# Source: httpbin/templates/patched_resources.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: httpbin + chart: httpbin-0.1.0 + heritage: Helm + release: httpbin + name: httpbin-httpbin +spec: + replicas: 1 + selector: + matchLabels: + app: httpbin + strategy: + type: Recreate + template: + metadata: + labels: + app: httpbin + release: httpbin + spec: + containers: + - image: docker.io/citizenstig/httpbin:v3 + imagePullPolicy: Always + livenessProbe: + httpGet: + path: / + port: 8000 + name: httpbin + ports: + - containerPort: 8000 + readinessProbe: + httpGet: + path: / + port: 8000 + resources: {} +status: {}