Read Managed Fields as an Ownership Record
A field manager is the name attached to a write, and the managed-fields list is the receipt. Server-side apply records one entry per writer, naming the manager, the operation, a timestamp and a tree of the paths that write sent. That tree is the only direct evidence of who owns a value; labels such as a managed-by convention are a claim someone typed, not a fact the API enforces.
The tree encodes one address from the object root to the leaf. Each node nests map keys and struct fields under an f: prefix, so a parent path and its children read as a single field address. A path that appears in two entries is shared ownership; a path that appears twice with different values is the disagreement the next apply is refused over.
Operation tells you how the entry was produced, and therefore how much to trust its breadth. An entry from an apply lists only the paths in that patch, while an entry from an update can claim a whole subtree the writer merely echoed back after a read. A controller doing read-modify-write therefore looks greedier in the record than it behaves, and a human who edits one field can appear to own a block of keys they never touched.
Manager identity is configuration, not a constant. The manifest resource writes under the name Terraform unless its field manager block overrides it, so two roots that keep the default are one manager to the API. Give each root a distinct name and the record becomes readable at a glance, with no need to guess which pipeline wrote a value.
| Manager entry | Typical operation | Fields it usually claims | What it means for the plan |
|---|---|---|---|
tf-app (a root you named) | Apply | only the paths in that root's manifest | safe to share the object with other writers |
tf-platform (a second root) | Apply | cluster-scoped bootstrap fields | a different object, not a different field of this one |
kube-controller-manager | Update | status, and the scale subresource | do not declare these fields in a manifest |
kubectl or a human manager | Apply | the field the person changed | a one-time takeover that needs a follow-up commit |
kubectl-client-side-apply | Update | the fields in the last-applied annotation | an older owner that must be released, not ignored |
Merge semantics decide whether sharing a list is even possible. A list the schema declares as a map keyed on name merges per entry, which is why a service mesh can append its sidecar to the Deployment's container list without deleting yours. A list with no merge strategy is atomic: whoever applies it owns every element, and a second writer's addition is dropped rather than merged.
Typed resources never reach this conversation. The typed resource family writes with a full update, so there is no apply patch for the API to check field by field and no conflict response to read. A controller's value is simply overwritten on the next apply and reappears as drift on the plan after that, which is a slower and less honest signal than a refusal.
An ownership entry can outlive the writer that made it. Deleting an autoscaler or an operator does not delete the entry it created; the field stays claimed until another manager takes it or the API prunes old entries. That is why a retired controller can still block a write months later, and why the record is a history as much as a map.
The status subresource keeps two arguments from colliding. Writes to status go through a different endpoint, so a controller updating conditions and Terraform updating the spec never contend for the same path even when both are recorded on one object. That separation is a property of the API design rather than a courtesy the controller extends, which is why writing status from configuration is an error and not a negotiation.
Read the record before the write, not after the failure. A get request with managed fields shown prints the entries beside the object, and the output is small enough to diff between two applies. Captured before the change, the conflict message becomes a lookup instead of an investigation.
A refusal names the fields it found, not only the first one. One failure is usually a complete inventory of the disagreement for that request, which is more useful than a single path and easier to skim past. Read all of it before deciding which owner is wrong, because fixing one path and re-running often reveals the next.
Figure 1 follows one field from three entries to a single answer.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
O["Live object
read with managed fields"] --> M["three manager entries
one field path"]
M --> T["tf-app
operation Apply"]
M --> C["kube-controller-manager
operation Update"]
M --> H["human manager
operation Apply"]
T --> Q{"Do the owners
agree on the value?"}
C --> Q
H --> Q
Q -->|"one value"| S["shared ownership
no request refused"]
Q -->|"different values"| X["409 conflict
apply rejected"]
S --> P["plan is stable while
each writer stays in bounds"]
X --> R["name the owner, then
release or take over once"]
R --> P
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class O,M,Q primary;
class T,C,H secondary;
class S,P ok;
class X danger;
class R warn;
Sharing an object is normal; sharing a path is the exception. Figure 2 separates one Deployment into the zones that three different writers legitimately hold, so the ownership question becomes local instead of object-wide.
Three questions turn the record into a decision. Who wrote the path, with which operation, and do they still run? A live Terraform manager plus a live controller over disjoint paths is a design; a stale entry plus a new claim over one path is a conflict waiting for the next plan.
Reproduce One Harmless Field Conflict
A ConfigMap is the cheapest object that still has real field semantics. Its data is a map of string keys, so ownership is per key rather than per object and a conflict names one key instead of the whole document. Nothing in the lab schedules a pod, which keeps a mistake inside a disposable namespace.
Create the object with Terraform first. The manifest resource owns exactly what the manifest contains, so the first apply records one entry for the Terraform manager over two keys: greeting and owner. A third key, note, is deliberately left to a human writer, which will show that disjoint keys coexist with no tolerance setting at all.
Then let a second manager write the same object. A server-side apply from the command line under a different manager adds a key Terraform does not manage, and that key is accepted immediately because nothing claims it. The same write also changes greeting, and that part is refused, because Terraform already owns the key at a different value; adding the force flag lets it through and transfers the claim. The object now carries two apply entries, one of them taken rather than granted.
The refusal is the mechanism working. A conflict response is not an outage, a credential problem or a version skew; it is the API stating that two writers disagree about one path and neither has been authorised to overrule the other. Repeating the identical apply reproduces it exactly, which is the useful property: nothing is half-written and nothing drifts while you decide.
Reverse the direction and the lesson holds. Terraform changes greeting again and the same check runs against the human entry, so this time Terraform is the writer being refused. The failure moved but the cause did not: nobody released the key, and force was used to paper over the first disagreement instead of resolving it.
Client-side apply leaves a different kind of owner behind. It records the fields in a last-applied annotation and adds a manager entry of its own, so an object moved from an older kubectl habit to server-side apply carries two claims before anyone edits a value. The first server-side write can then be refused by a record nobody remembers creating, which is why the migration is a planned release rather than a switch.
Release is a write that removes a path from your own applied set. Re-applying the human manifest without the greeting key drops that manager's claim, because a manager owns only the fields in its last applied configuration. With no other owner the key is then deleted from the object, which is the real cost of releasing a field that nobody else writes; Terraform's next apply recreates it at its own value.
A controller changes the consequence of the same step. When another manager also owns the field, withdrawing Terraform's claim leaves the value in place because the controller re-asserts it on its next reconcile. The identical release therefore deletes a ConfigMap key and preserves a replica count, which is exactly why the contract has to name the field's real owner before the handoff.
The refusal is per resource, not per run. Terraform stops at the failing resource, but earlier resources in the same apply are already written and recorded in state, so a conflict is also a partial apply. Re-plan after resolving it instead of resuming from memory, because the graph has already moved.
| Field | Terraform manager | Human manager | Next Terraform apply |
|---|---|---|---|
data.greeting | hello | hello-fixed, forced | refused with a conflict on this key |
data.owner | tf-lab | not claimed | unchanged, still Terraform-owned |
data.note | not claimed | from-kubectl | preserved, never touched |
metadata.labels | team=payments | not claimed | unchanged, per-key merge |
Figure 3 is the same sequence with the branches that matter, including the one where release deletes instead of hands over.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["Terraform apply
creates the ConfigMap"] --> B["human server-side apply
sets greeting"]
B --> Q{"Same key,
different value?"}
Q -->|"no, a new key"| OK["two entries
no error"]
Q -->|"yes"| X1["409 conflict
names manager and key"]
X1 --> F["force-conflicts
takes the key"]
F --> C["Terraform changes greeting"]
C --> X2["409 conflict
Terraform is refused"]
X2 --> R["human re-applies
without the key"]
R --> D{"Another owner
of the key?"}
D -->|"no"| DEL["key deleted
from the object"]
D -->|"yes, a controller"| KEEP["value kept
claim withdrawn only"]
DEL --> T["Terraform apply sets
its value without force"]
KEEP --> T
T --> V["two clean plans
field has one owner"]
OK --> V
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class A,Q,D primary;
class B,F,C,R secondary;
class T,V,OK,KEEP ok;
class X1,X2 danger;
class DEL warn;
The lab works because nothing reconciles it. A ConfigMap has no controller, so every change in the record belongs to a writer you can name and every disagreement stays a two-party argument. Add a controller and the same test stops being about who typed last; it becomes about which of the two is supposed to be right.
Choose a Narrow Ownership or Computed-Field Contract
The contract has three clauses and one prohibition. The first clause is the manager name, the second is the set of paths you send, and the third is the tolerance for values the server rewrites after the write. The prohibition is force as a steady state, because a permanent override is not a contract with the other owner; it is the absence of one.
Manager identity belongs to the root, not to the resource. Give each root a stable name that says which pipeline wrote the value, and record it beside the object's address in the ownership list. A name invented per resource multiplies entries without improving the answer, and a shared default merges two roots into one indistinguishable writer.
The manifest is the field list. Under server-side apply, omission is a claim boundary rather than an oversight: a path you never send is a path you never own. That makes removing a field from the manifest the primary release operation, and it makes a copied default a new claim on a value the schema was governing.
Typed resources need a different contract. They send a whole spec, so the only lever is the plan: omit the field where the schema permits it, or exclude that one attribute from change detection. That changes what Terraform proposes and leaves API ownership exactly as it was, and the two effects must not be confused in review.
The tolerance list has a default that is easy to erase. Declaring computed fields covers the values a mutating webhook or the API may change, and the default covers metadata labels and annotations. Supplying your own list replaces that default rather than extending it, so name the narrowest path that actually moves and re-include the metadata entry when you still depend on it.
A tolerant path is not an ownership transfer. Terraform still sends its value on every apply; the tolerance only decides whether the returned value is treated as an error. If the server's value should win permanently, delete the field from the manifest instead of teaching Terraform to accept an answer it keeps overwriting.
Force removes the check for the entire resource. It is not a per-field override, it does not remember why it was enabled, and it does not expire. A one-time takeover is defensible as a separate commit followed by a commit that removes the flag; a flag left on converts every future disagreement into a silent overwrite by whichever side applied last.
Another reconciler changes the manager name, not the mechanism. A Helm release writes under its own manager, and a GitOps controller writes under another, so one object can carry three apply entries from three tools. The rule from the prerequisite still holds — one reconciler per object — and the field list is what makes deliberate sharing safe rather than accidental.
| Clause | Provider setting | Scope | What it proves | Failure mode |
|---|---|---|---|---|
| Manager identity | field_manager.name | one resource per root | the record distinguishes your writers | two roots appear as one manager |
| Field boundary | the manifest itself | one path per omission | you own only what you send | a field you needed is simply absent |
| Server tolerance | computed_fields | named paths only | admission may rewrite these paths | a path typo covers nothing and still errors |
| Takeover | force_conflicts | the whole resource | a deliberate, one-time override | permanent last-writer-wins |
| Plan-only exclusion | ignore_changes on a typed resource | one attribute | the diff stays quiet | ownership is still contested in the API |
Narrow is a boundary, not a gap. Figure 4 shows the difference between a gate that admits one named path and a wall that is removed entirely, because that is the whole choice between a tolerance and a takeover.
A contract that owns three fields and states them is stronger than one that owns everything by force. Every remaining diff is then a question someone can answer, and every silent overwrite has already been ruled out by design rather than by discipline.
Verify Controller Convergence and Plan Stability
Five observations look alike in a terminal and need different answers. A conflict refuses a write, drift proposes one, defaulting fills a value the configuration never sent, a webhook mutation changes a value that was sent, and a controller mutation changes a field Terraform never claimed. The response differs in each case, so naming the observation is the first step rather than a formality.
| Observation | Where it appears | Was anything written | Correct response |
|---|---|---|---|
| Field conflict | apply fails, naming a manager and a path | no, the request is refused | change the contract, then release or take over once |
| Drift | plan proposes an update | yes, when applied | decide whether Terraform should own the field |
| Defaulting | a value appears after apply with no config change | yes, by the API | leave the field out of the manifest |
| Admission mutation | the same, caused by a webhook | yes, by the webhook | tolerate the exact path or let the webhook own it |
| Controller mutation | a value Terraform keeps resetting | yes, on every apply | withdraw the claim from the manifest |
A conflict writes nothing, which is why it is safe to investigate. Ownership is validated before the patch is stored, so a refusal leaves the object at its previous value and the plan unchanged. That safety is about a single request; a retry loop simply reproduces the same refusal with more noise in the logs.
Drift is a difference, and a difference is not a verdict. A plan that proposes a change is asking who has authority over the field; if a controller is the right owner, the answer is to stop declaring it, not to schedule more applies. The repeating diff is the symptom of two writers, and applying harder never resolves a disagreement about authority.
Defaulting happens on write, every write. The API fills a field because the object would otherwise be incomplete, and the typed provider absorbs that by reading the value back into a computed attribute. The manifest provider instead compares what you sent with what came back, so an untolerated default is reported as an inconsistent result rather than silently accepted.
Convergence is a runtime claim, not an apply result. A Deployment can be stored, accepted and still be mid-rollout or crash-looping, so read the rollout status, the Deployment conditions and pod readiness as separate evidence. The apply proves the API took the object; it never proves the workload works.
A refresh reads the cluster, and reading claims nothing. Refreshing after a controller change updates state with the live value, which can make the next plan quiet without changing who owns the field. A quiet plan after a refresh is evidence about the read rather than about the contract, so pair it with the manager entry before calling the dispute resolved.
Stability needs two plans separated by an event. The first plan after the change shows the record settled; a controller event between the two proves the settlement survives reconciliation. Two plans with nothing in between only prove that nothing happened.
Use the exit code instead of parsing prose. A detailed-exitcode plan returns 0 for no changes, 2 for changes and 1 for an error, so a pipeline can tell a clean cluster from an edited one without matching English text. That single integer is the difference between a gate and a habit.
Figure 5 places the before and after side by side, with the event that separates the two plans.
The check is cheap enough to run on every change. Capture the manager entries, run a plan, trigger or wait for one controller event, and run the plan again. If the second plan is clean, the ownership contract holds; if it is not, the diff names the path that is still being claimed twice.
Document a Reversible Handoff
Execution status: design-only. The procedure is written for Terraform 1.17.1 with hashicorp/kubernetes 3.5.0 and was not run against a live cluster for this article. Use a disposable cluster and a namespace you are allowed to delete.
Prerequisites. A cluster where you may create a namespace, a Deployment and a horizontal autoscaler; metrics available to that autoscaler; and one root that manages the Deployment through a manifest resource with its own field manager name. No cloud resource, storage class or ingress is involved.
Document a Reversible Handoff
- Capture the baseline. Read the Deployment with managed fields shown, record the manager entries, and run a plan with the detailed exit code. Expect 0, meaning the object and the configuration already agree.
- Reproduce the dispute without changing anything. Drive CPU above the autoscaler's target, wait for it to raise the count, then plan again. Expect a proposed change back to the configured count; stop there, because applying it would only restage the loop.
- Name the new owner in the contract. Remove the replica count from the manifest, or move it to a bootstrap-only resource that is not part of the steady-state root. Add a comment naming the autoscaler and the review that approved the handoff.
- Apply once and watch what does not happen. Expect success with no replacement and no change to the running replica count, because Terraform no longer sends that field and the autoscaler's entry still holds it.
- Read the record, not the plan. Confirm that Terraform's entry no longer lists the replica path and that the controller's entry still does. The claim is gone; the value is not.
- Prove the plan is stable. Plan, expect no changes, then drive another scale event and plan again. A change on the second plan means the field is still somewhere in the manifest or in a second root.
- Prove the controller still reconciles. Delete one pod and confirm the controller replaces it while the count stays at the autoscaler's target. A controller that had stopped reconciling would leave the replacement missing and the object at whatever count was last written.
- Prove Terraform still owns its half. Change the image tag in the manifest, apply, and confirm the rollout completes with no replica churn. If the count moves during the rollout, the field re-entered the applied set.
- Rehearse the reversal. Delete the autoscaler, restore the replica count to the manifest, and plan. If the plan conflicts with the retired entry, perform one apply with the force flag, remove the flag in the following commit, and prove a clean plan. The record outlives the writer, so a takeover step is expected rather than surprising.
- Record the handoff as an artifact. Write down the manager names, the field list per owner, the two plan results, the manager-entry excerpt and the reversal steps. The document is what makes the next engineer able to reverse the decision without repeating the experiment.
| Check | Evidence | Pass looks like |
|---|---|---|
| Dispute is real | plan after a scale event | a proposed change Terraform did not need to make |
| Claim withdrawn | manager entry for the Deployment | Terraform no longer lists the replica path |
| Value preserved | live object after the apply | the count the autoscaler set is still in place |
| Plan stable | two plans with a scale event between | both report no changes |
| Controller healthy | pod deletion and replacement | the controller restores the desired count |
| Terraform still works | image change and rollout | rollout completes, count does not move |
| Reversal documented | plan after restoring the field | clean, or one deliberate takeover then clean |
Expected observation. Withdrawing the field removes Terraform's claim without touching the value, because the autoscaler re-asserts it. The first plan after the handoff is the proof that the claim is gone, and the second plan after a scale event is the proof that it stays gone.
Failure checks. If the first plan still proposes the old count, the field is present somewhere else: a second root, a bootstrap resource, or a template that renders it back into the manifest. If the apply reports a conflict, the autoscaler is not the owner you assumed; read the entries before forcing anything. If the count drops to zero or one after the handoff, nothing owns the field, which is a different bug from a conflict.
Cost dimensions. The lab is close to free: one namespace, one Deployment and one autoscaler on a disposable cluster. There is no load balancer, node pool or persistent volume, so the only realistic charge is the cluster you already run.
Cleanup. Delete the autoscaler first so it stops writing, then the Deployment, then the namespace, and confirm no cluster-scoped object remains. Run a final plan against the root to prove it manages nothing else, and keep the manager-entry excerpt with the handoff record rather than in the pull request description.
The deliverable is the pair of plans, not the paragraph explaining them. A reviewer can see the claim before the change, the claim after it, and the same clean result surviving a controller event, which is the only evidence that the handoff is real and reversible.