Resource Hooks
You'll learn how ArgoCD's lifecycle hooks let you run specific tasks before, during, after, or when syncs fail.
What Are Resource Hooks?
Resource hooks are special Kubernetes resources that execute at precise moments in ArgoCD's sync lifecycle. Think of them like event handlers in programming—you're telling ArgoCD "when X happens, also run Y." They let you inject custom logic around your deployments without modifying ArgoCD itself.
The Four Hook Types
ArgoCD provides four hook annotations you add to any Kubernetes resource:
PreSync: Runs before the sync operation starts. Perfect for database migrations, schema updates, or checking prerequisites. Your hook must complete successfully before ArgoCD proceeds.
Sync: Runs during the normal sync phase alongside your regular resources. Use this when timing matters but you need coordination with the main deployment.
PostSync: Executes after all resources sync successfully. Ideal for smoke tests, cache warming, sending notifications, or cleanup tasks that should only happen when deployment succeeds.
SyncFail: Triggers only if the sync operation fails. Use this for rollback procedures, alerting, or diagnostic data collection when things go wrong.
How They Work
You mark a resource as a hook by adding an annotation like:
argocd.argoproj.io/hook: PreSync
ArgoCD recognizes this resource as special—it won't manage it as part of your normal application state. Instead, it runs it at the specified lifecycle point, waits for completion (or failure), then continues based on the result.
Hooks run as Kubernetes Jobs or Pods typically, giving you full scripting power at critical deployment moments.
Key Takeaway: Resource hooks give you surgical control over ArgoCD's sync lifecycle—run migrations before deployment, validate after success, or clean up after failures using PreSync, Sync, PostSync, and SyncFail annotations.