{{- range $key, $spec := .Values }}
{{- if and (ne $key "global") (ne $key "enabled") }}
{{- if $spec.enabled }}
apiVersion: v1
kind: ServiceAccount
{{- if $.Values.global.imagePullSecrets }}
imagePullSecrets:
{{- range $.Values.global.imagePullSecrets }}
  - name: {{ . }}
{{- end }}
{{- end }}
metadata:
  name: {{ $key }}-service-account
  namespace: {{ $spec.namespace | default $.Release.Namespace }}
  labels:
    app: {{ $spec.labels.istio }}
    chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
    heritage: {{ $.Release.Service }}
    release: {{ $.Release.Name }}
---
{{- end }}
{{- end }}
{{- end }}
