{{ if .Values.rabbitmq_operator.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: rabbitmq-operator
  namespace: argocd
spec:
  destination:
    namespace: rabbitmq
    server: 'https://kubernetes.default.svc'
  sources:
  - repoURL: {{ .Values.cluster_config.manifests }}
    path: {{ .Values.cluster_config.policies }}/rabbitmq
    targetRevision: HEAD
  - repoURL: 'https://charts.bitnami.com/bitnami'
    targetRevision: {{ .Values.rabbitmq_operator.version }}
    chart: rabbitmq-cluster-operator
    helm:
      # NOTE(mrtz): Also add metrics for topology operator?
      values: |
        fullnameOverride: rabbitmq-operator
        additionalArgs: []
        useCertManager: true
        {{ if .Values.rabbitmq_operator.metrics }}
        clusterOperator:
          metrics:
            service:
              enabled: true
            serviceMonitor:
              enabled: true
            podMonitor:
              enabled: true
        {{ end }}
  project: sys
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: sys
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
      - ServerSideApply=true
    {{- if .Values.rabbitmq_operator.version }}
    automated:
      prune: true
      # selfHeal: false
  ignoreDifferences:
    - group: ""
      kind: Secret
      name: rabbitmq-operator-messaging-topology-operator-webhook
      jsonPointers:
      - /data/ca.crt
      - /data/tls.crt
      - /data/tls.key
    - group: admissionregistration.k8s.io
      kind: ValidatingWebhookConfiguration
      jqPathExpressions:
        - '.webhooks[]?.clientConfig.caBundle'
    {{- end }}
{{ end }}
