Sync Waves order resources within a given hook/phase (e.g., PreSync or Sync). Wave numbers are only compared among resources in the same phase — a PreSync with wave -1 runs before a Sync with wave -1.
How sync waves work (quick summary)
- Annotation key: argocd.argoproj.io/sync-wave
- Scope: Compared only among resources in the same hook/phase.
- Order: Lower wave numbers are applied before higher numbers.
- Parallelism: Resources sharing the same wave number are applied in parallel.
Example scenario
Goal:- Run database migrations first,
- Create application Namespace,
- Deploy front-end, then database,
- Run a post-deploy cleanup/verification task.
- Use PreSync hooks for preparatory jobs (migrations, checks).
- Use the Sync phase with waves to order Namespace → front-end → database.
- Use a PostSync hook for final cleanup or verification.
Step-by-step sync flow (how Argo CD interprets this)
- PreSync phase runs first. Within PreSync:
- wave -2 job runs first (e.g., schema migration).
- wave -1 job runs next (e.g., data verification). If any PreSync hook fails, the entire sync is considered failed.
- Sync phase begins only after all PreSync hooks succeed. Within Sync:
- Create the Namespace (wave -1) so it exists before deployments are created.
- Create the front-end Deployment and Service (both wave 0) in parallel, then wait for them to become healthy.
- Create the PostgreSQL Deployment and Service (both wave 1) in parallel, then wait for them to become healthy.
- PostSync phase begins only after all Sync-phase resources are healthy. Run the cleanup job (PostSync hook) — this could run integration tests, send notifications, or perform final cleanup.
Warning about failure behavior
If a hook (for example, a PreSync job) fails, Argo CD will mark the sync as unsuccessful. Make hooks idempotent and configure appropriate timeouts and retries to avoid spurious failures.
Example manifests (annotations demonstrate hooks and sync-wave usage)
PreSync jobs (migrations)Best practices
- Make hooks idempotent so retries or re-runs are safe.
- Use negative waves for preparatory resources (e.g., -2, -1), zero for primary resources, and positive waves for resources that should be created last.
- Group unrelated resources that can be applied in parallel with the same wave.
- Add readiness checks (liveness/readiness probes) to Deployments so Argo CD waits for true health before proceeding to the next wave.
- Keep wave numbers sparse enough that you can insert intermediate steps later (e.g., use -10, -5, 0, 5, 10).
Quick reference table
| Concept | Use case | Example annotation |
|---|---|---|
| PreSync hook | Run DB migrations or checks before any resources are created | argocd.argoproj.io/hook: PreSync |
| Sync phase | Apply the core resources (Namespace, Deployments, Services) | argocd.argoproj.io/sync-wave: '0' |
| PostSync hook | Run verification or cleanup after resources are healthy | argocd.argoproj.io/hook: PostSync |
| Sync wave | Order resources inside a phase (lower runs first, equal runs in parallel) | argocd.argoproj.io/sync-wave: '-1' |
Links and references
- Argo CD documentation: https://argo-cd.readthedocs.io/
- GitOps with Argo CD (course): https://learn.kodekloud.com/user/courses/gitops-with-argocd/
- Kubernetes docs: https://kubernetes.io/docs/
Summary
- Hooks (PreSync, Sync, PostSync) control macro phases of a sync.
- Sync waves control ordering inside those phases: lower numbers run first; identical numbers run together.
- Use PreSync for migrations and checks, Sync waves for ordered resource creation, and PostSync for verification or cleanup.
- Combining hooks and sync waves helps avoid race conditions and ensures reliable application rollouts.