{{- if and .Values.forwarder.serviceAccount.create .Values.forwarder.enabled }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "fluentd.forwarder.serviceAccountName" . }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: forwarder
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  annotations:
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
    {{- if .Values.forwarder.serviceAccount.annotations }}
    {{- include "common.tplvalues.render" (dict "value" .Values.forwarder.serviceAccount.annotations "context" $) | nindent 4 }}
    {{- end }}
automountServiceAccountToken: {{ .Values.forwarder.serviceAccount.automountServiceAccountToken }}
{{- end -}}
{{- if and .Values.aggregator.serviceAccount.create .Values.aggregator.enabled }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "fluentd.aggregator.serviceAccountName" . }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: aggregator
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  annotations:
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
    {{- if .Values.aggregator.serviceAccount.annotations }}
    {{- include "common.tplvalues.render" (dict "value" .Values.aggregator.serviceAccount.annotations "context" $) | nindent 4 }}
    {{- end }}
automountServiceAccountToken: {{ .Values.aggregator.serviceAccount.automountServiceAccountToken }}
{{- end -}}
