Interview Prep/Helm/Templating: Go Templates & Sprig

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.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig