apiVersion: apps/v1
kind: Deployment
metadata:
  name: maddy
  namespace: {{ .Release.Namespace }}
spec:
  selector:
    matchLabels:
      app: maddy
  replicas: 1
  template:
    metadata:
      labels:
        app: maddy
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/config.yaml") . | sha256sum }}
    spec:
      volumes:
      - name: config
        configMap:
          name: maddy
      - name: certs
        secret:
          secretName: cert-{{ .Values.domains.primary.mx }}
      - name: data
        persistentVolumeClaim:
          claimName: data
      containers:
      - name: maddy
        image: giolekva/maddy-auth-smtp:v0.4.4
        imagePullPolicy: Always
        ports:
        - name: imap
          containerPort: 143
          protocol: TCP
        - name: imaps
          containerPort: 993
          protocol: TCP
        - name: smtp
          containerPort: 25
          protocol: TCP
        - name: smtps
          containerPort: 465
          protocol: TCP
        - name: submission
          containerPort: 587
          protocol: TCP
        command:
        - maddy
        - -config
        - /etc/maddy/config/maddy.conf
        volumeMounts:
        - name: config
          mountPath: /etc/maddy/config
        - name: certs
          mountPath: /etc/maddy/certs
        - name: data
          mountPath: /var/lib/maddy
---
apiVersion: v1
kind: Service
metadata:
  name: maddy
  namespace: {{ .Release.Namespace }}
spec:
  type: LoadBalancer
  externalTrafficPolicy: Local
  selector:
    app: maddy
  ports:
    - name: imap
      port: 143
      protocol: TCP
    - name: imaps
      port: 993
      protocol: TCP
    - name: smtp
      port: 25
      protocol: TCP
    - name: smtps
      port: 465
      protocol: TCP
    - name: submission
      port: 587
      protocol: TCP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data
  namespace: {{ .Release.Namespace }}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: {{ .Values.persistence.size }}
