helmfile icon indicating copy to clipboard operation
helmfile copied to clipboard

Ability to set appVersion

Open Stono opened this issue 4 years ago • 14 comments

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 avatar Sep 30 '21 21:09 Stono

@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 we aren't able to see the app's version, only checking the app's labels.

sergiomacedo avatar Oct 21 '21 18:10 sergiomacedo

Any news or hack?

robsonpeixoto avatar Oct 26 '21 21:10 robsonpeixoto

Nope, nothing from my side! :)

Stono avatar Oct 27 '21 10:10 Stono

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 avatar Dec 16 '21 12:12 slavashvets

@slavashvets do you use these hooks as global or per release?

sergiomacedo avatar Dec 22 '21 21:12 sergiomacedo

@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 avatar Dec 23 '21 13:12 sergiomacedo

@sergiomacedo Per release. I've updated the answer. Removed unneeded variables.

slavashvets avatar Jan 24 '22 12:01 slavashvets

@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 avatar Mar 23 '22 20:03 sergiomacedo

@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 avatar Mar 23 '22 23:03 mumoshu

@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.

sergiomacedo avatar Mar 25 '22 19:03 sergiomacedo

@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 avatar Mar 25 '22 19:03 sergiomacedo

@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 🤔

mumoshu avatar Mar 27 '22 01:03 mumoshu

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.

sergiomacedo avatar Mar 28 '22 20:03 sergiomacedo

Anyway, it would be nice if we could set this using a less "hacky" way... :smile:

sergiomacedo avatar Mar 31 '22 15:03 sergiomacedo