0

I have a helm chart that is using some kind of custom template references (as far as I understand). This is the .tpl file:

{{- define "common.secret._header" -}}
{{- $global := .global }}
{{- $name := .name }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ $name }}
  namespace: {{ include "common.namespace" $global }}
  labels:
    app: {{ include "common.name" $global }}
    chart: {{ $global.Chart.Name }}-{{ $global.Chart.Version | replace "+" "_" }}
    release: {{ include "common.release" $global }}
    heritage: {{ $global.Release.Service }}
{{- end -}}

I am used to having the predefined .Values or .Release template references, but I have never seen the .global or .name references before. I guess they are custom defined versions of the same concept.

Can someone explain the general mechanism behind this and how they are assigned?

94621
  • 39
  • 7
  • 1
    A `define` template takes a single parameter, which is `.`. So `.global` is a "named parameter" more or less from a call like `{{ include "common.secret._header" (dict "global" .Values.global "name" "some-name") }}`. Other things can be `.` too, and the linked question has more details. – David Maze Mar 15 '23 at 11:09
  • Thanks @DavidMaze. So in your example, the `(dict ...)` is defining the parameter for that `include`, right? Now that you say it, I have found this being used as `{{ include "common.secret._header" (dict "global" . "name" "myName") }}` in my chart. Can you say a word about the `.Values.global` that you have included in your example? – 94621 Mar 15 '23 at 12:43
  • 1
    Correct, in that invocation the `(dict ...)` is the parameter, and inside the called template that appears as `.`. `.Values.global` refers to, well, a block named `global` in the `values.yaml` file, but it's propagated into dependency charts; also see [Global Values](https://docs.helm.sh/docs/topics/charts/#global-values) in the Helm documentation. – David Maze Mar 15 '23 at 13:46

0 Answers0