This guide continues the Sync Hooks demo and shows how to enforce ordering between jobs and deployments in Argo CD using hook annotations (PreSync, Sync, PostSync), sync waves, and hook-delete-policy. This prevents jobs such as database migrations from running in parallel with deployments and ensures predictable lifecycle and cleanup of hook resources. Why use hooks?Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Ensure a DB migration runs before application Deployments.
- Run notifications or cleanup only after a successful sync.
- Control whether hook resources are retained or removed.
| Annotation | Purpose | Example |
|---|---|---|
argocd.argoproj.io/hook | Defines hook phase: PreSync, Sync, PostSync | argocd.argoproj.io/hook: PreSync |
argocd.argoproj.io/hook-delete-policy | Controls cleanup: HookSucceeded, HookFailed, BeforeHookCreation | argocd.argoproj.io/hook-delete-policy: HookSucceeded |
argocd.argoproj.io/sync-wave | Numeric ordering when using sync waves | argocd.argoproj.io/sync-wave: "5" |
- https://argo-cd.readthedocs.io/en/stable/user-guide/hooks/
- https://argo-cd.readthedocs.io/en/stable/user-guide/sync-waves/

- Purpose: run a migration before any application resources are created.
- Desired lifecycle: the job should be removed after it succeeds.
- Purpose: send a notification after a successful sync.
- Recommended cleanup: delete after success so notifications don’t persist.

- Purpose: run remedial cleanup when a sync completes (e.g., remove temp resources).
- Example policy: delete only on failure to preserve artifacts for troubleshooting.

Hook phases act like guardrails: a PreSync hook must succeed before Sync proceeds; a failing PreSync stops the synchronization and prevents deployments.
- Happy path: PreSync → Sync → PostSync
- If Sync fails, PostSync is typically not executed unless you configure alternative lifecycle behaviors.


- Argo CD creates the PreSync DB migration Job (hook icon shown).
- Argo CD waits for the Job to finish successfully.
- If the Job succeeds, Argo CD proceeds to create normal resources (Deployment, Service, etc.) — the Sync phase.
- If the Sync succeeds, PostSync hooks (cleanup, notifications) execute as configured.
- hook-delete-policy determines whether Jobs remain after success/failure.
- The migration job was created and completed.
- Deployments were created in the Sync phase.
- A cleanup job ran afterwards and, due to the delete policy, the DB migration job was deleted.

| Pattern | When to use | Notes |
|---|---|---|
| PreSync job + HookSucceeded | DB migrations or schema changes that must happen before deployments | Clean up after success to avoid clutter |
| PostSync job + HookSucceeded | Notifications (Slack, PagerDuty) | Use generateName for unique jobs |
| PostSync job + HookFailed | Cleanup only when sync fails | Preserve logs for debugging by keeping failed hooks |
- Use
argocd.argoproj.io/hook: PreSyncto force jobs to run before your main sync. - Use
argocd.argoproj.io/hook: PostSyncfor notifications/cleanup after successful syncs. - Use
argocd.argoproj.io/hook-delete-policyto control retention of hook resources. - Optionally use
argocd.argoproj.io/sync-wavefor finer-grained numeric ordering across many resources.
- Argo CD Hooks — https://argo-cd.readthedocs.io/en/stable/user-guide/hooks/
- Argo CD Sync Waves — https://argo-cd.readthedocs.io/en/stable/user-guide/sync-waves/
- Argo CD CLI docs — https://argo-cd.readthedocs.io/en/stable/user-guide/commands/