Skip to main content

kube_spec_seq_field

Function kube_spec_seq_field 

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

Read the sub-spec.<field> YAML sequence on a K8s custom resource YAML document as Option<&serde_yaml::Sequence> — the composed sequence- arity per-sub-field-sequence accessor peer that stands on the composed scalar-arity kube_spec_field (23bd568) accessor, folding the trailing .and_then(|v| v.as_sequence()) shape-gate closure into the helper for callers that always want a sequence (the load-bearing per- CR body-sub-field sequence readbacks — spec.ingress[] on the CiliumNetworkPolicy per-:contratos L4/L7 rule fan-out, spec.listeners[] / spec.parentRefs[] / spec.hostnames[] on the Gateway API Gateway / HTTPRoute per-:entrada overlay, spec.rules[] on the Gateway API HTTPRoute per-rule match/backend fan-out, spec.healthChecks[] on the Flux v2 Kustomization per-CR health-check block). Structural mirror of the sibling kube_spec_str_field (c4fe21d) on the same sub-spec.<field> axis: both accessors fold a trailing shape-gate closure onto the composed scalar-arity kube_spec_field two-hop navigation, both stay parametric on the per-<field> sub-field axis-key. Where kube_spec_str_field closes the spec.<field> string-scalar readback (the leaf-scalar arm), this closes the spec.<field> sequence readback (the multi-entry sub-block arm). Together they bracket the two canonical composed per-spec.<field> shape-gate arities every K8s CR document the emit-side kube_resource_skeleton renders carries under its spec: body: scalar-string leaves via the sibling, ordered sub-sequences via this accessor.

Returns None on any of the four short-circuit arms folded through the underlying composition: the outer spec: block is absent (the kube_spec outer-arm short-circuit), the spec: value is present but carries a non-Mapping YAML type (the kube_spec shape-gate short-circuit), the requested sub-field <field> axis-key is absent from the spec: sub-mapping (the kube_spec_field trailing Mapping::get none-arm), or the sub-field value is present but carries a non-sequence YAML type (the trailing .as_sequence() shape-gate short-circuit — a schema-invalid per-CR body-sub-field type per the K8s apiserver’s OpenAPI schema 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 canonical shape ≥30 test-side per-CR readback sites across caixa-mesh + caixa-flux previously carried inline as the two-line composition

kube_spec_field(<value>, <FIELD>)
    .and_then(|v| v.as_sequence())
    ...

around a one-token semantic payload (the <FIELD> sub-field axis- key — CILIUM_KEY_INGRESS on the per-CNP ingress-rules readback, GATEWAY_API_KEY_LISTENERS on the per-Gateway listener-set readback, GATEWAY_API_KEY_PARENT_REFS on the per-HTTPRoute parent-Gateway readback, GATEWAY_API_KEY_HOSTNAMES on the per-HTTPRoute host-set readback, KUBE_KEY_RULES on the per- HTTPRoute rule-set readback, FLUX_KEY_HEALTH_CHECKS on the per- Kustomization health-check-set readback). After this lift, every routed consumer folds the two-hop-plus-shape-gate navigation onto kube_spec_seq_field(<value>, <FIELD>) — the outer spec → as_mapping → get(<field>) → as_sequence walk happens once inside the helper, and the caller keeps its downstream idiom (.and_then(|s| s.first()), .iter().find(...), .expect(...), .unwrap_or_else(...)) unchanged — the lift closes the navigation surface, not the per-site continuation posture.

Every future per-CR spec.<field> sequence readback (the future per-:politicas CiliumClusterwideEnvoyConfig emitter’s per-policy spec.rules[] navigation, MESH-COMPOSITION §III.2 #3; the app-operator’s per-Aplicacao mesh.pleme.io/v1alpha1/Aplicacao CR materializer’s spec.membros[] / spec.contratos[] readback, §III.2 #5; the future caixa-otel per-Servico OpenTelemetry-Collector CR’s spec.receivers[] navigation; every future test-side spec.<field>[] sequence probe the M3.x + M4 renderer set adds) reaches this same helper by construction — no per-consumer two-hop- plus-shape-gate chain re-inline, no per-consumer KUBE_KEY_SPEC axis-key drift, no coordinated rewrite across every per-CR body- sub-field sequence readback on a future K8s API-machinery rebrand of the top-level spec: axis.