{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.auth.enabled (not .Values.auth.existingSecret) .Values.createAdminTokenJob.enabled (ne .Values.objectStore "memory") .Values.createAdminTokenJob.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ template "influxdb.createAdminTokenJob.serviceAccountName" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" (dict "customLabels" .Values.commonLabels "context" .) | nindent 4 }}
    app.kubernetes.io/part-of: influxdb
    app.kubernetes.io/component: create-admin-token
  {{- $defaultAnnotations := ternary (dict "helm.sh/hook" "pre-install" "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded") (dict) .Values.useHelmHooks }}
  {{- $annotations := include "common.tplvalues.merge" (dict "values" (list .Values.createAdminTokenJob.serviceAccount.annotations .Values.commonAnnotations $defaultAnnotations) "context" .) }}
  annotations: {{- include "common.tplvalues.render" (dict "value" $annotations "context" .) | nindent 4 }}
automountServiceAccountToken: {{ .Values.createAdminTokenJob.serviceAccount.automountServiceAccountToken }}
{{- end }}
