combine Strings and vars in Helm chart

11/23/2020

Hi i need to make these Options changeabel:

values.yaml

connector:
  proxyname: "xx.${{ .Values.context }}.xx.xx"

ingress:
  hosts:
    - host: xx.${{ .Values.context }}.xx.xx
  tls:
      hosts: 
        - xx.${{ .Values.context }}.xx.xx

my understanding was i can call it now like this:

helm install newpod -f ... --set context=${{ github.event.inputs.context }} .

But after i call this i get the following message:

.... [spec.rules[0].host: Invalid value: "xx.{{ .Values.context }}.xx.xx" ....

how can i deal with it?

-- Klatuu
kubernetes
kubernetes-helm

1 Answer

11/23/2020

This can be achieved using tpl function

values.yaml

context: test

connector:
  proxyname: "xx.{{ .Values.context }}.xx.xx"

manifest.yaml

test: {{ tpl .Values.connector.proxyname . }} 

If you need to use them in your ingress inside a range, use $ to point to the root context

ingress.yaml

...
spec:
  {{- if .Values.ingress.tls }}
  tls:
    {{- range .Values.ingress.tls }}
    - hosts:
        {{- range .hosts }}
        - {{ tpl . $ | quote }}
        {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- range .Values.ingress.hosts }}
    - host: {{ tpl .host $ | quote }}
      http:
        paths:
...

NOTES.txt

...
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ tpl $host.host $ }}{{ . }}
...
-- edbighead
Source: StackOverflow