---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postfix
  namespace: mailserver
spec:
  selector:
    matchLabels:
      app: mailserver
      tier: postfix
  template:
    metadata:
      labels:
        app: mailserver
        tier: postfix
        logType: postfix
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: mailserver/environment
                  operator: In
                  values:
                    - mailserver
      containers:
        - name: postfix
          image: technicalguru/mailserver-postfix
          imagePullPolicy: IfNotPresent
          env:
            - name: PF_DB_HOST
              value: "mariadb"
            - name: PF_DB_NAME
              value: "mail"
            - name: PF_DB_USER
              value: "postfix"
            - name: PF_DB_PASS
              value: "postfix"  # TODO: move me to a secret
            - name: PF_SETUP_PASS
              valueFrom:
                secretKeyRef:
                  name: mariadb-secrets
                  key: root-password
            - name: PF_MYDOMAIN
              value: "mail.seccomp.sk"
            - name: PF_MYHOSTNAME
              value: "seccomp-mailserver"
            - name: PF_AMAVIS_SERVICE_NAME
              # value is complete DNS name: "<service-name>.<namespace-name>.svc.cluster.local"
              value: "amavis.mailserver.svc.cluster.local"
            - name: PF_AMAVIS_SERVICE_PORT
              value: "10024"
            - name: PF_TLS_CERT_FILE
              value: "/var/certificate/tls.crt"
            - name: PF_TLS_KEY_FILE
              value: "/var/certificate/tls.key"
            - name: PF_TLS_CAFILE
              value: "/var/certificate/tls.chain"
            - name: PF_TLS_CAPATH
              value: "/etc/ssl/certs"
            - name: PF_TLS_ADMIN_EMAIL
              value: "postmaster@mail.seccomp.sk"
          ports:
            - containerPort: 25
              name: smtp
            - containerPort: 110
              name: pop3
            - containerPort: 143
              name: imap
            - containerPort: 587
              name: submission
            - containerPort: 993
              name: imaps
            - containerPort: 995
              name: pop3s
            - containerPort: 10025
              name: checked
          volumeMounts:
            - name: mailboxes
              mountPath: /var/vmail
            - name: spool
              mountPath: /var/spool/postfix
            - name: certificate
              mountPath: /var/certificate
      volumes:
        - name: mailboxes
          persistentVolumeClaim:
            claimName: postfix-mailboxes-claim
        - name: spool
          persistentVolumeClaim:
            claimName: postfix-spool-claim
        - name: certificate
          secret:
            secretName: tls-certificate
