How do you pass multiple parameters to a named template?
AdvancedConceptTemplating: Go Templates & Sprig
Answer
A named template receives exactly one argument, so build a dict that carries the root context and your extra parameters:
{{- define "shop.service" -}}
apiVersion: v1
kind: Service
metadata:
name: {{ include "shop.fullname" .root }}-{{ .component }}
labels:
{{- include "shop.labels" .root | nindent 4 }}
spec:
ports:
- port: {{ .port }}
targetPort: http
selector:
{{- include "shop.selectorLabels" .root | nindent 4 }}
app.kubernetes.io/component: {{ .component }}
{{- end }}
{{ include "shop.service" (dict "root" . "component" "api" "port" 3000) }}
Forgetting to pass the root is the cause of can't evaluate field Release in type string.
More on Templating: Go Templates & Sprig
What template language does Helm use?BeginnerWhat does the dot (`.`) mean in a Helm template?BeginnerWhat is `$` and when do you need it?IntermediateHow does whitespace control (`{{-` and `-}}`) work?BeginnerHow do `if`, `else if` and `else` evaluate truthiness?BeginnerWhat do `and`, `or`, `not`, `eq`, `ne`, `lt`, `gt` look like in Helm?Beginner