{{- $disable_lookups:= .Values.disableLookups }}
{{- $cluster_name :=  default "mycluster" .Release.Name }}
{{- $install_namespace := .Release.Namespace }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ $cluster_name }}-sa
  namespace: {{ $install_namespace }}
{{- if ((((.Values).image).pullSecrets).enabled) }}
imagePullSecrets:
  {{- $secret_name := .Values.image.pullSecrets.secretName }}
  {{- if not $secret_name }}
    {{- fail "image.pullSecrets.secretName is required when pull secrets are enabled" }}
  {{- end }}
  {{- if and (not $disable_lookups) (not (lookup "v1" "Secret" $install_namespace $secret_name)) }}
    {{- $err := printf "image.pullSecrets.secretName: secret '%s' not found in namespace '%s'" $secret_name $install_namespace }}
    {{- fail $err }}
  {{- end }}
- name: {{ $secret_name }}
{{- end }}