apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "hlf-couchdb.fullname" . }}
  labels:
{{ include "labels.standard" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ include "hlf-couchdb.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
{{ include "labels.standard" . | indent 8 }}
    spec:
      volumes:
      - name: data
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.existingClaim | default (include "hlf-couchdb.fullname" .) }}
      {{- else }}
        emptyDir: {}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          envFrom:
          - secretRef:
              name: {{ include "hlf-couchdb.fullname" . }}
          volumeMounts:
          - mountPath: /opt/couchdb/data
            name: data
          ports:
            - name: couchdb
              containerPort: 5984
              protocol: TCP
          livenessProbe:
            tcpSocket:
              port: 5984
            initialDelaySeconds: 60
            timeoutSeconds: 5
            failureThreshold: 6
          readinessProbe:
            tcpSocket:
              port: 5984
            initialDelaySeconds: 5
            timeoutSeconds: 3
            periodSeconds: 5
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
