Skip to content

Operator: "the object has been modified" – conflicts on status updates

Python & Gotested on Go 1.26, Kubebuilder v4, controller-runtime, envtest

An occasional conflict is normal, a permanent conflict is a bug. Usually the controller writes the whole object via Update while others change it in parallel.

Symptom

grep -c 'Reconciler error' run.log
13

The operator uses Update instead of Patch; kubectl patch and kubectl annotate change the same site in parallel.

Diagnosis

Look at the error text, the error metric and the writers according to managedFields.

grep 'Reconciler error' run.log | head -1 | sed 's/.*"error": //'
curl -s localhost:8080/metrics | grep 'reconcile_errors_total{controller="staticsite"'
kubectl get site demo --show-managed-fields -o jsonpath=\
'{range .metadata.managedFields[*]}{.manager} {.operation} {.subresource}{"\n"}{end}'
"Operation cannot be fulfilled on staticsites.web.lab.example \"demo\": the object
has been modified; please apply your changes to the latest version and try again"}
controller_runtime_reconcile_errors_total{controller="staticsite"} 13
kubectl-client-side-apply Update
main Update status
kubectl-annotate Update
kubectl-patch Update
site-operator Update status

Causes

UpdateWhole object with an old resourceVersion

Update sends the complete object including the resourceVersion from the cache. If someone else wrote meanwhile, optimistic locking strikes.

managedFieldsSeveral writers

managedFields reveals the players: kubectl-annotate and kubectl-patch write in parallel – like GitOps, an HPA or colleagues in a real cluster.

Fix

Go back to Patch with MergeFrom – it sends only the diff, without resourceVersion.
git checkout -- internal/controller/status.go
grep -c 'Reconciler error' run.log
0

Don't: Suppressing the conflict with a retry loop inside Reconcile – the workqueue retries with backoff anyway; the problem is the Update.

▶
Break it yourself and find it – free
Kubernetes operators hands-on, Day 15: a competition with eight typical operator faults, from hot loop to orphans.
Go to day 15 →

FAQ

Is every conflict an error?

No. Reconcile returns the error and the workqueue retries with backoff. Only a permanent conflict is a bug.

How do I see who last wrote a field?

With kubectl get … --show-managed-fields. managedFields is the write log of an object.

Related error patterns

More