{{- if .Values.clusterConfig.argo.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: plausible-analytics
  namespace: argocd
spec:
  destination:
    namespace: plausible
    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: plausible.yaml.gotmpl
  project: aux
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: aux
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
    {{- if .Values.plausible.autosync }}
    automated:
      prune: true
      selfHeal: true
    {{- end }}
  ignoreDifferences:
    - kind: Secret
      name: plausible-analytics
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
{{- end }}
