{{- if .Values.nfs_provisioner.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: nfs-provisioner
  namespace: argocd
spec:
  destination:
    namespace: kube-system
    server: 'https://kubernetes.default.svc'
  source:
  #- repoURL: {{ .Values.cluster_config.manifests }}
  #  path: {{ .Values.cluster_config.policies }}/nfs-provisioner
  #  targetRevision: HEAD
    repoURL: 'https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/'
    targetRevision: {{ .Values.nfs_provisioner.version }}
    chart: nfs-subdir-external-provisioner
    helm:
      values: |
        nfs:
          server: {{ .Values.cluster_config.fileserver }}
          path: /{{ default (.Values.cluster_config.cluster) .Values.nfs_provisioner.path }}
          mountOptions:
            - nfsvers=4.2
            {{- range .Values.nfs_provisioner.extraMountOpts }}
            - {{ . }}
            {{- end }}
        storageClass:
          defaultClass: {{ .Values.nfs_provisioner.defaultClass}}
          name: managed-nfs-storage
          archiveOnDelete: {{ .Values.nfs_provisioner.archiveOnDelete }}
        tolerations:
           - key: unschedulable
             operator: Exists
             effect: NoSchedule
  project: sys
  syncPolicy:
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
    {{- if .Values.nfs_provisioner.autosync }}
    automated:
      prune: true
      # selfHeal: false
    {{- end }}
{{- end }}
