1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
//! Substrate primitive for the `Api::all(<client>)` binding every
//! workspace consumer of a **cluster-scoped** typed [`Api<K>`] handle
//! reaches for when it needs a bare cluster-wide typed collection
//! from an owned [`Client`] (no namespace slot, no per-request
//! reconciler context in scope).
//!
//! Owns the 1-link chain
//!
//! ```text
//! let api: Api<K> = Api::all(<client>);
//! ```
//!
//! that every cluster-scoped tatara-CRD / K8s-built-in binder site
//! hand-authored pre-lift at each `Api::all(self.kube.clone())`
//! callsite.
//!
//! # Peer axis
//!
//! Sibling to [`crate::process_api::namespaced`] +
//! [`crate::configmap::namespaced`] on the (scope × K) axis pair —
//! those primitives own the `Api::namespaced(<client>, <ns>)` shape
//! at a fixed `K = Process` / `K = ConfigMap`; this primitive owns
//! the `Api::all(<client>)` shape at any `K: Resource<DynamicType =
//! ()>`. The pre-lift 4-site sprawl split across two crates spanned
//! FOUR distinct K bindings (`Process` + `ProcessTable` +
//! `EphemeralPool` + `EphemeralAllocation`), so the primitive fixes
//! the scope slot structurally at `Api::all` and leaves the K slot
//! generic — the callsite's return-type annotation (or its enclosing
//! `-> Api<K>` signature) picks the K, and rustc infers it end-to-end
//! from the callsite's typed handle usage.
//!
//! # Pre-lift call-site history
//!
//! The `Api::all(<client>.clone())` chain recurred at FOUR
//! hand-authored production sites past the ★★ PRIME-DIRECTIVE ≥ 2
//! duplication threshold, spanning two crates:
//!
//! * `tatara-reconciler::context::Context::process_table_api` — the
//! cluster-scoped `Api<ProcessTable>` binder for the /proc
//! singleton, fed into the top-level `Controller::new(table_api,
//! …)` watch wiring + into every downstream ProcessTable
//! consumer (`bootstrap_process_table` seed, `table_controller`
//! reconcile loop, `check_ptbl_in_sync` diagnostic).
//! * `tatara-reconciler::context::Context::processes_all_api` — the
//! cluster-scoped `Api<Process>` binder for the reap-children
//! walker (`phase_machine::handle_exiting` filtering by
//! `spec.identity.parent`), the claim-arbiter enumerate
//! (`table_controller::reconcile` grouping by
//! `${cluster}/${app}`), and the top-level `Controller::new(...)`
//! wiring in `main.rs` when `--watch-namespace` is empty.
//! * `tatara-pool-reconciler::context::PoolContext::pools_all_api` —
//! the cluster-scoped `Api<EphemeralPool>` binder for the
//! top-level `Controller::new(pool_api, …)` watch wiring in the
//! pool reconciler's `main.rs`.
//! * `tatara-pool-reconciler::context::PoolContext::allocations_all_api`
//! — the cluster-scoped `Api<EphemeralAllocation>` binder for the
//! top-level `Controller::new(alloc_api, …)` watch wiring in the
//! pool reconciler's `main.rs`.
//!
//! Each pre-lift site restated `Api::all(self.kube.clone())`
//! verbatim, with the `.clone()` on the ambient `Client` field
//! feeding the primitive's owned-Client slot. Post-lift each
//! consumer reads `tatara_process::api::all(self.kube.clone())` and
//! the cluster-scoped typed-handle binding lives at ONE substrate
//! owner across every CRD binding.
//!
//! # Compounding
//!
//! A future normalization of the cluster-scoped Api-handle posture (a
//! wired-in tracing span for handle construction, a client-side QPS
//! limiter, a fixture-backed client for CI/smoke-tests, a per-CRD
//! watch filter that pre-warms `Controller::new`'s stream cache)
//! lands at THIS ONE function and every downstream consumer — the
//! four current callsites AND every future cluster-scoped Api
//! binding site (a future `Api<EphemeralAllocationBinding>` for the
//! P3 kenshi-runner lift, a future audit-walker enumerating every
//! Process across a subshard) inherits the upgrade mechanically.
//!
//! # Naming
//!
//! The module is named [`api`] — a bare top-level submodule under
//! `tatara-process` naming the axis it closes ("build a cluster-
//! scoped typed `Api<K>` handle at ONE substrate primitive"). The
//! peer namespaced-scope binders live at [`crate::process_api`] (K
//! = Process) and [`crate::configmap::namespaced`] (K = ConfigMap)
//! rather than under this module because those primitives fix a K
//! structurally — the cluster-scoped axis instead leaves K generic
//! and lets the callsite pick, so a bare [`api`] name best matches
//! its polymorphic contract.
use ;
use NamespaceResourceScope;
use ;
/// Bind a cluster-scoped typed [`Api<K>`] handle from an owned
/// [`Client`] for any K that satisfies the standard
/// [`kube::Resource`] projection with a zero-sized `DynamicType`
/// (every derive-generated CRD + every K8s built-in Rust binding
/// meets this bound).
///
/// Owns the 1-link chain `Api::all(<client>)` at ONE substrate site
/// across every workspace consumer that reads or writes a
/// cluster-scoped typed collection through a typed handle. Sibling
/// to [`crate::process_api::namespaced`] +
/// [`crate::configmap::namespaced`] on the (scope × K) axis pair —
/// those own the namespaced-scope shape at a fixed K; this owns the
/// cluster-scope shape at any K.
///
/// The `K` type parameter is inferred from the callsite's return-
/// type annotation (or its enclosing `-> Api<K>` signature), so a
/// caller writes `tatara_process::api::all(self.kube.clone())` and
/// gets the same typed handle every hand-authored `Api::all(client)`
/// site produced.
///
/// A future normalization of the cluster-scoped Api posture (a
/// default-injected tracing span for handle construction, a
/// client-side QPS budget, a fixture-backed client for CI/smoke-
/// tests, a wired-in watch pre-warmer) lands at THIS ONE function
/// and every downstream consumer inherits the upgrade mechanically —
/// no per-site edit at any of the four listed callers or at future
/// consumers.
///
/// Theory anchor: THEORY.md §VI.1 (generation over composition —
/// the 1-link `Api::all::<K>(<client>)` chain recurred at 4 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 primitive at fail-before-
/// pass-after granularity, so a regression that drifted the scope
/// slot from `Api::all` to `Api::namespaced` — silently narrowing a
/// cluster-wide watch to a single namespace — surfaces at
/// `api::tests::*` rather than as silent operator-facing skew across
/// the four consumer sites).
/// Bind a namespace-scoped typed [`Api<K>`] handle from an owned
/// [`Client`] + `&str` namespace for any K that satisfies the
/// standard [`kube::Resource`] projection with a zero-sized
/// `DynamicType` (every derive-generated CRD + every K8s built-in
/// Rust binding meets this bound).
///
/// Sibling to [`all`] on the (scope × K) axis pair: [`all`] owns the
/// cluster-scoped `Api::all(<client>)` shape at any K; this owns the
/// namespace-scoped `Api::namespaced(<client>, <ns>)` shape at any K.
/// Both primitives fix the scope choice structurally at the function
/// name — a caller writes `api::all(client)` for the cluster-wide
/// posture or `api::namespaced(client, ns)` for the namespace-scoped
/// posture, and a regression that silently drifted one for the other
/// (a stray `Api::all` where a namespace-scoped dependency lookup was
/// intended, an `Api::namespaced` where a cluster-wide watch was
/// intended) fails at the callsite's scope-word rather than as silent
/// operator-facing skew.
///
/// The `K` type parameter is inferred from the callsite's return-
/// type annotation (or its enclosing `-> Api<K>` signature). Fixed-K
/// namespaced binders already open at [`crate::process_api::namespaced`]
/// (K = Process) and [`crate::configmap::namespaced`] (K = ConfigMap)
/// delegate through THIS primitive post-lift, so a future
/// normalization of the ns-scoped Api posture (a default-injected
/// tracing span for handle construction, a client-side QPS budget, a
/// per-namespace retry budget, a fixture-backed client for CI/smoke-
/// tests, a wired-in `PatchParams` field manager for status writes)
/// lands at THIS ONE function and every downstream consumer inherits
/// the upgrade mechanically.
///
/// # Pre-lift call-site history
///
/// The `Api::namespaced(<client>.clone(), <ns>)` chain recurred at
/// SIX hand-authored production sites past the ★★ PRIME-DIRECTIVE ≥ 2
/// duplication threshold spanning four crates and five distinct K
/// bindings — three tatara CRDs and two K8s built-ins:
///
/// * `tatara_pool_reconciler::context::PoolContext::pool_api` — the
/// namespace-scoped `Api<EphemeralPool>` binder every pool-side
/// reconcile handler rides through.
/// * `tatara_pool_reconciler::context::PoolContext::allocation_api` —
/// the namespace-scoped `Api<EphemeralAllocation>` binder every
/// pool-side reconcile handler rides through.
/// * `tatara_pool_reconciler::context::PoolContext::process_api` —
/// the namespace-scoped `Api<Process>` binder every pool-side
/// reconcile handler rides through when it patches a bound member's
/// overlay.
/// * `tatara_github_watcher::handler::HandlerState::allocation_api` —
/// the github-watcher's per-request namespace-scoped
/// `Api<EphemeralAllocation>` binder.
/// * `tatara_reconciler::phase_machine::classify_export_jobs` — the
/// namespace-scoped `Api<Job>` binder for the export-watching
/// Verifying-arm reconcile step.
/// * `tatara_process::process_api::namespaced` +
/// `tatara_process::configmap::namespaced` — the two fixed-K
/// siblings already lifted (K = Process, K = ConfigMap), which
/// now delegate through THIS primitive rather than restating
/// `Api::namespaced(client, ns)` at their own bodies.
///
/// Each pre-lift site restated `Api::namespaced(self.kube.clone(),
/// ns)` verbatim, with the `.clone()` on the ambient `Client` field
/// feeding the primitive's owned-Client slot. Post-lift each consumer
/// reads `tatara_process::api::namespaced::<K>(client, ns)` (or
/// delegates through a fixed-K sibling that itself routes here) and
/// the ns-scoped typed-handle binding lives at ONE substrate owner
/// across every CRD binding.
///
/// Theory anchor: THEORY.md §VI.1 (generation over composition — the
/// 1-link `Api::namespaced::<K>(<client>, <ns>)` chain recurred at 6
/// 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 primitive at fail-before-pass-after
/// granularity, so a regression that drifted the scope slot from
/// `Api::namespaced` to `Api::all` — silently widening a
/// namespace-scoped dependency lookup into a cluster-wide sweep —
/// surfaces at `api::tests::*` rather than as silent operator-facing
/// skew across the six consumer sites).
/// Bind a namespace-scoped [`Api<DynamicObject>`] handle from an owned
/// [`Client`] + `&str` namespace + a runtime-resolved
/// [`ApiResource`] descriptor.
///
/// Owns the 1-link `Api::namespaced_with(<client>, <ns>, <&ar>)` chain
/// every workspace consumer of a namespace-scoped **dynamic** typed
/// handle reaches for when the K binding is not known at compile time
/// — the arbitrary rendered-resource axis where `K = DynamicObject`
/// and the schema is carried by a [`ApiResource`] value the caller
/// resolved through [`crate::process_api`] / the reconciler's discovery
/// cache.
///
/// # Peer axis
///
/// Sibling to [`namespaced`] on the (K-slot × runtime-schema-slot)
/// axis pair: [`namespaced`] fixes `K: Resource<DynamicType = ()>` so
/// the K's schema is statically-known through its `Resource` impl and
/// no [`ApiResource`] slot is required; this primitive fixes `K =
/// DynamicObject` (whose `DynamicType = ApiResource` — the schema is
/// carried at the value level) and takes the [`ApiResource`] slot
/// explicitly. Both fix the scope at `Api::namespaced` / `Api::
/// namespaced_with` structurally at the function name — a caller
/// writes `api::namespaced::<K>(client, ns)` for statically-typed K or
/// `api::namespaced_dynamic(client, ns, &ar)` for the dynamic-object
/// binding, and a regression that silently drifted between them (a
/// stray `Api::namespaced_with` where a statically-typed handle was
/// intended, an `Api::namespaced` on `DynamicObject` that would fail
/// at compile time for want of the `ApiResource` slot) fails at the
/// callsite's function-name rather than as silent operator-facing skew.
///
/// # Pre-lift call-site history
///
/// The 1-link `Api::namespaced_with::<DynamicObject>(client, ns, &ar)`
/// chain recurred at TWO hand-authored production sites past the ★★
/// PRIME-DIRECTIVE ≥ 2 duplication threshold, both in
/// `tatara-reconciler::ssapply` and both feeding a downstream
/// wire-verb dispatch through the DynamicObject typed handle:
///
/// * `ssapply::apply_owned` — the SSA-side dynamic-object writer for
/// every rendered flux/aplicacao resource. Builds the handle before
/// dispatching through [`crate::patch::apply`] to stamp the owned
/// resource under [`FIELD_MANAGER`].
/// * `ssapply::fetch` — the by-coordinate dynamic-object reader every
/// VERIFY-phase readiness probe + ATTEST-heartbeat drift detector
/// composes to pull the current apiserver-side view of an owned
/// resource. Chains through `Api::get_opt(name)` to project the
/// 404 → `Ok(None)` corner.
///
/// Both sites restated the SAME 3-arg positional chain verbatim:
/// `Api::namespaced_with(client, namespace, &ar)` on an owned `client:
/// Client` + a borrowed `namespace: &str` + a borrowed `&ar:
/// &ApiResource`. Post-lift each callsite reads
/// `tatara_process::api::namespaced_dynamic(client, namespace, &ar)`
/// and the dynamic-object ns-scoped handle binding lives at ONE
/// substrate owner across both consumers.
///
/// # Compounding
///
/// A future normalization of the dynamic-object ns-scoped handle
/// posture (a wired-in tracing span for handle construction naming
/// the ApiResource's kind + group, a client-side QPS budget scoped to
/// the discovery-resolved K, a per-namespace retry budget, a
/// fixture-backed client for CI/smoke-tests, a discovery-cache
/// pre-warmer) lands at THIS ONE function and every downstream
/// consumer inherits the upgrade mechanically — no per-site edit at
/// `apply_owned` / `fetch` or at future consumers (a future dynamic-
/// object watcher for the P3 kenshi-runner lift, a future kensa audit
/// walker over every rendered resource under a Process, a future
/// drift-probe that fetches by dynamic kind before verifying the
/// attestation root).
///
/// The `&ApiResource` slot is borrowed (matching `Api::namespaced_with`'s
/// own signature) rather than owned — both pre-lift callsites already
/// build the `ar` from `api_resource(&api_version, &kind)?` earlier in
/// the function body and pass it by reference; no consumer needs to
/// consume the descriptor at binding time.
///
/// Theory anchor: THEORY.md §VI.1 (generation over composition — the
/// 1-link `Api::namespaced_with::<DynamicObject>(<client>, <ns>, <&ar>)`
/// 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 primitive at
/// fail-before-pass-after granularity, so a regression that drifted
/// the scope slot away from `Api::namespaced_with` — a stray `Api::all_with`
/// cluster-wide widening, a bind through the statically-typed
/// `Api::namespaced` that would fail at compile time for want of the
/// ApiResource carrier — surfaces at `api::tests::*` rather than as
/// silent operator-facing skew across the two consumer sites).