Search code examples
kubernetes-helm

Are Helm variables case insensitive? (The templates seem to be.)


I am trying to debug one of my Helm charts and I noticed that the app.kubernetes.io/version label is created using the following code (in _helpers.tpl):

{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}

But the actual variable is called appVersion. Similar inconsistencies exist with version and name. The use of them is using PascalCase, but the definition is using camelCase. I tried to google it, but can't find any info on it.

Are Helm variables really case insensitive? Or is there some kind of conversion going on behind the scenes.


Solution

  • The fields in the built-in objects are generally capitalized. That documentation also includes an example using {{ .Chart.Name }}-{{ .Chart.Version }}. Even though .Chart contains the contents of the chart.yaml file, its fields follow this convention.

    Field access is case-sensitive and if you reference .Chart.appVersion you should get an error.

    At an implementation level, the Go template . operator can either navigate a Go object tree or a Go map. The top-level object is a mix of maps and objects. .Values is an unstructured map; a release can include any values it wants in essentially any YAML layout. .Release turns out to be a map too, but with fixed known keys.

    .Chart is a chart.Metadata object (not the parsed YAML directly but an object form of it). Its fields are visible to the template engine. Go's rule is that structure fields that begin with capital letters are visible, and that capitalization carries through back to the template engine.