Argo CD has a safety check that most teams never see, because it only shows up on a bad day.
If an Application runs automated sync with prune: true and Git suddenly renders nothing for it, Argo CD doesn't delete everything. It skips the sync and puts a SyncError on the app:
Skipping sync attempt to <revision>: auto-sync will wipe out all resources
One field turns that check off: allowEmpty: true. The docs list it under "Automatic Pruning with Allow-Empty (v1.8)", and it's easy to set without thinking about what it removes.
What the check actually does
The code is short. In controller/appcontroller.go (lines 3127 to 3138 on master today), before an automated sync runs, the controller walks every resource the Application manages. If prune is on, allowEmpty is off, and every one of those resources would be pruned, it stops there and writes that message.
The docs describe it as protection "from any automation/human errors when there are no target resources."
With allowEmpty: true, that loop never runs. The sync goes ahead and prunes all of it.
How an app ends up rendering nothing
Nobody has to delete a folder for this to happen. Picture a Helm chart that wraps its templates in {{- if .Values.enabled }}, which a lot of charts do. Someone copies a values file over from a staging overlay where the service is switched off. The PR looks like a config tidy-up and gets merged.
helm template now returns zero objects for production.
With the guard on, Argo CD refuses, the app goes into SyncError, and someone has to go and look. That's annoying, and it's the good outcome. With allowEmpty on, the next auto-sync deletes the Deployment, the Service, the ConfigMaps and everything else the app owns.
One thing the guard doesn't cover either way: a commit that drops some manifests but not all of them. It only fires when every resource would go.
Why teams turn it off
The guard has a cost. An Application that is supposed to be empty for a while sits in SyncError until something shows up in Git. A common case is an ApplicationSet that generates one app per folder, where a team has created the folder but not the manifests yet.
Setting allowEmpty: true makes that error go away. If it goes into the ApplicationSet template, every Application the template generates has the guard switched off, including the ones that aren't empty and never will be.
That's where I'd look first.
How to check by hand
Both commands are read-only. You need read access to the namespaces where Argo CD keeps its Applications and ApplicationSets.
Applications with the guard off:
kubectl get applications -A -o json | jq -r '.items[] | select(.spec.syncPolicy.automated.prune == true and .spec.syncPolicy.automated.allowEmpty == true) | .metadata.namespace + "/" + .metadata.name'
ApplicationSet templates with the guard off:
kubectl get applicationsets -A -o json | jq -r '.items[] | select(.spec.template.spec.syncPolicy.automated.prune == true and .spec.template.spec.syncPolicy.automated.allowEmpty == true) | .metadata.namespace + "/" + .metadata.name'
An empty result means every app with automated prune still has the guard.
The second command reads the structured template only. If you set syncPolicy through templatePatch or a Go template string, it won't show up there, so search the repo too:
git grep -n 'allowEmpty'
What to do about it
If an app turns up and nobody can say why it needs to be empty, remove allowEmpty: true. Prune keeps working for normal changes. Only the delete-everything case stops.
If an app really does need to be empty sometimes, you have two options. Turn prune off for that app and prune by hand. Or keep allowEmpty and put argocd.argoproj.io/sync-options: Prune=false on the resources you can't afford to lose, so a prune skips them.
And on the review side, a PR that adds allowEmpty: true next to prune: true deserves a second look. It's a one-line change, and it decides what happens the day a values file is wrong.
Top comments (0)