Skip to main content

error_ctx

Function error_ctx 

Source
pub fn error_ctx(kind_plural: &str, ns: &str) -> String
Expand description

Compose the diagnostic-body head every namespace-scoped default failure wraps around the underlying kube::Error via crate::kube_error::KubeResultExt::kube_ctx_with.

Owns the fixed "list <PluralKind> in <ns>" shape as ONE substrate site. Sibling to crate::configmap::error_ctx on the (per-wire- verb × substrate-owned error-slug) axis-family:

  • crate::configmap::error_ctx owns the "<verb> ConfigMap <ns>/<name>" shape — a per-CM write with an explicit resource name.
  • error_ctx (this primitive) owns the "list <PluralKind> in <ns>" shape — a namespace-wide GET-list with no resource name (the returned list carries every visible resource of that kind).

Both share the discipline of routing the failure-diagnostic shape through ONE substrate composer per wire-verb rather than restating the shape as a bare format!(…) chain at every consumer.

Pre-lift the 2-slot format!("list <PluralKind> in {ns}") chain recurred at TWO hand-authored sites past the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold, both wrapping the same default primitive against a namespace-scoped Api<K>:

  • tatara-pool-reconciler::controller_pool::reconcile_pool — kind "Processes" — the namespace-wide Process enumeration the pool controller walks to find its own owned members.
  • tatara-pool-reconciler::controller_allocation::reconcile_inner — kind "Pools" — the namespace-wide EphemeralPool enumeration the allocation controller walks to build its pool-name → members lookup.

Both sites walked the SAME shape — take a PascalCase plural kind label + the target namespace — and produced the SAME "list <PluralKind> in <ns>" diagnostic. Post-lift each callsite reads list::error_ctx(<kind_plural>, ns) and pipes the returned context string through crate::kube_error::KubeResultExt::kube_ctx_with, which owns the ": {e}" tail; the two halves compose to the byte-identical pre-lift diagnostic.

A future normalization step — a tracing-annotated span carrying the kind + namespace for post-hoc audit, a per-kind structured- error variant so operators filter by list-kind rather than substring-match on the message body, a wire-time hedging of the preposition ("in" vs "@" per a fleet convention), a namespace- prefix injection for a shared-controller deployment — lands at THIS ONE substrate primitive and every downstream namespace-scoped list-diagnostic across the fleet picks up the upgrade mechanically.

§Naming

The kind_plural slot names the K8s resource kind in its PascalCase plural form the way an operator would read it in kubectl get <kind> output ("Pools", "Processes", "HelmReleases", "Kustomizations"). Both current consumers pass a &'static str literal; the signature takes &str so a future caller composing the plural from a typed crate::flux_resource::FluxResource / crate::k8s_builtin_resource::K8sBuiltinResource variant rides through the same composer without a widening.

Theory anchor: THEORY.md §VI.1 (generation over composition — the 2-slot format!(...) chain recurred at 2 hand-authored sites past the ★★ PRIME-DIRECTIVE ≥ 2 duplication trigger and is lifted onto the ONE workspace-wide substrate owner here). THEORY.md §II.1 invariant 5 (composition preserves proofs — the pin block below binds the composer at fail-before-pass-after granularity, so a regression that reordered the head slots, dropped the "in " preposition, or drifted the kind slot from the caller’s typed label surfaces at list::tests::error_ctx_* rather than as silent operator-facing skew across the two consumer sites).