Skip to main content

Module status

Module status 

Source
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

  1. 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.observedGeneration already equals metadata.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.

  2. Optimistic concurrency (item-5 CAS). The status Patch carries expected: Some(rv) where rv is the object’s metadata.resourceVersion AS SEEN THIS TICK. If a concurrent spec change (operator scale) committed between the controller’s list and this write, mod_revision advanced, the precondition fails, and the store returns ResourceOp::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, not Written.

  3. Typed emission. The status JSON is authored as a typed serde_json::Value (the store is opaque-JSON); no format!() 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§

StoreCasEnv
CasEnv over the store, writing as one Reason.

Enums§

StatusEdit
What an edit makes of the object it was handed.
StatusEditOutcome
Outcome of an edit_status_cas call. Every arm but Proposed means nothing was proposed, and each says why.
StatusWriteOutcome
Outcome of a write_status_cas call.

Constants§

GENERATION
metadata.generation, the spec-intent revision observedGeneration reconciles 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, ask edit what 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.generation off a stored object. 0 when absent.
pod_is_ready
True iff pod reports a status.conditions[type=Ready,status=True]. The shared readiness predicate for the replica-counting controllers.
resource_version_of
Parse a stored object’s metadata.resourceVersion string into a Revision — the CAS expected value 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 .status onto parent via an optimistic-concurrency Patch, skipping the write entirely when the status is already current.