Add a PostSync hook Job that runs the tests; if the Job fails, the sync is marked failed, signaling a bad deployment (and triggering SyncFail hooks/notifications). Combined with automated rollback strategies or alerting, this gates the deployment on test success within the GitOps flow.
Hooks are typically generated with unique names (e.g., using generateName) or cleaned up via BeforeHookCreation so a new sync doesn't collide with a leftover from a prior run. Because Jobs are immutable in key fields, reusing a fixed name without deletion causes apply errors, so deletion policies or unique names are important.
Jobs are the most common (run to completion for migrations, tests, seeds), and Pods for simple one-off tasks. Any Kubernetes resource can technically carry hook annotations, but run-to-completion workloads (Jobs) fit hook semantics best because ArgoCD tracks their success/failure to gate the sync.
Real-world example
Migrations, backups, and smoke tests are all implemented as hook Jobs that ArgoCD monitors to completion.
Likely follow-ups
Why are Jobs ideal for hooks? | Can any resource be a hook?
Ordering across separate Applications isn't governed by a single sync's waves/hooks; you coordinate via the parent (App of Apps) sync waves on the child Application resources, or by splitting concerns so prerequisites are their own app synced first. Within one app, waves/hooks order resources; across apps, order the Application CRs themselves.
Example
# Parent app annotates child Applications with sync-wave to order them
Real-world example
The parent app syncs the 'infra' child Application (wave 0) before the 'workloads' child (wave 1) so shared CRDs exist first.
Likely follow-ups
Do waves span multiple Applications? | How do you order child apps?
Add the annotation argocd.argoproj.io/sync-wave with an integer string value on the resource metadata. Lower numbers apply first. Resources without the annotation default to wave 0.
After applying a wave, ArgoCD waits for those resources to become Healthy before starting the next wave, subject to timeouts. There's also a short delay (configurable) between waves. If a wave's resources never become Healthy, later waves won't proceed and the sync stalls.
Real-world example
The next wave doesn't start until the database in the current wave reports Healthy.
Likely follow-ups
What if a wave never becomes Healthy? | Is the inter-wave delay configurable?
PreSync hooks run before the main resources apply, ideal for preparation tasks that must succeed first: database schema migrations, provisioning, or backups. If a PreSync hook fails, the sync fails and the new version isn't rolled out.
PostSync hooks run after all resources are applied and Healthy—used for smoke tests, cache warming, notifications, or registering the deployment. A failing PostSync hook marks the sync failed, signaling the release didn't pass its post-checks.
A SyncFail hook runs only when a sync operation fails, used for cleanup, rollback of partial changes, or alerting. It lets you react to failed deployments within the sync lifecycle rather than relying solely on external monitoring.
The hook-delete-policy annotation accepts HookSucceeded (delete after success), HookFailed (delete after failure), and BeforeHookCreation (delete the prior hook before creating a new one). They keep completed hook resources from accumulating and manage reruns.