Skip to content

CICD-297 · Argo CD deployment hooks ​

Encyclopedia · Advanced GitOps and progressive delivery · All snippets

Previous · CICD-296 · Next · CICD-298

1. Where it fits ​

  • Placement gitops/migration-job.yaml metadata fragment.
  • Prerequisites trusted configuration repository, test cluster and named GitOps controller or rollout controller.
  • Platforms kubernetes, local-lab.

2. Copy the snippet ​

yaml
annotations:
  argocd.argoproj.io/hook: PreSync
  argocd.argoproj.io/hook-delete-policy: BeforeHookCreation,HookSucceeded

3. How it works ​

The PreSync hook runs the Job before the main resources. Its delete policy controls reruns and successful cleanup, while a failing Job blocks sync.

A failed migration hook blocks normal synchronization.

flowchart TD
  N1["Begin Argo sync"]
  N2["Run PreSync Job"]
  N1 --> N2
  N3{"Job completes"}
  N2 --> N3
  N4["Sync application resources"]
  N3 -->|Yes| N4
  N5["Stop sync"]
  N3 -->|No| N5
  classDef trigger fill:#EFF6FF,stroke:#0540F2,color:#0A0A0A
  classDef build fill:#CCFBF1,stroke:#0D9488,color:#0A0A0A
  classDef test fill:#EEF2FF,stroke:#4F46E5,color:#0A0A0A
  classDef gate fill:#FEF3C7,stroke:#D97706,color:#0A0A0A
  classDef security fill:#EDE9FE,stroke:#7C3AED,color:#0A0A0A
  classDef deploy fill:#D1FAE5,stroke:#059669,color:#0A0A0A
  classDef fail fill:#FEE2E2,stroke:#DC2626,color:#0A0A0A
  class N1 trigger
  class N2 test
  class N3 gate
  class N4 deploy
  class N5 fail

4. Verify the result ​

Use an idempotent migration Job with bounded time. A failed PreSync hook should hold application changes.

Validation syntax-validated (YAML parse). Status definitions.