Wednesday, April 24, 2024
HomeKubernetesArgoCDArgo CD Sync Phases and Waves

Argo CD Sync Phases and Waves

Recently we have Argo CD Sync options with examples, part of that, there is additional options with sync, those are Phases and waves. Why this is matters? This is sometime very useful, if you are expecting some manifest on sequence or some order. Let’s see about Argo CD Phases and waves, in this section.

Sync Phases

Argo CD executes a sync operation in a number of steps. At a high-level, there are 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.     

Argo CD Sync phases

Synchronization can be configured using resource hooks. Hooks are ways to run scripts before, during, and after a Sync operation. Hooks can also be run if a Sync operation fails at any point. Some use cases for hooks are:

  • Using a PreSync hook to perform a database schema migration before deploying a new version of the app.
  • Using a Sync hook to orchestrate a complex deployment requiring more sophistication than the Kubernetes rolling update strategy.
  • Using a PostSync hook to run integration and health checks after a deployment.
  • Using a SyncFail hook to run clean-up or finalizer logic if a Sync operation fails.

Usage

Hooks are simply Kubernetes manifests tracked in the source repository of your Argo CD Application annotated with argocd.argoproj.io/hook, e.g.:

apiVersion: batch/v1
kind: Job
metadata:
  generateName: schema-migrate-
  annotations:
    argocd.argoproj.io/hook: PreSync

During a Sync operation, Argo CD will apply the resource during the appropriate phase of the deployment. Hooks can be any type of Kubernetes resource kind, but tend to be Pod, Job or Argo Workflows. Multiple hooks can be specified as a comma separated list.

ArgoCD Hook

Note:

  • Named hooks (i.e. ones with /metadata/name) will only be created once. If you want a hook to be re-created each time either use BeforeHookCreation policy (see below) or /metadata/generateName.
  • Hooks are not run during selective sync.

Hook Deletion Policies

  • Hooks can be deleted in an automatic fashion using the annotation: argocd.argoproj.io/hook-delete-policy.
ArgoCD Hook deletion policy
  • Note that if no deletion policy is specified, ArgoCD will automatically assume BeforeHookCreation rules.

Sync Waves

Syncwaves are used in Argo CD to order how manifests are applied to the cluster. On the other hand, resource hooks break up the delivery of these manifests in different phases. Using a combination of syncwaves and resource hooks, you can control how your application rolls out.

Argo CD Sync waves

This example will take you through the following steps:

  • Using Syncwaves to order deployment
  • Exploring Resource Hooks
  • Using Syncwaves and Hooks together

Using Sync Waves

A Syncwave is a way to order how Argo CD applies the manifests that are stored in git. All manifests have a wave of zero by default, but you can set these by using the argocd.argoproj.io/sync-wave annotation, like below;

metadata:
  annotations:
    argocd.argoproj.io/sync-wave: "2"

The wave can also be negative as well.

metadata:
  annotations:
    argocd.argoproj.io/sync-wave: "-5"

How Does It Work?

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
    • Namespace
    • Network Policy
    • Resource quota
    • Limit range
    • PodSecurityPolicy
    • .. etc                                ## Find the list sync-task
  • By name

Note:

  • Waves values can be negative or positive.
  • Argocd starts with the lowest wave value to highest
  • Each wave will start if previous wave resources are healthy.
    • Default delay between waves is 2 sec. But you can customize using ARGOCD_SYNC_WAVE_DELAY

Find the sample manifests on: https://github.com/foxutech/kubernetes/tree/main/argocd/sync


You can follow us on social media, to get some regular updates

RELATED ARTICLES
- Advertisment -

Most Popular

Recent Comments