pub fn kube_root_map_field<'a>(
value: &'a Value,
field: &str,
) -> Option<&'a Mapping>Expand description
Read a top-level <field>: sub-mapping on a K8s custom resource
YAML document as Option<&serde_yaml::Mapping> — the composed
sub-mapping-arity per-top-level-field accessor at the root axis,
folding the shape value.get(field).and_then(|v| v.as_mapping())
onto one substrate-primitive method call the caller reads as
intent (kube_root_map_field(<value>, <FIELD>) — “read this K8s
CR’s top-level <FIELD>: sub-mapping”) rather than as a two-hop
readback → shape-gate chain. Structural mirror at the root axis
of the sibling composed sub-mapping-arity accessors on the sub-
axes: kube_metadata_map_field (d03cc08) on the sub-
metadata.<field> axis and kube_spec_map_field (27fc2ee) on
the sub-spec.<field> axis — same trailing .as_mapping() shape-
gate closure folded onto the readback, differing only in which
axis the caller navigates (top-level <field>: here, sub-
metadata.<field> on the metadata peer, sub-spec.<field> on the
spec peer). The root-level variant needs no outer shape gate on
value itself — serde_yaml::Value::get already short-circuits
to None on non-Mapping outer values — so the composition folds
on one hop rather than the two hops the sub-axis peers close.
The two canonical pinned peers on this root-level sub-mapping-
arity axis — kube_metadata (f41c4fe) on the KUBE_KEY_METADATA
half of the K8s CR skeleton every controller admits and
kube_spec (9b028ee) on the KUBE_KEY_SPEC half — now
compose through this lifted primitive: kube_metadata becomes
kube_root_map_field(value, KUBE_KEY_METADATA) and kube_spec
becomes kube_root_map_field(value, KUBE_KEY_SPEC). The two
previously carried identical two-hop
value.get(<KUBE_KEY_*>).and_then(|v| v.as_mapping()) bodies
differing only in the pinned top-level axis-key — exactly the
two-verbatim-copy shape a substrate-primitive lift closes into
one navigation surface.
Returns None on either short-circuit arm the underlying inline
chain closes: the requested top-level <field>: axis-key is
absent (a legally-omitted top-level sub-block — e.g. a
List-shaped document that carries no per-item metadata:
header, or a bare status-scoped document that carries no spec:
body), or the top-level <field>: value is present but carries a
non-Mapping YAML type (a schema-invalid top-level sub-block per
the K8s API-machinery contract that pins both metadata: and
spec: as Mappings, but tolerated here as None so the readback
stays a total function). The returned &Mapping borrows into
the input Value — the caller decides whether to enumerate
(for (k, v) in sub { ... }), further-navigate
(sub.get(KUBE_KEY_LABELS)), pin its length (.len()), or clone.
The field axis stays parametric (rather than pinned to
KUBE_KEY_METADATA or KUBE_KEY_SPEC — those pinned peers
kube_metadata / kube_spec still exist and now compose on
this primitive) so the same lift closes every top-level sub-
mapping-arity axis a future K8s API-machinery revision surfaces:
a status: sub-block readback for the future caixa-operator’s
per-Caixa/Lacre/CaixaBuild CR reconciler’s
status.observedGeneration navigation, a data: sub-block
readback on ConfigMap / Secret shapes the mesh renderer
materializes for per-Aplicacao config surfaces, a
spec.template nested pod-template readback each future per-
Deployment renderer reaches for — each new top-level sub-mapping
axis reaches this helper with a new [KUBE_KEY_<AXIS>] const,
not a fresh per-axis helper. Root-axis peer to kube_root_str_field
(ae83f4e) which closes the same one-hop-plus-shape-gate
navigation on the string-scalar-arity top-level <field>: axis
— together they open a two-arity family at the root that mirrors
the sub-metadata: and sub-spec: three-arity families
({str, seq, map}) already closed at the sub-axis level.