Sync Policy: Every Field, Every Sync Option, Every Annotation
60%
A Recap Exercise
This exercise puts the chapter's fields, sync options, and annotations together in a single manifest, plus one option from the section on deleting an Application. Write the YAML yourself first, then check it against the solution.
The Exercise
Write one Application manifest named my_app in the argocd namespace that satisfies every condition below. Then write the two resource manifests asked for in conditions 22, 23, and 24. Those live in the Git repository the Application points at, not in the Application itself.
- The application belongs to the
defaultproject. - Its manifests come from the repository
https://gitlab.com/learningargo/my-app.git, themanifestsdirectory, tagv0.2. - It deploys to the local cluster, referenced by its registered name rather than its API server URL.
- It deploys into the
team-anamespace. - Synchronization is automated.
- A resource deleted from Git is deleted from the cluster.
- A change made directly in the cluster is reverted to the Git state.
- A sync that would leave the application with zero resources is refused.
- Before any resource is pruned, the deletion has to be approved by a human.
- Pruning runs only after every other resource has been applied and reports healthy.
- When a pruned resource is deleted, its dependents are removed before the resource itself.
- A failed sync is retried up to 7 times. The first retry waits 15 seconds, each following wait is three times the previous one, and no wait exceeds 5 minutes.
- If the
team-anamespace does not exist, Argo CD creates it. - The created namespace carries the label
team: team-aand the annotationimageregistry: quay.io. - Each sync applies only the resources that changed, not every resource in the application.
- The merge is computed by the Kubernetes API server, not by the Argo CD client.
- Client-side schema validation is skipped before apply.
- The sync fails if any of the application's resources is already managed by another Application.
- The diff ignores two things: the
replicasfield of everyDeployment, so a Horizontal Pod Autoscaler changing it does not register as drift, and the value of the environment variable namedLOG_LEVELin theDeploymentnamedapi. - The fields ignored in condition 19 are also left at their live values during a sync, instead of being overwritten from Git.
- The application keeps only its last 5 sync records.
- In the
manifestsdirectory, thePersistentVolumeClaimnameddatais never pruned, even though condition 6 enables pruning for the application. - The same
dataPersistentVolumeClaimalso survives when the whole Application is deleted, not only when it is removed from Git. - In the
manifestsdirectory, theServicenamedlegacyis updated withkubectl replaceinstead ofkubectl apply, because it changes an immutable field.
Try it before reading on.
Solution
The Application manifest. Each comment marks the condition the line satisfies.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my_app
namespace: argocd
spec:
project: default # (1)
source: # (2)
repoURL: https://gitlab.com/learningargo/my-app.git
path: manifests
targetRevision: v0.2
destination:
name: in-cluster # (3)
namespace: team-a # (4)
revisionHistoryLimit: 5 # (21)
syncPolicy:
automated: # (5)
prune: true # (6)
selfHeal: true # (7)
allowEmpty: false # (8)
retry: # (12)
limit: 7
backoff:
duration: 15s
factor: 3
maxDuration: 5m
syncOptions:
- CreateNamespace=true # (13)
- Prune=confirm # (9)
- PruneLast=true # (10)
- PrunePropagationPolicy=foreground # (11)
- ApplyOutOfSyncOnly=true # (15)
- ServerSideApply=true # (16)
- Validate=false # (17)
- FailOnSharedResource=true # (18)
- RespectIgnoreDifferences=true # (20)
managedNamespaceMetadata: # (14)
labels:
team: team-a
annotations:
imageregistry: quay.io
ignoreDifferences: # (19)
- group: apps
kind: Deployment
jsonPointers:
- /spec/replicas
- group: apps
kind: Deployment
name: api
jqPathExpressions:
# env[]? skips any container with no env block, so the
# expression does not error on a sidecar that defines none
- '.spec.template.spec.containers[].env[]? | select(.name GitOps the Hard Way, with Argo CD
Build Real GitOps Pipelines From Empty Clusters to Automated DeploysEnroll now to unlock all content and receive all future updates for free.
