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

12/7/2018

In the helm template, I want to write something like below:

{{- 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 -}}

Since there is a colon in filter:authtoken, I got the error as below:

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

In values.yaml, the snippet is as below:

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

So anyway to workaround this ?

-- 英佶孙
kubernetes-helm

1 Answer

12/7/2018

That's not valid YAML; but YAML being YAML there are multiple ways to "spell" things. (All valid JSON is valid YAML.) Among other options, you can quote the key in the values file:

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

(I've also quoted the value with a colon in in...just in case it gets misinterpreted as a mapping.)

When you go to read it back, you probably will have to use the Go text/template index function to pluck the value out, since it doesn't look like an ordinary name.

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

Since, as a chart author, you control what you're looking for in the values.yaml file, it may be easier to just pick a more neutral punctuation mark like a period or underscore, and avoid all of this.

-- David Maze
Source: StackOverflow