apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: serverless-svc
spec:
  generators:
    - list:
        elements:
          - env: nightly
            cluster: dev-base-us-west-2
          - env: staging
            cluster: staging-base-us-west-2
            paused: "true"   # Temporarily pause staging auto-sync for testing; remove this line when done
          - env: prod
            cluster: prod-base-us-west-2
  template:
    metadata:
      name: "{{env}}-serverless-svc"
    spec:
      project: default # Use default project as a start
      source:
        repoURL: https://github.com/tidbcloud/app-delivery.git
        targetRevision: HEAD
        path: "serverless-svc/envs/{{env}}"
      destination:
        name: "{{cluster}}"
        namespace: "{{env}}-ms"
      syncPolicy:
        automated:
          selfHeal: true
          prune: true
        syncOptions:
          - CreateNamespace=true
          - PruneLast=true
        retry:
          limit: 5
          backoff:
            duration: 5s
            factor: 2
            maxDuration: 3m
  # For envs marked with paused (currently staging only), drop `automated` to stop
  # auto-sync/selfHeal/prune. templatePatch is always rendered with Go templating,
  # independent of the goTemplate flag. Remove this block together with the `paused`
  # line above once testing is complete.
  templatePatch: |
    {{- if eq .paused "true" }}
    spec:
      syncPolicy:
        automated: null
    {{- end }}
