apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mailu-helm.fullname" . }}-imap
  labels:
    component: imap
    {{- include "mailu-helm.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      component: imap
      {{- include "mailu-helm.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        component: imap
        {{- 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: mail
          {{- .Values.volumes.mail | nindent 10 }}
      containers:
        - name: imap
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "mailu/dovecot:{{ .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: imap-auth
              containerPort: 2102
              protocol: "TCP"
            - name: imap-transport
              containerPort: 2525
              protocol: "TCP"
            - name: pop3
              containerPort: 110
              protocol: "TCP"
            - name: imap-default
              containerPort: 143
              protocol: "TCP"
            - name: sieve
              containerPort: 4190
              protocol: "TCP"
          resources:
            {{- toYaml .Values.imap.resources | nindent 12 }}
          volumeMounts:
            - name: data
              mountPath: "/data"
            - name: mail
              mountPath: "/mail"
          startupProbe:
            exec:
              command:
                - sh
                - -c
                - 'echo QUIT|nc localhost 110|grep "Dovecot ready."'
            periodSeconds:  10
            failureThreshold: 30
            timeoutSeconds: 5
          livenessProbe:
            exec:
              command:
                - sh
                - -c
                - 'echo QUIT|nc localhost 110|grep "Dovecot ready."'
            periodSeconds:  10
            failureThreshold: 3
            timeoutSeconds: 5
          readinessProbe:
            exec:
              command:
                - sh
                - -c
                - 'echo QUIT|nc localhost 110|grep "Dovecot ready."'
            periodSeconds:  10
            failureThreshold: 1
            timeoutSeconds: 5
