apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "nfs-client-provisioner.fullname" . }}
  labels:
    app: {{ template "nfs-client-provisioner.name" . }}
    chart: {{ template "nfs-client-provisioner.chart" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    type: {{ .Values.strategyType }}
  selector:
    matchLabels:
      app: {{ template "nfs-client-provisioner.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      annotations:
      {{- if and (.Values.tolerations) (semverCompare "<1.6-0" .Capabilities.KubeVersion.GitVersion) }}
        scheduler.alpha.kubernetes.io/tolerations: '{{ toJson .Values.tolerations }}'
      {{- end }}
      labels:
        app: {{ template "nfs-client-provisioner.name" . }}
        release: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ template "nfs-client-provisioner.serviceAccountName" . }}
      {{- 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 }}
      {{- if .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: {{ template "nfs-client-provisioner.provisionerName" . }}
            - name: NFS_SERVER
              value: {{ .Values.nfs.server }}
            - name: NFS_PATH
              value: {{ .Values.nfs.path }}
          {{- with .Values.resources }}
          resources:
{{ toYaml . | indent 12 }}
          {{- end }}
      volumes:
        - name: nfs-client-root
{{- if .Values.buildMode }}
          emptyDir: {}
{{- else if .Values.nfs.mountOptions }}
          persistentVolumeClaim:
            claimName: pvc-{{ template "nfs-client-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 }}