- PreSync — run before the main sync step.
- Sync — the normal synchronization of non-hooked resources.
- PostSync — run after a successful sync.
- SyncFail — run when a sync fails.
- PreDelete / PostDelete — run during deletion lifecycles.
| Hook Phase | When it runs | Typical use case |
|---|---|---|
| PreSync | Before regular resources are applied | Run migrations or prepare state required by other resources |
| Sync | Regular resource application phase | Deploy Deployments, Services, etc. |
| PostSync | After a successful sync | Run cleanup tasks or post-deploy verification |
| SyncFail | After a sync failure | Rollback-related tasks or notifications |
| PreDelete / PostDelete | During resource deletion | Cleanup external state or revoke credentials |

- An Nginx Deployment
- A database migration Job
- A cleanup Job
| Field | Value (example) |
|---|---|
| Application name | syncHooks0 |
| Project | default |
| Sync policy | Automatic |
| Auto-create namespace | Enabled |
| Repository URL | (my repo URL) |
| Path | ./synchronization/hooks |
| Destination cluster | https://kubernetes.default.svc |
| Destination namespace | sync-hooks-0 |

- Run the migration Job first.
- When the migration Job completes successfully, create the Nginx Deployment.
- After the Deployment is ready, run the cleanup Job.
- Mark the migration Job as PreSync:
- Leave the Nginx Deployment as a regular resource (applied during Sync).
- Mark the cleanup Job as PostSync:
By default, Argo CD applies resources concurrently. Use hook annotations (for example,
argocd.argoproj.io/hook: PreSync or PostSync) to enforce ordering for tasks like database migrations or cleanup. For full details and advanced hook lifecycle options, refer to the Argo CD Sync Hooks documentation: https://argo-cd.readthedocs.io/en/stable/user-guide/hooks/