{{- if .Values.clusterConfig.argo.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: prometheus
  namespace: argocd
spec:
  destination:
    namespace: prometheus
    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: prometheus.yaml.gotmpl
  project: sys
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: sys
    syncOptions:
    - ServerSideApply=true
    - CreateNamespace=true
    - ApplyOutOfSyncOnly=true
    {{- if .Values.prometheus.autosync }}
    automated:
      prune: true
      # selfHeal: false
    {{- end }}
  ignoreDifferences:
    - group: apps
      kind: Deployment
      jqPathExpressions:
        - '.spec.template.spec.containers[]?.resources'
    - group: monitoring.coreos.com
      kind: ServiceMonitor
      jqPathExpressions:
        - '.spec.endpoints[]?.relabelings'
    - group: admissionregistration.k8s.io
      kind: MutatingWebhookConfiguration
      jqPathExpressions:
        - '.webhooks[]?.clientConfig.caBundle'
    - group: admissionregistration.k8s.io
      kind: ValidatingWebhookConfiguration
      jqPathExpressions:
        - '.webhooks[]?.clientConfig.caBundle'
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: prometheus-crd
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-wave: "-1"
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: prometheus
    server: 'https://kubernetes.default.svc'
  source:
    repoURL: 'https://prometheus-community.github.io/helm-charts'
    targetRevision: '27.0.0'
    chart: prometheus-operator-crds
  project: sys
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: sys
    automated: {}
    syncOptions:
      - ServerSideApply=true
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
{{- end }}
