What is `metadata.managedFields`, and how does Server-Side Apply use it to track ownership?
Quick Answer
managedFields is server-maintained metadata that records which field manager owns which fields and via which operation (Apply or Update). Its fieldsV1 map lists field keys but omits values — the mere presence of a key means that manager owns that field. It lets the API server answer who changed which field and when.
Detailed Answer
Every SSA-managed object carries a managedFields list in its metadata. Each entry has a manager name (for example kubectl, helm, or a controller), an operation (Apply for apply requests, Update for imperative writes and subresources), an apiVersion, a timestamp, and a fieldsV1 tree. That tree mirrors the object structure but stores only keys with empty {} leaves; a key present under a manager means that manager owns the field. So f:spec / f:replicas: {} under manager kubectl means kubectl owns spec.replicas. Because ownership is explicit and per field, multiple managers can co-own different parts of one object (Git owns the pod template, the HPA owns replicas, a controller owns status).
Code Example
managedFields:
- manager: kubectl
operation: Apply
fieldsV1:
f:spec:
f:replicas: {} # kubectl owns spec.replicas
- manager: controller
operation: Update
subresource: statusInterview Tip
Stress that the field map omits values and that presence-of-key equals ownership — that detail signals you have actually read managedFields, not just heard of it.