Search code examples
kubernetes-helmnginx-ingress

How does nginx ingress HELM chart compute the service account name?


I am looking at the relevant HELM code - https://github.com/kubernetes/ingress-nginx/blob/helm-chart-4.5.2/charts/ingress-nginx/templates/controller-serviceaccount.yaml:

{{- if or .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    {{- include "ingress-nginx.labels" . | nindent 4 }}
    app.kubernetes.io/component: controller
    {{- with .Values.controller.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  name: {{ template "ingress-nginx.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
  {{- if .Values.serviceAccount.annotations }}
  annotations:
  {{- toYaml .Values.serviceAccount.annotations | nindent 4 }}
  {{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
{{- end }}

Specifically the line:

name: {{ template "ingress-nginx.serviceAccountName" . }}

My question is - how does this get resolved?


Solution

  • It is defined in the _helpers.tpl file:

    {{- define "ingress-nginx.serviceAccountName" -}}
    {{- if .Values.serviceAccount.create -}}
        {{ default (include "ingress-nginx.fullname" .) .Values.serviceAccount.name }}
    {{- else -}}
        {{ default "default" .Values.serviceAccount.name }}
    {{- end -}}
    {{- end -}}