apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: openmetadata
  namespace: platform
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
    - list:
        elements:
          # sync-wave 0: dependencies (MySQL, OpenSearch, Airflow) 먼저 배포
          - name: openmetadata-dependencies
            chartPath: manifests/helm/openmetadata-dependencies/1.12.1  # chart repo 내 경로
            valuesPath: openmetadata/dependencies-values.yaml # values repo 내 경로
            syncWave: "0"
          # sync-wave 1: 본체 배포
          - name: openmetadata
            chartPath: manifests/helm/openmetadata/1.12.1               # chart repo 내 경로
            valuesPath: openmetadata/openmeta-values.yaml              # values repo 내 경로
            syncWave: "1"
  template:
    metadata:
      name: "{{ .name }}"
      namespace: argocd
      annotations:
        argocd.argoproj.io/sync-wave: "{{ .syncWave }}"
    spec:
      # project: <ARGOCD_PROJECT>
      project: default
      sources:
        # Source 1: Helm chart를 관리하는 Git repo
        - repoURL: https://gitea.example.org/dip/catalog-test
          targetRevision: main
          path: "{{ .chartPath }}"
          helm:
            valueFiles:
              - $values/{{ .valuesPath }}  # Source 2의 values 파일 참조
        # Source 2: Custom values를 관리하는 Git repo
        - repoURL: https://gitea.example.org/dip/values-test
          targetRevision: main
          ref: values                 # $values 변수로 Source 1에서 참조
      destination:
        #server: <DESTINATION_SERVER>
        server: https://kubernetes.default.svc
        #namespace: <TARGET_NAMESPACE>
        namespace: open-metadata
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
          - CreateNamespace=true
          - ServerSideApply=true
        retry:
          limit: 5
          backoff:
            duration: 10s
            factor: 2
            maxDuration: 3m