{{- if .Values.clusterConfig.argo.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: dapr
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
    argocd.argoproj.io/compare-options: ServerSideDiff=true
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: dapr-system
    server: 'https://kubernetes.default.svc'
  sources:
  - repoURL: {{ .Values.clusterConfig.manifests }}
    targetRevision: HEAD
    path: helmfile.d
    plugin:
      name: helmfile-cmp
      env:
      - name: CLUSTER_NAME
        value: {{ .Values.clusterConfig.cluster }}
      - name: HELMFILE_ENVIRONMENT
        value: default
      - name: HELMFILE_FILE_PATH
        value: dapr.yaml.gotmpl
  - repoURL: https://dapr.github.io/helm-charts
    targetRevision: 1.16.9
    chart: dapr
    helm:
      valueFiles:
        - $values/values/dapr/values/dapr.yaml
  - repoURL: https://dapr.github.io/helm-charts
    targetRevision: 0.15.0
    chart: dapr-dashboard
    helm:
      valueFiles:
        - $values/values/dapr/values/dashboard.yaml
  - repoURL: {{ .Values.clusterConfig.manifests }}
    targetRevision: main
    ref: values
  project: sys
  ignoreDifferences:
  - kind: Secret
    jsonPointers:
    - /metadata/labels
    - /data
  - group: apiextensions.k8s.io
    kind: CustomResourceDefinition
    jsonPointers:
      - /spec/conversion/webhook/clientConfig/service/namespace
      - /spec/conversion/webhook/clientConfig/caBundle
  - group: admissionregistration.k8s.io
    kind: MutatingWebhookConfiguration
    jsonPointers:
    - /webhooks/0/clientConfig/caBundle
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: sys
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
      - ServerSideApply=true
    {{- if .Values.dapr.autosync }}
    automated:
      prune: true
      # selfHeal: false
    {{- end }}
{{- end }}
