apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "opendmarc.fullname" . }}
  labels:
    {{- include "opendmarc.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "opendmarc.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "opendmarc.selectorLabels" . | nindent 8 }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ include "opendmarc.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: opendmarc
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.opendmarc.image.repository }}:{{ .Values.opendmarc.image.tag }}"
          imagePullPolicy: {{ .Values.opendmarc.image.pullPolicy }}
          ports:
            - name: dmarc
              containerPort: 8893
              protocol: TCP
          volumeMounts:
            {{- range $key, $val := .Values.opendmarc.configmaps }}
            - name: opendmarc-{{ $key }}
              mountPath: "/etc/opendmarc/{{ $key }}.conf"
              subPath: {{ $key }}
            {{- end }}
      volumes:
      - name: data
        {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ if .Values.persistence.existingClaim }}{{ .Values.persistence.existingClaim }}{{- end }}
        {{- else }}
        emptyDir: {}
        {{- end }}
      {{- range $key, $val := .Values.opendmarc.configmaps }}
      - name: opendmarc-{{ $key }}
        configMap:
          name: opendmarc-{{ $key }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}