{{ if .Values.clickhouse_operator.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: clickhouse-operator
  namespace: argocd
spec:
  destination:
    namespace: clickhouse
    server: 'https://kubernetes.default.svc'
  sources:
  - repoURL: {{ .Values.cluster_config.manifests }}
    path: {{ .Values.cluster_config.policies }}/clickhouse
    targetRevision: HEAD
  - repoURL: 'https://docs.altinity.com/clickhouse-operator'
    targetRevision: {{ .Values.clickhouse_operator.version }}
    chart: altinity-clickhouse-operator
    helm:
      values: |
        configs:
          files:
            config.yaml:
              watch:
                namespaces: ["analytics", "analytics-production"]
  project: sys
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: sys
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
      - ServerSideApply=true
    {{- if .Values.clickhouse_operator.version }}
    automated:
      # selfHeal: false
      prune: true
    {{- end }}
  ignoreDifferences:
   - group: apps
     kind: Deployment
     jqPathExpressions:
       - .spec.template.spec.containers[].env[].valueFrom.resourceFieldRef.divisor
       - .spec.template.spec.initContainers[].env[].valueFrom.resourceFieldRef.divisor
{{ end }}
