roboll / helmfile

Deploy Kubernetes Helm Charts
MIT License
4.03k stars 567 forks source link

How to feed dynamically generated values.yaml to specific release via envvar? #157

Closed gobengo closed 5 years ago

gobengo commented 6 years ago

I have a script that prepares the values for my app, and I'd like to use the computed value in my helmfile.

releases:
- name: apps
  namespace: default
  chart: ./charts/apps
  values:
  - {{ requiredEnv "APPS_CHART_VALUES" | default "" }}

and then

APPS_CHART_VALUES="$(./values)" helmfile sync

But I get an error

2018/05/31 13:12:56 err: failed to read ./helm/helmfile.yaml: yaml: line 91: did not find expected key

In a helm template I can sometimes use the 'toYaml' function, but it is not around in helmfile templates..

mumoshu commented 6 years ago

@gobengo Hi! Which version of helmfile do you use?

In case you're using older releases of helmfile, could you try again with a more recent one, like v0.17.0?

gobengo commented 6 years ago

I just tried on v0.20.0 tag in this reduced test case https://gitlab.ops.bengo.is/bugs/helmfile-env

output:

$ TILLER_NAMESPACE=helm ./reproduce_bug
exec: helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "bengo" chart repository
...Successfully got an update from the "monocular" chart repository
...Successfully got an update from the "akomljen-charts" chart repository
...Successfully got an update from the "gitlab" chart repository
...Successfully got an update from the "charts.gitlab.io" chart repository
...Successfully got an update from the "stable" chart repository
...Successfully got an update from the "coreos" chart repository
Update Complete. ⎈ Happy Helming!⎈
exec: helm dependency update /home/bengo/dev/bugs/helmfile-env/charts/apps
No requirements found in /home/bengo/dev/bugs/helmfile-env/charts/apps/charts.
exec: helm upgrade --install --reset-values apps /home/bengo/dev/bugs/helmfile-env/charts/apps --namespace default --values /tmp/values008400334
Error: UPGRADE FAILED: render error in "apps/templates/deployment.yaml": template: apps/templates/deployment.yaml:24:28: executing "apps/templates/deployment.yaml" at <.Values.image.reposi...>: can't evaluate field repository in type interface {}
err: exit status 1

For now I can prepare each environment variable ahead of running helmfile now, but what I really want to have is one script that will print my yaml values on stdout, and then be able to use that whole set of yaml values (not many different env vars) with one of the releases in a helmfile.

mumoshu commented 5 years ago

@gobengo How about this?

APPS_CHART_VALUES=<(./values) helmfile sync
gobengo commented 5 years ago

@mumoshu I think it worked! https://gitlab.ops.bengo.is/bugs/helmfile-env/commit/f9d748c19822a94924ac9d0211cfa5a48fa9782a

I was not familiar with that bash syntax. I guess it basically makes the values output 'look like' a file path to the helmfile program. So then helmfile can just read values from a file, which is already supported.

Thanks for the advice!

iamdempa commented 6 months ago

Hi @gobengo, i have a similar issue, could you post your answer here? The link you provided doesn't work :)