All technological notes.
Sync Phases
| Phases | Description | Use cases |
|---|---|---|
PreSync |
Executes before any resources are applied. | DB migrations, schema updates, security checks |
Sync |
Default. Runs alongside standard application syncing. | |
Skip |
Indicates to Argo CD to skip the application of the manifest. | |
PostSync |
Executes after all resources are synced and healthy. | smoke tests, notifying Slack |
SyncFail |
Runs if the synchronization fails.fails. | |
PreDelete |
Executes before the application is deleted. | |
PostDelete |
Executes after the application is deleted. |
Sync hooks
argocd.argoproj.io/hook used by resources to specify custom logic at specific stages of an sync operation.apiVersion: batch/v1
kind: Job
metadata:
generateName: database-migrations
annotations:
argocd.argoproj.io/hook: PreSync
hook deletion policies (argocd.argoproj.io/hook-delete-policy)
HookSucceeded, HookFailed, and BeforeHookCreation.| Policies | Description |
|---|---|
HookSucceeded |
Deletes the resource if it finishes successfully, but keeps it for debugging if it fails. |
HookFailed |
Deletes the resource if the hook fails. |
BeforeHookCreation |
Default policy; deletes any existing hook resource before creating a new one, ensuring a clean state for the new hook. |
Annotations are added to the resource metadata, typically to Kubernetes Jobs or Pods used for tasks like migrations, as shown in this Argo CD Resource Hooks Documentation.apiVersion: batch/v1
kind: Job
metadata:
name: db-migration-job
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation, HookSucceeded
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: migration
image: busybox
command:
- "sh"
- "-c"
- "echo 'Running db migration...'; sleep 20; echo 'Done'"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: sync-job
namespace: argocd
spec:
project: default
source:
repoURL: "git@github.com:simonangel-fong/Demo_Helm_Private_Repo.git"
targetRevision: HEAD
path: sync-hook
destination:
server: "https://kubernetes.default.svc"
namespace: default
syncPolicy:
syncOptions:
- CreateNamespace=true
kubectl apply -f sync-hook.yaml
Sync Waves
argocd.argoproj.io/sync-wave) that controls the order in which Kubernetes resources are applied to a cluster.integer wave value

metadata:
annotations:
argocd.argoproj.io/sync-wave: "5"
Sync Wave order within each Sync Phase!
Order:
By name
PreSync: The Setup
Sync (The Main Event)
PostSync (The Wrap-up)
apiVersion: batch/v1
kind: Job
metadata:
name: presync-10-data-backup
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation, HookSucceeded
argocd.argoproj.io/sync-wave: "10"
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: data-backup
image: busybox
command:
- "sh"
- "-c"
- "echo 'Running data-backup ...'; sleep 5; echo 'Done'"
apiVersion: batch/v1
kind: Job
metadata:
name: presync-20-config-check
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation, HookSucceeded
argocd.argoproj.io/sync-wave: "20"
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: config-check
image: busybox
command:
- "sh"
- "-c"
- "echo 'Running config-check...'; sleep 5; echo 'Done'"
apiVersion: batch/v1
kind: Job
metadata:
name: presync-30-db-migrate
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation, HookSucceeded
argocd.argoproj.io/sync-wave: "30"
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: db-migrate
image: busybox
command:
- "sh"
- "-c"
- "echo 'Running db-migrate...'; sleep 5; echo 'Done'"
apiVersion: v1
kind: ConfigMap
metadata:
name: sync-10-configmap
annotations:
argocd.argoproj.io/sync-wave: "10"
data:
db_host: "pgdb"
apiVersion: batch/v1
kind: Job
metadata:
name: sync-20-configmap-check
annotations:
argocd.argoproj.io/hook: Sync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation, HookSucceeded
argocd.argoproj.io/sync-wave: "20"
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: configmap-check
image: busybox
command:
- "sh"
- "-c"
- "echo 'Running configmap-check...'; sleep 5; echo 'Done'"
apiVersion: apps/v1
kind: Deployment
metadata:
name: sync-30-web-app
labels:
app: nginx
annotations:
argocd.argoproj.io/sync-wave: "30"
spec:
replicas: 5
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
apiVersion: batch/v1
kind: Job
metadata:
name: sync-40-web-check
annotations:
argocd.argoproj.io/hook: Sync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation, HookSucceeded
argocd.argoproj.io/sync-wave: "40"
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: web-check
image: busybox
command:
- "sh"
- "-c"
- "echo 'Running web-check...'; sleep 5; echo 'Done'"
apiVersion: batch/v1
kind: Job
metadata:
name: postsync-10-smoke-testing
annotations:
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation, HookSucceeded
argocd.argoproj.io/sync-wave: "10"
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: smoke-testing
image: busybox
command:
- "sh"
- "-c"
- "echo 'Running smoke-testing...'; sleep 5; echo 'Done'"
apiVersion: batch/v1
kind: Job
metadata:
name: postsync-20-notifications
annotations:
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation, HookSucceeded
argocd.argoproj.io/sync-wave: "20"
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: notifications
image: busybox
command:
- "sh"
- "-c"
- "echo 'Running notifications...'; sleep 5; echo 'Done'"
kubectl apply -f sync-wave.yaml
# application.argoproj.io/sync-wave created
