{{- $name := include "name" . -}}
{{- $chart := include "chart" . -}}

{{- range $service, $val := $.Values.services }}
{{- if and $val.serviceAccount (not $val.disabled) }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ $val.serviceAccount }}
  namespace: {{ $.Values.namespace }}
  annotations:
    iam.gke.io/gcp-service-account: "{{$val.serviceAccount }}@{{ $.Values.projectId}}.iam.gserviceaccount.com"
  labels:
    app.kubernetes.io/instance: {{ $.Release.Name }}
    app.kubernetes.io/managed-by: {{ $.Release.Service }}
    app.kubernetes.io/version: {{ $.Values.version | quote }}
    app.kubernetes.io/component: {{ $service }}
    helm.sh/chart: {{ $chart }}
---
{{ end }}
{{- end }}
