{{- if ne .Values.efsProvisioner.efsFileSystemId "fs-12345678" }}
{{/*
The `efsFileSystemId` value must be set.

The above `if` condition also prevents the helm integration tests from failing.
Given that the helm test infrastructure does not have access to valid
AWS EFS resources, a deployment that references the example `fs-12345678`
creates pods that will never enter a clean, running state.

Omitting the deployment hacks around this limitation.
*/}}
kind: Deployment
apiVersion: apps/v1beta2
metadata:
  name: {{ template "efs-provisioner.fullname" . }}
  labels:
    app: {{ template "efs-provisioner.name" . }}
    env: {{ .Values.global.deployEnv }}
    chart: {{ template "efs-provisioner.chartname" . }}
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
  annotations:
{{ toYaml .Values.annotations | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "efs-provisioner.name" . }}
      release: "{{ .Release.Name }}"
  revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
  strategy:
    type: Recreate
  template:
    metadata:
    {{- if .Values.podAnnotations }}
      annotations:
{{ toYaml .Values.podAnnotations | indent 8}}
    {{- end }}
      labels:
        app: {{ template "efs-provisioner.name" . }}
        release: "{{ .Release.Name }}"
      annotations:
{{ toYaml .Values.annotations | indent 8 }}
    spec:
      serviceAccount: {{ template "efs-provisioner.serviceAccountName" . }}
      {{- if .Values.priorityClassName }}
      priorityClassName: "{{ .Values.priorityClassName }}"
      {{- end }}
      containers:
      - name: {{ template "efs-provisioner.fullname" . }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
        - name: FILE_SYSTEM_ID
          value: {{ .Values.efsProvisioner.efsFileSystemId }}
        - name: AWS_REGION
          value: {{ .Values.efsProvisioner.awsRegion }}
        - name: PROVISIONER_NAME
          value: {{ .Values.efsProvisioner.provisionerName }}
        volumeMounts:
        - name: pv-volume
          subPath: {{ (trimPrefix "/" .Values.efsProvisioner.path) }}
          mountPath: /persistentvolumes
      {{- if ne .Values.efsProvisioner.path "/" }}
      initContainers:
      - name: "init-path"
        image: {{ .Values.busyboxImage.repository}}:{{ .Values.busyboxImage.tag}}
        imagePullPolicy: {{ .Values.busyboxImage.pullPolicy }}
        command: [ "sh", "-c", "mkdir -p /efs-vol-root/{{ (trimPrefix "/" .Values.efsProvisioner.path) }}" ]
        volumeMounts:
        - name: pv-volume
          mountPath: /efs-vol-root
      {{- end }}
      volumes:
      - name: pv-volume
        nfs:
          server: {{ .Values.efsProvisioner.efsFileSystemId }}.efs.{{ .Values.efsProvisioner.awsRegion }}.amazonaws.com
          path: /
{{- end }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
    {{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
    {{- end }}
