Argo CD "PreSync hook failed" in CI
A PreSync hook runs before the main sync, typically a migration or setup Job. If the hook resource fails, Argo CD stops the sync and marks the operation SyncFailed, because the main resources should not apply after a failed prerequisite.
What this error means
The sync operation ends with "SyncFailed" and a hook message such as "PreSync hook Job/db-migrate failed" or a nonzero Job completion, before the main resources are applied.
FATA[0042] Operation has completed with phase: Failed
Message: one or more synchronization tasks completed unsuccessfully,
reason: PreSync hook Job argocd/db-migrate failedCommon causes
The hook Job exited non-zero
The migration or setup command inside the PreSync Job failed, so its pod completed with an error and the hook is marked failed.
The hook could not schedule or pull its image
A missing image, RBAC gap, or resource limit keeps the hook pod from running to completion, which reads as a hook failure.
How to fix it
Read the hook Job logs
- Find the hook Job named in the SyncFailed message.
- Read its pod logs to see why the command failed.
- Fix the command or its inputs, then re-sync.
kubectl -n argocd logs job/db-migrate
kubectl -n argocd describe job db-migrateControl hook lifecycle and deletion policy
Set a hook delete policy so failed hook resources are cleaned up and re-created on the next attempt.
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: HookFailedHow to prevent it
- Make hook Jobs idempotent so a retry does not compound a partial run.
- Set a hook-delete-policy so failed hooks do not block the next sync.
- Test migration hooks against a staging cluster before prod.