apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "nginx-ldapauth-proxy.fullname" . }}
  labels:
    app: {{ template "nginx-ldapauth-proxy.name" . }}
    chart: {{ template "nginx-ldapauth-proxy.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  selector:
    matchLabels:
      app: {{ template "nginx-ldapauth-proxy.name" . }}
      release: {{ .Release.Name }}
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        app: {{ template "nginx-ldapauth-proxy.name" . }}
        release: {{ .Release.Name }}
      annotations:
        checksum/config: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }}
    spec:
    {{- if .Values.image.pullSecrets }}
      {{- range $pullSecret := .Values.image.pullSecrets }}
      imagePullSecrets:
        - name: {{ $pullSecret }}
      {{- end }}
    {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if and .Values.proxy.ldapHost .Values.secrets.ldapBindPassword }}
          env:
            - name: LDAP_BIND_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ template "nginx-ldapauth-proxy.fullname" . }}
                  key: ldapBindPassword
{{- end }}
          ports:
            - containerPort: {{ .Values.service.internalPort }}
          livenessProbe:
            httpGet:
              path: /_ping
              port: {{ .Values.service.internalPort }}
          readinessProbe:
            httpGet:
              path: /_ping
              port: {{ .Values.service.internalPort }}
          volumeMounts:
            - mountPath: /etc/nginx/nginx.conf
              name: config
              subPath: nginx.conf
          resources:
{{ toYaml .Values.resources | indent 12 }}
      volumes:
        - name: config
          configMap:
            name: {{ template "nginx-ldapauth-proxy.fullname" . }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
