{{- if .Values.stunnelClient.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "postgresql.fullname" . }}-stunnel-client
  labels:
    {{- include "postgresql.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.stunnelClient.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "postgresql.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
      app.kubernetes.io/component: stunnel-client
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "postgresql.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/component: stunnel-client
    spec:
      containers:
        - name: stunnel-client
          image: "{{ .Values.stunnelClient.image.repository }}:{{ .Values.stunnelClient.image.tag }}"
          imagePullPolicy: {{ .Values.stunnelClient.image.pullPolicy }}
          ports:
            - name: postgres
              containerPort: {{ .Values.stunnelClient.service.port }}
              protocol: TCP
          resources:
            {{- toYaml .Values.stunnelClient.resources | nindent 12 }}
          volumeMounts:
            - name: config
              mountPath: /etc/stunnel/stunnel.conf
              subPath: stunnel.conf
      volumes:
        - name: config
          configMap:
            name: {{ include "postgresql.fullname" . }}-stunnel-client
{{- end }}
