Created
December 30, 2023 16:38
-
-
Save daveneeley/5f88d46d4c1f0491a6abdc9af0162a1e to your computer and use it in GitHub Desktop.
render template against merged release template before rendering final values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# controls which charts are installed | |
environments: | |
default: | |
values: | |
- fake: | |
install: false | |
ci_cd: | |
values: | |
- fake: | |
install: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# controls values in the release | |
# but elastic-exporter.values.gotmpl is evaluated too early | |
# want a method to apply the template after all other values are merged | |
templates: | |
release_template: | |
values: | |
- chart: | |
key: template-default-value | |
- elastic-exporter.values.gotmpl | |
installedTemplate: | | |
{{`{{ eq .Values.fake.install true }}`}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# passes because installedTemplate will be set to false | |
helmfile diff --environment=default && echo "environment=default: PASS" | |
# fails because elastic-exporter.values.gotmpl will be rendered | |
# but it tries to set a value whose key is loaded in the same render | |
helmfile diff --environment=ci_cd && echo "environment=ci_cd: PASS" || echo "environment=ci_cd: FAIL" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{/* won't render because chart.key is created in the same base and doesn't "exist" yet */}} | |
{{- $chartVals := .Values }} | |
{{- $chartVals = $chartVals | setValueAtPath "chart.key" "chart-specific-val" }} | |
{{ toYaml $chartVals }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bases: | |
- base-1.yaml.gotmpl | |
--- | |
bases: | |
- base-2.yaml.gotmpl | |
--- | |
repositories: | |
- name: prometheus-community | |
url: https://prometheus-community.github.io/helm-charts | |
releases: | |
- name: elastic-exporter | |
namespace: monitoring | |
chart: prometheus-community/prometheus-elasticsearch-exporter | |
inherit: | |
- template: release_template |
This gist was created to showcase a dilemma in helmfile/helmfile#1261
Note that if you changed elastic-exporter.values.gotmpl
to the following that it renders successfully.
chart:
key: chart-specific-val
The point is that programmatic merging with custom template functions like setValueAtPath
can't be used because it seems that .Values
is not kept up to date as the values/files are loaded in the current phase.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output of
bash demo.sh