apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "nfs-subdir-external-provisioner.fullname" . }}
  labels:
    {{- include "nfs-subdir-external-provisioner.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    type: {{ .Values.strategyType }}
  selector:
    matchLabels:
      {{- include "nfs-subdir-external-provisioner.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
      {{- with .Values.podAnnotations }}
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if and (.Values.tolerations) (semverCompare "<1.6-0" .Capabilities.KubeVersion.GitVersion) }}
        scheduler.alpha.kubernetes.io/tolerations: '{{ toJson .Values.tolerations }}'
      {{- end }}
      labels:
        {{- include "nfs-subdir-external-provisioner.podLabels" . | nindent 8 }}
    spec:
      serviceAccountName: {{ template "nfs-subdir-external-provisioner.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
      {{- end }}
      {{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
      {{- end }}
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName | quote }}
      {{- end }}
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          volumeMounts:
            - name: {{ .Values.nfs.volumeName }}
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: {{ template "nfs-subdir-external-provisioner.provisionerName" . }}
            - name: NFS_SERVER
              value: {{ .Values.nfs.server }}
            - name: NFS_PATH
              value: {{ .Values.nfs.path }}
            {{- if eq .Values.leaderElection.enabled false }}
            - name: ENABLE_LEADER_ELECTION
              value: "false"
            {{- end }}
          {{- with .Values.resources }}
          resources:
{{ toYaml . | indent 12 }}
          {{- end }}
      volumes:
        - name: {{ .Values.nfs.volumeName }}
{{- if .Values.buildMode }}
          emptyDir: {}
{{- else if .Values.nfs.mountOptions }}
          persistentVolumeClaim:
            claimName: pvc-{{ template "nfs-subdir-external-provisioner.fullname" . }}
{{- else }}
          nfs:
            server: {{ .Values.nfs.server }}
            path: {{ .Values.nfs.path }}
{{- end }}
      {{- if and (.Values.tolerations) (semverCompare "^1.6-0" .Capabilities.KubeVersion.GitVersion) }}
      tolerations:
{{ toYaml .Values.tolerations | indent 6 }}
      {{- end }}
