Expand description
M0.1 item 8 — shared status-subresource write primitive.
Every workload controller (Deployment / ReplicaSet / StatefulSet /
Job) computes a .status from the LIVE owned children it already
listed in its tick + writes it back. Per the Prime Directive this is
solved ONCE here: write_status_cas is the single shape all four
controllers consume.
§Three invariants this primitive enforces
-
Idempotent skip (the primary hot-loop defense). The desired status is compared field-by-field against the status already on the live object; if they are equal AND
status.observedGenerationalready equalsmetadata.generation, NO command is proposed (StatusWriteOutcome::NoChange). A no-op reconcile tick mutates nothing, so the watch event it would otherwise produce never happens and the loop terminates. -
Optimistic concurrency (item-5 CAS). The status
Patchcarriesexpected: Some(rv)wherervis the object’smetadata.resourceVersionAS SEEN THIS TICK. If a concurrent spec change (operator scale) committed between the controller’s list and this write,mod_revisionadvanced, the precondition fails, and the store returnsResourceOp::Conflict. That is a benign retry (Proposed(Rejected(Conflict))) — the write is dropped, the next watch-wake re-reads fresh state and recomputes. A status write thus NEVER clobbers a concurrent spec change.What the store did is read through
Effect::of, never by testing for one op: a patch the store refused for any reason (PatchRejected,ApplyConflict) is reported refused, notWritten. -
Typed emission. The status JSON is authored as a typed
serde_json::Value(the store is opaque-JSON); noformat!()of JSON.
§The second shape: an edit of the object as read (T2.5)
write_status_cas writes a status computed from what the controller
LISTED, so after a conflict it cannot recompute: it drops the write and
the next watch-wake starts over. edit_status_cas is for a status
that is a function of the object itself, such as one condition set by
type (upsert_condition_cas). It reads the object, asks the edit what
to write, writes that at the revision it read, and on a conflict reads
again and retries exactly once. Its outcome names each way nothing was
written (StatusEditOutcome), where StatusWriteOutcome::NoChange
folds “already current” and “no revision” into one arm.
The reads and writes go through CasEnv, the store in production
(StoreCasEnv) and a fake that races a concurrent writer in tests.
Structs§
- Store
CasEnv CasEnvover the store, writing as oneReason.
Enums§
- Status
Edit - What an edit makes of the object it was handed.
- Status
Edit Outcome - Outcome of an
edit_status_cascall. Every arm butProposedmeans nothing was proposed, and each says why. - Status
Write Outcome - Outcome of a
write_status_cascall.
Constants§
- GENERATION
metadata.generation, the spec-intent revisionobservedGenerationreconciles against. The store stamps it on every write;0(never stamped) when absent.
Traits§
- CasEnv
- The reads and writes of a read-modify-write: read the object, and write an RFC 7396 merge patch conditioned on the revision read.
Functions§
- edit_
status_ cas - Read the object at
key, askeditwhat to merge into its.status, and write that at the revision read. On a conflict, read again and retry exactly once. - generation_
of - Read
metadata.generationoff a stored object.0when absent. - pod_
is_ ready - True iff
podreports astatus.conditions[type=Ready,status=True]. The shared readiness predicate for the replica-counting controllers. - resource_
version_ of - Parse a stored object’s
metadata.resourceVersionstring into aRevision— the CASexpectedvalue for the status write. - upsert_
condition_ cas - Set one condition on the object at
key, by type (upsert_condition), writing at the revision read and retrying once on a conflict (edit_status_cas). - write_
status_ cas - Write a controller-computed
.statusontoparentvia an optimistic-concurrencyPatch, skipping the write entirely when the status is already current.