Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference other variables in values.yaml.gotmpl #2078

Open
mseiwald opened this issue Feb 3, 2022 · 6 comments
Open

Reference other variables in values.yaml.gotmpl #2078

mseiwald opened this issue Feb 3, 2022 · 6 comments

Comments

@mseiwald
Copy link

mseiwald commented Feb 3, 2022

Hi,

I would like to achieve something like the below.

values.yaml.gotmpl

customer: xxxxx
domain: {{ .Values.customer }}.example.com

This obviously does not work. Is there another way to reference a previous variable in values.yaml.gotmpl that I'm missing?

Thanks!

@MurzNN
Copy link

MurzNN commented Feb 4, 2022

Try to use the recommendation from this document: https://github.com/roboll/helmfile/blob/master/docs/writing-helmfile.md#layering-state-template-files - something like this:

customer: xxxxx
---
domain: {{ .Values.customer }}.example.com

@pathob
Copy link

pathob commented Feb 9, 2022

Hi @mumoshu, Hi @MurzNN

I would like to add my question here, I hope that's fine.

Is this also possible with environment values? Can I use Go templating and the state layering there? What I'm trying to do is something like:

org:
  keyvault:
    kv1: org-kv1.vault.azure.net
---
org:
  database:
    postgres96:
      host: ref+azurekeyvault://{{ .Values.org.keyvault.kv1 }}/azure-postgresql-96-host
      user: ref+azurekeyvault://{{ .Values.org.keyvault.kv1 }}/azure-postgresql-96-user
      ...
    postgres11:
      host: ref+azurekeyvault://{{ .Values.org.keyvault.kv1 }}/azure-postgresql-11-host
      user: ref+azurekeyvault://{{ .Values.org.keyvault.kv1 }}/azure-postgresql-11-user
      ...

But it does not work. I get something like:

err: failed to read helmfile.yaml: failed to load environment values file "environments/dev.yaml.gotmpl": failed to render [environments/dev.yaml.gotmpl], because of template: stringTemplate:17:42: executing "stringTemplate" at <.Values.org.keyvault.kv1>: map has no entry for key "org"

Any help would be very appreciated. Thank you!

@Ro-Fo
Copy link

Ro-Fo commented May 4, 2022

Hi,
Currently I have the same problem like @pathob

helmfile.yaml

releases:
- name: myservice
  namespace: test
  chart: chart/parent
  values:
  - values.yaml.gotmpl

values.yaml.gotmpl

customer: xxxxx
---
domain: {{ .Values.customer }}.example.com

this leads to the following errors @MurzNN

helmfile write-values
> ... in ./helmfile.yaml: failed to render values files "values.yaml.gotmpl": failed to render [values.yaml.gotmpl], because of template: stringTemplate:3:18: 
executing "stringTemplate" at <.Values.customer>: map has no entry for key "customer"

Thanks for your support.

@mumoshu
Copy link
Collaborator

mumoshu commented May 6, 2022

@pathob @Ro-Fo Hey! As far as I remember, I don't think --- was supported in values file templates.
It's supported in helmfile.yaml templates so all I can say is that you'd better handle such "layering" in helmfile yamls, not values templates.

You could also try combining dict, merge, readFile, and fromYaml to merge objects, and finally outputting yaml by piping the result to toYaml in your values template.

@mathe-matician
Copy link

Same issue here. I'm trying to migrate an existing chart over to helmfile. The original chart used named templates and did a bunch of stuff that can be simplified by templating out a values file w/ helmfile.

So I thought I'd be able to do something like this:

# helmfile
releases:
- name: mychart
  namespace: test
  chart: mychart
  values:
  - values.yaml
  - custom-thing.gotmpl
# values.yaml
trueThing: true
# custom-thing.gotmpl
{{- if .Values.trueThing }}
do it
{{- else }}
don't do it
{{- end }}

How can I achieve this?

@TheCodingSheikh
Copy link

Same issue here. I'm trying to migrate an existing chart over to helmfile. The original chart used named templates and did a bunch of stuff that can be simplified by templating out a values file w/ helmfile.

So I thought I'd be able to do something like this:

# helmfile
releases:
- name: mychart
  namespace: test
  chart: mychart
  values:
  - values.yaml
  - custom-thing.gotmpl
# values.yaml
trueThing: true
# custom-thing.gotmpl
{{- if .Values.trueThing }}
do it
{{- else }}
don't do it
{{- end }}

How can I achieve this?

Did u figure this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants