{{ if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
{{- if .Values.serviceAccount.automountServiceAccountToken }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
{{- end }}
metadata:
  name: {{ include "sealed-secrets.serviceAccountName" . }}
  namespace: {{ include "sealed-secrets.namespace" . }}
  {{- if or (.Values.commonAnnotations) (.Values.serviceAccount.annotations) }}
  annotations: 
    {{- if .Values.commonAnnotations }}
    {{- toYaml .Values.commonAnnotations | nindent 4 }}
    {{- end}}
    {{- if .Values.serviceAccount.annotations }}
    {{- toYaml .Values.serviceAccount.annotations | nindent 4 }}
    {{- end}}
  {{- end }}
  labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
    {{- if .Values.serviceAccount.labels }}
    {{- include "sealed-secrets.render" ( dict "value" .Values.serviceAccount.labels "context" $) | nindent 4 }}
    {{- end }}
{{ end }}
