helmfile
helmfile copied to clipboard
Ability to set appVersion
Hey I’m guessing you’ll have read https://github.com/helm/helm/issues/8194 at some point.
The general idea is that we use a common chart to deploy applications so would like to be able to set the appVersion field in Chart.yaml at runtime.
As helmfile wraps helm and I (assume) first fetches the charts, is this something helmfile could do?
Thanks
@Stono I'm having exactly the same issue. One standard chart for the company, with different apps being deployed using it. When we run helm list -n
Any news or hack?
Nope, nothing from my side! :)
We use the following workaround (set $VERSION and $APP_VERSION variable before you run helmfile):
{{ $prefix := now | unixEpoch }}
hooks:
- events: ['prepare']
command: "helm"
args: ["fetch", "repo-name/{{ .Name }}-chart", "--version={{ env "VERSION" }}", "--untar", "-d", "charts/{{ $prefix }}"]
- events: ['prepare']
command: "sed"
args: ["-i", "-e", "$aappVersion: {{ env "APP_VERSION" }}", "charts/{{ $prefix }}/{{ .Name }}-chart/Chart.yaml"]
@slavashvets do you use these hooks as global or per release?
@slavashvets I tried your solution but to no avail. The chart is correctly downloaded by fetch and the Chart.yaml receives the appVersion at its end. However, helm list still shows an empty APP VERSION column. What am I missing?
@sergiomacedo Per release. I've updated the answer. Removed unneeded variables.
@slavashvets Just now I had the time to test this solution again and it still didn't work. Here's my helmfile.yaml:
repositories:
- name: my-custom-chart
url: git+ssh://[email protected]/private/my-custom-chart@repo?ref=main&sparse=0
releases:
- chart: my-custom-chart/my-custom-chart
name: test-app
namespace: test-app
values:
- values/base.yaml.gotmpl
hooks:
- events: ['prepare']
command: "helm"
args: ["fetch", "my-custom-chart/my-custom-chart", "--untar", "-d", "charts/{{`{{ .Release.Name }}`}}"]
- events: ['prepare']
command: "sed"
args: ["-i", "-e", "$aappVersion: {{`{{ .Values.version }}`}}", "charts/{{`{{ .Release.Name }}`}}/my-custom-chart/Chart.yaml"]
environments:
homolog:
values:
- values/HOMOLOG.yaml
- values/version.yaml
If I check the charts/test-app/my-custom-chart/Chart.yaml, the variable appVersion is correctly set to the version present in values/version.yaml. However, the appVersin does not appear set when I run helm list -n test-app.
Any hints on what may be different from your setup?
@sergiomacedo AFAIK, hooks had no support for release templates so that might be the issue. Does the appVersion really needs to be from the release template of {{ .Values.version }}?
This part of your config seems to indicate that the version if defined per environment, nor per release, right??
environments:
homolog:
values:
- values/HOMOLOG.yaml
- values/version.yaml
If so, you don't need to use release template, just go ahead with the helmfile template, something like:
environments:
homolog:
values:
- values/HOMOLOG.yaml
- values/version.yaml
---
repositories:
- name: my-custom-chart
url: git+ssh://[email protected]/private/my-custom-chart@repo?ref=main&sparse=0
releases:
{{ $releaseName := "test-app" -}}
- chart: my-custom-chart/my-custom-chart
name: {{ $releaseName }}
namespace: test-app
values:
- values/base.yaml.gotmpl
hooks:
- events: ['prepare']
command: "helm"
args: ["fetch", "my-custom-chart/my-custom-chart", "--untar", "-d", "charts/{{ $releaseName }}"]
- events: ['prepare']
command: "sed"
args: ["-i", "-e", "$aappVersion: {{ .Values.version }}", "charts/{{ $releaseName }}/my-custom-chart/Chart.yaml"]
Do ensure environments is in the top of your helmfile.yaml and there's --- to reliably use environment values within template. Otherwise you may end up famous chicken-and-egg problem. (Helmfile needs to render the whole helmfile.yaml as a go template to obtain the YAML to load, but to load YAML it needs to render the yaml!
@mumoshu just to clear one thing up: the version.yaml is on each environment on this example because of issue/feature request https://github.com/roboll/helmfile/issues/2033
I know I could get it from environment but it isn't the way it is right now (I'm working on this).
That being said, I'll try your suggestion.
@mumoshu @slavashvets Here's the result:
$ helm list -n test-app
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
test-app test-app 133 2022-03-25 16:12:35.411269922 -0300 -03 deployed my-custom-chart-0.0.1
$ cat charts/test-app/my-custom-chart/Chart.yaml
apiVersion: v2
description: XXXXXXXXX
name: my-custom-chart
sources:
- https://github.com/XXXXXXXXXXXX
version: 0.0.1
appVersion: v1.2.3
As you can see, the appVersion, though present in the extracted Chart.yaml, isn't applied to the deployed helm.
Any other idea?
@sergiomacedo That might be because you have chart: my-custom-chart/my-custom-chart which instructs helmfile to install your release from the chart chart: my-custom-chart/my-custom-chart, while you're modifying another local chart's Chart.yaml that's unrelated to chart: my-custom-chart/my-custom-chart 🤔
That was it, @mumoshu. After pointing the chart to the locally fetched copy, everything worked as expected.
repositories:
- name: my-custom-chart
url: git+ssh://[email protected]/private/my-custom-chart@repo?ref=main&sparse=0
releases:
- chart: ./charts/my-custom-chart
name: test-app
namespace: test-app
values:
- values/base.yaml.gotmpl
hooks:
- events: ['prepare']
command: "rm"
args: ["-rf", "./charts/" ]
- events: ['prepare']
command: "helm"
args: ["fetch", "my-custom-chart/my-custom-chart", "--untar", "-d", "charts/"]
- events: ['prepare']
command: "sed"
args: ["-i", "-e", "$aappVersion: {{`{{ .Values.version }}`}}", "charts/my-custom-chart/Chart.yaml"]
$ helm list -n test-app
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
test-app test-app 136 2022-03-28 16:47:09.666956037 -0300 -03 deployed my-custom-chart-0.0.1 main
Thanks for your time. This issue can be closed now.
Anyway, it would be nice if we could set this using a less "hacky" way... :smile: