Search code examples
kubernetes-helmgo-templates

How can I access a value in a parent Helm chart from a subchart containing dashes in its name?


I am trying to access values in a parent Helm chart from a subchart using the method described in this PR:

{{ template "foo-bar.fullname" .Subcharts.foo-bar }}-rest-of-string

However, I am getting bad character U+002D '-' errors when doing so due to the subchart containing dashes in its name.

Renaming the subchart is not possible since it's upstream.

How can I circumvent this?

Using helm v3.13.0.


Solution

  • The Go text/template documentation doesn't fully spell out the rules for what characters are allowed in variable or field names, but if it follows Go's rules, - isn't allowed in the middle of a name (in Go it would be a subtraction operator).

    You can use the standard index function to get around this. index $foo "bar" is the same thing as $foo.bar, but index uses a quoted string (or a variable) to find the map key so it doesn't have the same syntactic constraints.

    {{ template "foo-bar.fullname" (index .Subcharts "foo-bar") }}-rest-of-string