Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 253
Matt Avatar asked Feb 05 '23 01:02

Matt


2 Answers

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*"]
like image 82
nickgryg Avatar answered Apr 05 '23 02:04

nickgryg


Alternatively, the following also worked for me without having to extra-quote the input values:

"{{- join "\",\"" .Values.myArrayField }}"

Of course, this only works for non-empty arrays and produces a single empty quoted value for an empty array. Someone knows a simple guard one could integrate here?

like image 25
enote-kane Avatar answered Apr 05 '23 00:04

enote-kane