{{ if .Values.clusterConfig.argo.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: {{ .Values.atlantis.env }}-atlantis
  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: {{ .Values.atlantis.env }}-atlantis
    server: https://kubernetes.default.svc
  project: atlantis
  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: {{ .Values.atlantis.env }}
      - name: HELMFILE_FILE_PATH
        value: atlantis.yaml.gotmpl
  {{- if ne .Values.atlantis.env "beta" }}
  - repoURL: https://charts.bitnami.com/bitnami
    targetRevision: 20.1.7
    chart: redis
    helm:
      valueFiles:
      - $values/values/atlantis/values/redis-{{ .Values.atlantis.env }}.yaml
  {{- end }}
  - repoURL: https://git.oceanbox.io/platform/manifests.git
    targetRevision: main
    ref: values
  ignoreDifferences:
    - kind: Secret
      name: beta-atlantis-db-superuser
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
    - kind: Secret
      name: azure-keyvault
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
    - kind: Secret
      name: dapr-api-token
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
    - kind: Secret
      name: {{ .Values.atlantis.env }}-atlantis-rabbitmq
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
    - kind: Secret
      name: prod-atlantis-db-replication
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
    - kind: Secret
      name: prod-atlantis-db-ca
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
    - kind: Secret
      name: slurm-access-token
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
  syncPolicy:
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
    {{- if .Values.atlantis.autosync }}
    automated:
      prune: true
      selfHeal: false
    {{- end }}
{{- end }}
