Skip to main content

kube_root_seq_field

Function kube_root_seq_field 

Source
pub fn kube_root_seq_field<'a>(
    value: &'a Value,
    field: &str,
) -> Option<&'a Sequence>
Expand description

Read a top-level <field>: sub-sequence on a K8s custom resource or helm-values-shaped YAML document as Option<&serde_yaml::Sequence> — the composed sequence-arity per-top-level-field accessor at the root axis, folding the shape value.get(field).and_then(|v| v.as_sequence()) onto one substrate-primitive method call the caller reads as intent (kube_root_seq_field(<value>, <FIELD>) — “read this document’s top-level <FIELD>: sequence”) rather than as a two-hop readback → shape-gate chain. Structural mirror at the root axis of the sibling composed sequence-arity accessors on the sub-axes: kube_metadata_seq_field (139a94b) on the sub-metadata.<field> axis and kube_spec_seq_field (fc64ed7) on the sub-spec.<field> axis — same trailing .as_sequence() 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. Peer of kube_root_str_field (ae83f4e) on the string-scalar-arity root axis and kube_root_map_field (723f6d7) on the sub-mapping-arity root axis: the three together close the root-axis {str, seq, map} three-arity family to structural parity with the sub-metadata: {str, seq, map} and sub-spec: {str, seq, map} three-arity families already closed at the sub-axis level.

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 values.yaml document that carries no programs: sequence yet, a List-shaped document whose items: sequence is absent, a bare HelmRelease that carries no root-level programs: when the emitter routes through spec.values.programs instead), or the top-level <field>: value is present but carries a non-sequence YAML type (a schema-invalid top-level sub-block per the fleet-programs / HelmRelease values contract that pins programs: as a Sequence, but tolerated here as None so the readback stays a total function). The returned &Sequence borrows into the input Value — the caller decides whether to iterate (.iter()), pick the first entry (.first()), enumerate for length (.len()), or clone.

The field axis stays parametric (rather than pinned to FLEET_PROGRAMS_KEY_PROGRAMS as a separate helper) so the same lift closes every top-level sequence-shaped axis a future emitter surfaces: a root-level items: readback on a List-shaped multi- doc envelope, a root-level documents: readback on a hypothetical M4 aggregator envelope the future app-operator per-Aplicacao mesh.pleme.io/v1alpha1/Aplicacao CR materializer emits (MESH-COMPOSITION §III.2 #5), a root-level imports: readback on a future lacre.lisp closure-manifest envelope — each new top- level sequence axis reaches this helper with a new axis-key const, not a fresh per-axis helper.

Two identical-shape test-side call sites in [caixa-flux] converge onto this helper — the [caixa_flux::upsert_into_programs_yaml] round-trip pins at [caixa_flux::tests::upsert_inserts_new_entry] and [caixa_flux::tests::upsert_replaces_existing_entry] both reach through the root-level programs: sequence readback on the bare-values.yaml shape, and both re-derived the same two-hop .get(FLEET_PROGRAMS_KEY_PROGRAMS).unwrap().as_sequence().unwrap() chain inline. Post-lift each site composes as kube_root_seq_field(&modified, FLEET_PROGRAMS_KEY_PROGRAMS).unwrap() — the shape they now name is the substrate primitive rather than the hand-spelled readback chain.