Search code examples
kubernetes-helm

helm join list from values file


I'm looking for a solution to transform a list in my values.yaml in a comma separated list.

values.yaml

app:
  logfiletoexclude:
    - "/var/log/containers/kube*"
    - "/var/log/containers/tiller*"

_helpers.tpl:

{{- define "pathtoexclude" -}}
{{- join "," .Values.app.logfiletoexclude }}
{{- end -}}

configmap:

<source>
  @type tail
  path /var/log/containers/*.log
  exclude_path [{{ template "pathtoexclude" . }}]
  ...
  ...
</source>

The problem is there is missing quotes in my result

 exclude_path [/var/log/containers/kube*,/var/log/containers/tiller*]

How can I fix it to be able to have:

  exclude_path ["/var/log/containers/kube*","/var/log/containers/tiller*"] 

I've try with:

{{- join "," .Values.app.logfiletoexclude | quote}}

but this give me:

exclude_path ["/var/log/containers/kube*,/var/log/containers/tiller*"] 

Thanks


Solution

  • Double quotes should be escaped in .Values.app.logfiletoexclude values.

    values.yaml is:

    app:
      logfiletoexclude:
        - '"/var/log/containers/kube*"'
        - '"/var/log/containers/tiller*"'
    

    _helpers.tpl is:

    {{- define "pathtoexclude" -}}
    {{- join "," .Values.app.logfiletoexclude }}
    {{- end -}}
    

    And finally we have:

    exclude_path ["/var/log/containers/kube*","/var/log/containers/tiller*"]