0
votes

I have a file which will be binded to a configmap. Once I put a tpl function in it, it stops working when other lines are included in the file.

I use this helper tpl:

{{- define "call-nested" }}
{{- $dot := index . 0 }}
{{- $subchart := index . 1 | splitList "." }}
{{- $template := index . 2 }}
{{- $values := $dot.Values }}
{{- range $subchart }}
{{- $values = index $values . }}
{{- end }}
{{- include $template (dict "Chart" (dict "Name" (last $subchart)) "Values" $values "Release" $dot.Release "Capabilities" $dot.Capabilities) }}
{{- end }}

testing in some.yaml:

psqlhost:  {{include "call-nested" (list . "postgresql" "postgresql.fullname")}}
newlinekey: value

It works well if some.yaml is a standalone file. But once I bind it a configmap, it gives this error:

executing "mytestchart/templates/my-configmap.yaml" at <tpl (.Files.Glob "config/*").AsConfig .>: error calling tpl: Error during tpl function execution for "some.yaml:<br>\"name:  {{include \\\"call-nested\\\" (list . \\\"postgresql\\\" \\\"postgresql.fullname\\\")}}\\r\\nnewlinekey:\n  value\"\n": parse error in "mytestchart/templates/my-configmap.yaml": template: mytestchart/templates/my-configmap.yam:1: unexpected "\\" in operand

Once I remove the new line it will also work well.

edit: Configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: somename
data:
{{ tpl (.Files.Glob "config/*").AsConfig .| indent 2 }}
1
I am investigating your issue. Could you please try changing the 6th line of your ConfigMap to this: {{ (.Files.Glob "confs/*").AsConfig | indent 2 }} and let me know if that works?Wytrzymały Wiktor
Any progress with your case?Wytrzymały Wiktor

1 Answers

0
votes

Your template is not rendering correctly. In order to make it work you need to change the following:

  1. Add a .tmpl suffix to the file you'd like to put to your ConfigMap, for example: some.yaml.tmpl.

  2. Set your ConfigMap's data: to: {{- tpl ((.Files.Glob "config/*.tmpl").AsConfig) . | indent 2 }}. Add a indentation to that line also.

Your ConfigMap would than look something like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: somename
data:
  {{- tpl ((.Files.Glob "config/*.tmpl").AsConfig) . | indent 2 }}

You can find more info with some examples here.

Please let me know if that helped.