4. Sync Phases and Waves
In this Lab you are going to learn about Sync Phases and Waves .
Sync Phases and Waves
At a high-level, Argo CD executes the sync operation in the three phases pre-sync, sync and post-sync.
Within each phase you can have one or more waves, that allows you to ensure certain resources are healthy before subsequent resources are synced.
When Argo CD starts a sync, it orders the resources in the following precedence:
- The phase
- The wave they are in (lower values first)
- By kind (e.g. namespaces first)
- By name
It then determines the number of the next wave to apply. This is the first number where any resource is out-of-sync or unhealthy.
It applies resources in that wave.
It repeats this process until all phases and waves are in-sync and healthy.
How to specify waves and phases
Pre-sync and post-sync can only contain hooks defined on annotations argocd.argoproj.io/hook: PreSync.
You can specify the wave in the sync phase by setting an annotation argocd.argoproj.io/sync-wave. Hooks and resources are assigned to wave zero by default. The wave can be negative, so you can create a wave that runs before all other resources.
Task 4.1: Sync Wave Example
Let’s now get our hands on a sync wave example.
Create the new application argo-wave-$USER with the following command. The Application consist of the following resources, phases and waves:
- PreSync
- Job: upgrade-sql-schema
- Sync Wave 0
- Deployment: backend
- Service: backend
- Sync Wave 1
- Job: maintenance-page-up
- Sync Wave 2
- Deployment: frontend
- Service: frontend
- Sync Wave 3
- Job: maintenance-page-down
Create a file argocd-wave-application.yaml with the following content and apply it:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: argo-wave-$USER
namespace: openshift-gitops
spec:
project: default
source:
repoURL: https://gitea.training.cluster.acend.ch/$USER/argocd-training-examples.git
targetRevision: HEAD
path: sync-wave
destination:
server: https://kubernetes.default.svc
namespace: $USER
oc apply -f argocd-wave-application.yaml
Sync the application:
Hint
Open the Argo CD UI
and click Sync on the argo-wave-$USER application.
And verify the deployment:
oc get pod --namespace $USER --watch
Task 4.2: Delete the Application
Delete the application after you’ve explored the Argo CD Resources and the managed Kubernetes resources.
Hint
oc delete application argo-wave-$USER -n openshift-gitops