如何访问helm模板中属性名称中带有冒号的属性



在helm模板中,我想写以下内容:

{{- if empty .Values.conf.proxy_server.filter:authtoken.auth_uri -}}
{{- $_ := tuple "identity" "internal" "api" . | include "helm-toolkit.endpoints.keystone_endpoint_uri_lookup"| set .Values.conf.proxy_server.filter:authtoken "auth_uri" -}}
{{- end -}}

由于filter:authtoken中有一个冒号,我得到的错误如下:

Error: parse error in "swift/templates/configmap-etc.yaml": template: swift/templates/configmap-etc.yaml:20: expected :=

values.yaml中,摘录如下:

conf:
proxy_server:
filter:authtoken:
paste.filter_factory: keystonemiddleware.auth_token:filter_factory
auth_type: password
......

那么,无论如何都要解决这个问题?

这不是有效的YAML;但是,作为YAML,有多种方法可以"拼写"事物。(所有有效的JSON都是有效的YAML。(在其他选项中,您可以引用值文件中的键:

conf:
proxy_server:
"filter:authtoken":
paste.filter_factory: "keystonemiddleware.auth_token:filter_factory"
auth_type: password
......

(我还在中引用了带冒号的值……以防它被误解为映射。(

当你去读回它时,你可能必须使用go text/templateindex函数来提取值,因为它看起来不像一个普通的名称。

{{- if empty (index .Values.conf.proxy_server "filter:authtoken").auth_uri -}}

由于作为图表作者,您可以控制在values.yaml文件中查找的内容,因此选择一个更中性的标点符号(如句点或下划线(可能会更容易,并避免所有这些。

最新更新