apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mailu-helm.fullname" . }}-smtp
  labels:
    component: smtp
    {{- include "mailu-helm.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      component: smtp
      {{- include "mailu-helm.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        component: smtp
        {{- include "mailu-helm.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      volumes:
        - name: data
          {{- .Values.volumes.data | nindent 10 }}
        - name: certs
          secret:
            secretName: {{ include "mailu-helm.fullname" . }}-tls
        - name: config
          configMap:
            name: {{ include "mailu-helm.fullname" . }}-smtp
      containers:
        - name: smtp
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "mailu/postfix:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          envFrom:
            - configMapRef:
                name: {{ include "mailu-helm.fullname" . }}
            - secretRef:
                name: {{ include "mailu-helm.fullname" . }}
          ports:
          - name: smtp
            containerPort: 25
            protocol: "TCP"
          - name: smtp-ssl
            containerPort: 465
            protocol: "TCP"
          - name: smtp-starttls
            containerPort: 587
            protocol: "TCP"
          - name: smtp-proxy
            containerPort: 10024
            protocol: "TCP"
          - name: smtp-auth
            containerPort: 10025
            protocol: "TCP"
          resources:
            {{- toYaml .Values.smtp.resources | nindent 12 }}
          volumeMounts:
            - name: data
              mountPath: "/data"
            - name: certs
              mountPath: "/certs"
            - name: config
              mountPath: "/overrides"
          startupProbe:
            exec:
              command:
                - sh
                - -c
                - 'echo QUIT|nc localhost 25|grep "220 .* ESMTP Postfix"'
            periodSeconds:  10
            failureThreshold: 30
            timeoutSeconds: 5
          livenessProbe:
            exec:
              command:
                - sh
                - -c
                - 'echo QUIT|nc localhost 25|grep "220 .* ESMTP Postfix"'
            periodSeconds:  10
            failureThreshold: 3
            timeoutSeconds: 5
          readinessProbe:
            exec:
              command:
                - sh
                - -c
                - 'echo QUIT|nc localhost 25|grep "220 .* ESMTP Postfix"'
            periodSeconds:  10
            failureThreshold: 1
            timeoutSeconds: 5
