Skip to main content
Resource hooks allow you to run Kubernetes Jobs, Pods, or other resources at specific points during the sync lifecycle. They’re essential for tasks like database migrations, smoke tests, and notifications.

Available Hook Types

Basic Hook Configuration

Add the hook annotation to any Kubernetes resource:
Hooks can be any Kubernetes resource, but Jobs and Pods are most common.

PreSync Hooks

Run before the main sync operation. Ideal for migrations and prerequisites.

Database Migration Example

Pre-Flight Check Example

If a PreSync hook fails, the entire sync operation stops. Design hooks to be idempotent and have appropriate retry logic.

Sync Hooks

Run at the same time as regular manifests, after PreSync hooks succeed.

PostSync Hooks

Run after all resources are synced and healthy. Perfect for validation and notifications.

Smoke Test Example

Slack Notification Example

Data Seeding Example

SyncFail Hooks

Run when the sync operation fails. Useful for cleanup and notifications.
SyncFail hooks run even if PreSync or Sync hooks fail. If SyncFail hooks fail, Argo CD marks the operation as failed but takes no special action.

PreDelete Hooks

Run before Application deletion. Only triggers on Application deletion, not during normal sync with pruning.

Database Backup Example

External Resource Cleanup

If a PreDelete hook fails, Application deletion is blocked. The Application enters a DeletionError state and resources remain in the cluster.
Recovering from failed PreDelete hooks:
  1. Fix the hook in Git and Argo CD will retry on next reconciliation
  2. Or manually delete the failing hook resource: kubectl delete job <hook-name>

PostDelete Hooks

Run after all Application resources are deleted. Available in Argo CD v2.10+.

Audit Log Example

Skip Hook

Prevent resources from being applied:
Useful for disabling Helm hooks that conflict with Argo CD, such as ingress-nginx admission webhooks.

Hook Deletion Policies

Control when hooks are cleaned up:
If no policy is specified, BeforeHookCreation is used by default.

Combining Deletion Policies

This deletes the hook whether it succeeds or fails.

Combining Hooks with Sync Waves

Use sync waves to order hooks within the same phase:

Multiple Hooks

A resource can have multiple hook types:

Advanced Patterns

Conditional Hook with Init Container

Hook with Service Account

For hooks that need Kubernetes API access:

Hook Best Practices

Idempotent Hooks

Design hooks to be safely re-runnable in case of failures

Set Timeouts

Use activeDeadlineSeconds to prevent hung jobs

Appropriate Backoff

Set reasonable backoffLimit for retries

Clean Up

Always use deletion policies to avoid resource accumulation

Troubleshooting

Hook Not Running

  1. Verify annotation syntax:
  2. Check hook status in Argo CD UI or CLI:
  3. Ensure hook is in the correct phase

Hook Fails Continuously

  1. Check job logs:
  2. Describe the job:
  3. Verify environment variables and secrets

Sync Blocked by Failed Hook

Next Steps

Sync Waves

Combine hooks with waves for precise control

Sync Options

Configure additional sync behavior

Health Checks

Ensure resources are healthy

Creating Apps

Learn how to create applications