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

how to access the attribute with colon in attribute name in helm template

在 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 是 YAML,有多种方法可以 "spell" 事情。 (所有有效的 JSON 都是有效的 YAML。)在其他选项中,您可以引用值文件中的密钥:

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

(我还在...中用冒号引用了该值,以防它被误解为映射。)

当你去读它的时候,你可能不得不使用 Go text/template index 函数来提取值,因为它看起来不像一个普通的名字。

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

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