【发布时间】:2020-04-08 09:27:41
【问题描述】:
我有一个将绑定到配置映射的文件。一旦我将一个 tpl 函数放入其中,当文件中包含其他行时,它就会停止工作。
我使用这个助手 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 }}
在 some.yaml 中测试:
psqlhost: {{include "call-nested" (list . "postgresql" "postgresql.fullname")}}
newlinekey: value
如果 some.yaml 是独立文件,它会很好地工作。但是一旦我将它绑定到一个 configmap,它就会给出这个错误:
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
一旦我删除了新行,它也可以正常工作。
编辑:配置图:
apiVersion: v1
kind: ConfigMap
metadata:
name: somename
data:
{{ tpl (.Files.Glob "config/*").AsConfig .| indent 2 }}
【问题讨论】:
-
我正在调查您的问题。您能否尝试将 ConfigMap 的第 6 行更改为:
{{ (.Files.Glob "confs/*").AsConfig | indent 2 }}并告诉我是否可行?
标签: kubernetes kubernetes-helm