apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mail-relay.fullname" . }}
  labels:
    {{- include "mail-relay.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "mail-relay.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "mail-relay.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "mail-relay.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: smtp
              containerPort: 587
              protocol: TCP
          env:
            - name: ALLOWED_SENDER_DOMAINS
              value: {{ .Values.env.ALLOWED_SENDER_DOMAINS | quote }}
            - name: HOSTNAME
              value: {{ .Values.env.HOSTNAME | quote  }}
            - name: TZ
              value: {{ .Values.env.TZ | quote }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
          - name: config-volume
            mountPath: /etc/postfix/transport
            subPath: transport
          - name: config-volume
            mountPath: /etc/postfix/sasl_passwd
            subPath: sasl_passwd
          - name: config-volume
            mountPath: /docker-init.db/update_transport.sh
            subPath: update_transport.sh
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
      - name: config-volume
        configMap:
          name: {{ include "mail-relay.fullname" . }}

