Skip to main content

Module meta

Module meta 

Source
Expand description

ObjectMeta accessor extension trait.

Every workload controller (ReplicaSet / Deployment / StatefulSet / Endpoints / Job / GC) reads the same handful of fields off the opaque serde_json::Value it lists from the store:

  • metadata.uid — the object’s stable identity (owner refs)
  • metadata.name — the object’s name (child naming, owner refs)
  • metadata.namespace — scope

Before this trait each controller hand-copied byte-identical *_uid / *_name accessors. Per the Prime Directive the shape is solved ONCE here: ObjectMeta is the single accessor surface every controller consumes. Adding a new controller no longer re-derives these accessors.

The trait is implemented for serde_json::Value (so it is also available through any &Value deref); call sites read obj.uid() / obj.name() / obj.namespace() directly.

§Reading an integer: DefaultedInt and int_at (T1.6)

A count (spec.replicas, spec.completions, metadata.generation) has three states — absent, an integer, or something else — and the old spec_i64(key, default) read the third as the first: a Deployment declaring replicas: "3" was scaled to one pod. Both readers go through engenho_types::SpecInt and keep the third state an error:

  • int_at — Ok(None) absent, Ok(Some(n)) an integer, Err(ShapeError::NotAnInteger) anything else. For a field whose absence means “off” (startingDeadlineSeconds).
  • DefaultedInt::read — the same, with absence replaced by the field’s API default, declared once next to the field’s path (REPLICAS). For a count the apiserver would have defaulted.

A malformed integer is a Declarative, Item-scoped ShapeError: the object it belongs to gets nothing written for it this pass and a Warning (an Event through the sweep, or warn_unreadable where there is no sweep), and every other object is reconciled as usual.

§Writing: object_mut and array_mut are total

Reading an opaque object is already total (get returns Option). Writing was not: a controller reached a nested map through .as_object_mut().expect(..) or serde_json’s IndexMut, and both PANIC on a value of the wrong JSON type. Stored objects are declared by users, so the wrong type is ordinary input, not a broken invariant. The owner-reference writer was the worked case: a ReplicaSet whose spec.template.metadata.ownerReferences was null panicked the whole controller task on its first pod, and every ReplicaSet after it in the list stopped converging.

The two accessors decide every shape in one place:

  • absent, or null — treated as empty: {} or [] is inserted and returned. Upstream’s Go types decode null to a nil map or slice, and every upstream writer initializes a nil one before writing, so this is the same answer, not a new leniency;
  • the expected container — returned as-is;
  • anything else — ShapeError::Wrong, naming the dotted path and the JSON type found there. Nothing is written.

JsonKind has no Null arm, because null is never reported: it is the empty case.

Structs§

DefaultedInt
An integer field whose absence means its API default.
FieldPath
A dotted path into an object, as the operator reads it.

Enums§

Container
The container a write needs at a path.
JsonKind
The JSON type found where a Container was needed.
ShapeError
A stored object does not have the shape a controller needs: a write needs a container, or a read needs an integer.

Constants§

REPLICAS
apps/v1 spec.replicas (Deployment, ReplicaSet, StatefulSet): the apiserver defaults an absent count to 1.

Traits§

ObjectMeta
Borrowed accessors over a K8s object’s metadata + spec.

Functions§

array_mut
The array at path inside value, creating it as [] when absent or null, and every absent or null step above it as {}.
int_at
The integer at path in object, in its three states: Ok(None) when missing or null, Ok(Some(n)) when it holds an integer.
object_mut
The map at path inside value, creating every absent or null step as {}.
warn_unreadable
Say that a field object declares cannot be read (error names it), so nothing is written from it this pass — the structured warning where there is no crate::sweep::Sweep to raise an Event on the object.