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
//! Substrate primitive for the `Api::namespaced::<Process>` binding
//! every workspace consumer of the tatara `Process` CRD reaches for
//! when it needs a namespace-scoped typed handle from a bare
//! [`Client`] + `&str` namespace pair (no per-crate reconciler
//! context in scope).
//!
//! Owns the 1-link chain
//!
//! ```text
//! let api: Api<Process> = Api::namespaced(<client>, <ns>);
//! ```
//!
//! that every below-controller-layer + boundary-layer Process-handle
//! consumer hand-authored pre-lift at each namespace-scoped bind site.
//!
//! Sibling to the ns-scoped K8s-typed-handle family already lifted at:
//! - [`crate::configmap::namespaced`] — the K8s built-in ConfigMap
//! ns-scoped handle binder, opened for the same
//! `tatara-export-worker` + `tatara-closed-loop-probe` consumers
//! that could not thread through a shared reconciler context.
//! - `tatara_reconciler::context::Context::process_api` — the
//! reconciler's per-request Process-typed handle binder (kept as a
//! forwarder that delegates through THIS substrate primitive
//! post-lift, so a future normalization at the substrate owner
//! reaches BOTH the reconciler-side handler sprawl AND every
//! below-controller boundary/export-worker consumer through ONE
//! owner).
//! - `tatara_pool_reconciler::context::PoolContext::{pool_api,
//! allocation_api,pools_all_api,allocations_all_api}` — the
//! pool-reconciler's tatara-CRD-typed handle binders.
//! - `tatara_github_watcher::handler::HandlerState::allocation_api`
//! — the github-watcher's per-request allocation-typed handle
//! binder.
//!
//! All sibling lifts closed the `Api::namespaced(<client>.clone(),
//! <ns>)` shape at either a controller-owned context struct (per-CRD
//! binder) or a workspace-wide substrate module (per-K8s-built-in
//! binder). This primitive closes the SAME shape at the tatara
//! `Process` CRD for the THREE consumer sites that neither own a
//! reconciler context nor thread through a shared per-request
//! state:
//! - `tatara_reconciler::boundary::evaluate_process_phase` — the
//! `ConditionKind::ProcessPhase` boundary evaluator. Called with
//! a bare `Client` moved in from `check_conditions` (no `Context`
//! in scope; the evaluator sits below the reconciler layer so it
//! can be reused by the `tatara-check` binary).
//! - `tatara_reconciler::boundary::check_depends_on` — the
//! `spec.dependsOn` evaluator. Iterates every dep with a
//! `client.clone()` per row; also called from the boundary layer
//! without a `Context`.
//! - `tatara_export_worker::main::read_artifact` — the export
//! worker's `ProcessSnapshotSource` reader. `tatara-export-worker`
//! is a below-controller-layer binary that DOES NOT depend on
//! `tatara-reconciler` (would introduce a cycle) so it cannot
//! reach the reconciler's `Context::process_api`.
//!
//! Pre-lift the 1-link `let api: Api<Process> = Api::namespaced(
//! <client>, <ns>)` chain recurred at THESE THREE hand-authored
//! consumer sites past the ★★ PRIME-DIRECTIVE ≥ 2 duplication
//! threshold. Post-lift each consumer reads
//! `tatara_process::process_api::namespaced(client, ns)` and the
//! ns-scoped Process handle binding lives at ONE substrate owner.
//!
//! ### Naming
//!
//! The module is named [`process_api`] — the tatara-process crate
//! already owns a top-level `crd` module carrying the `Process`
//! type itself, so a bare `process` submodule would collide with
//! the crate's own name and read as an accidental self-reference
//! (`tatara_process::process::namespaced`). `process_api` names the
//! axis it closes ("build a typed `Api` for the tatara `Process`
//! CRD") explicitly, mirrors the reconciler's own `process_api`
//! method on `Context`, and reads unambiguously at every callsite.
//!
//! Fixing the concrete `K = Process` at the primitive lands three
//! guarantees the pre-lift 3-site sprawl could not offer:
//! - the two `use tatara_process::crd::Process;` /
//! `use tatara_process::prelude::*;` imports at the callsite
//! crates are the ONE typed edge to the Process CRD; any future
//! rename or module-path shift lands at ONE substrate primitive
//! rather than at every consumer;
//! - a regression that swapped `Api::namespaced` for `Api::all` at
//! ONE callsite is now structurally impossible — the scope choice
//! is owned by the primitive's name (peer `Api::all` cluster-wide
//! Process consumers route through
//! `tatara_reconciler::context::Context::processes_all_api` on
//! the reconciler side; a future workspace-wide cluster-scoped
//! peer composes as `process_api::all` on this module);
//! - a future migration to `Api::namespaced_with(client, ns, &ar)`
//! (for the same ns-scoped posture through the dynamic-object
//! channel, mirroring `tatara-reconciler::ssapply`'s DynamicObject
//! consumer) lands at ONE point — every downstream consumer
//! inherits the shift mechanically.
use ;
use crateProcess;
/// Bind a namespace-scoped typed [`Api<Process>`] handle for
/// [`Client`] + `ns`.
///
/// Owns the 1-link chain `Api::namespaced(<client>, <ns>)` for the
/// tatara `Process` CRD at ONE substrate owner across every
/// workspace consumer that reads or writes a Process through a
/// typed handle without a shared per-request context in scope.
/// Sibling to the K8s-built-in ns-scoped handle binder
/// [`crate::configmap::namespaced`] and to the reconciler's
/// per-request `Context::process_api` forwarder.
///
/// A future normalization of the Process-handle posture (a
/// default-injected `PatchParams` field manager for status writes,
/// a wired-in tracing span for handle construction, a per-namespace
/// retry budget, a fixture-backed client for CI/smoke-tests) lands
/// at THIS ONE function and every downstream consumer inherits the
/// upgrade mechanically — no per-site edit at any of the three
/// listed callers or at future consumers (a future boundary-layer
/// evaluator for a new `ConditionKind`, a future below-controller
/// binary that reads a Process by name, a future workspace-side
/// audit walker).
///
/// The returned `Api<Process>` matches `Api::namespaced` verbatim
/// — every current consumer chains through `.get_opt(...)` (both
/// boundary-layer evaluators) or `.get(...)` (the export-worker
/// snapshot reader) at its own callsite, so no wire-side posture
/// is baked in at the primitive.
///
/// Theory anchor: THEORY.md §VI.1 (generation over composition —
/// the 1-link `Api::namespaced::<Process>(<client>, <ns>)` chain
/// recurred at 3 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 swapped the fixed `K = Process` type parameter for a
/// different CRD (`EphemeralPool`, `EphemeralAllocation`, `ProcessTable`)
/// or drifted the scope slot away from `Api::namespaced` — a stray
/// `Api::all` cluster-wide read where a namespace-scoped
/// dependency lookup was intended — surfaces at
/// `process_api::tests::*` rather than as silent operator-facing
/// skew across the three consumer sites).
/// Compose the diagnostic-body head every wire-verb failure against a
/// namespaced [`Process`] wraps around the underlying error via
/// [`crate::kube_error::KubeResultExt::kube_ctx_with`] or the sibling
/// [`anyhow::Context::with_context`] closure form.
///
/// Owns the fixed `<verb> Process <ns>/<name>` shape as ONE substrate
/// site, routing the `<ns>/<name>` join through the workspace-wide
/// [`crate::qualified_process_ref`] composer so a future normalization
/// of the qualified-ref shape (case-fold, unicode collation, IDN)
/// lands at ONE site and every Process-scoped diagnostic body picks
/// it up mechanically.
///
/// Sibling to [`crate::configmap::error_ctx`] on the (per-Kind ×
/// substrate-owned error-slug) axis-family — that primitive owns the
/// fixed `"ConfigMap"` resource-kind literal on the K8s-built-in
/// ConfigMap axis; THIS primitive owns the fixed `"Process"`
/// resource-kind literal on the tatara CRD axis. Both share the
/// discipline of routing the failure-diagnostic head through ONE
/// substrate composer per K8s-Kind rather than restating the shape
/// as a bare `format!(…)` chain at every consumer. And both share
/// the workspace-canonical TitleCase resource-kind spelling
/// (`"ConfigMap"` / `"Process"`) — matching the sibling
/// [`crate::list::error_ctx`]'s TitleCase-plural convention
/// (`"Processes"`) so an operator grepping across the fleet on the
/// canonical kube-canonical form hits every diagnostic surface.
///
/// Pre-lift the 3-slot `format!("{verb} process {ns}/{name}: {e}")`
/// chain (with lowercase `process`, DRIFTING from the workspace-
/// canonical TitleCase `Process` the sibling [`crate::list::error_ctx`]
/// pins for the plural spelling) recurred at TWO hand-authored sites
/// past the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold across two
/// crates:
///
/// * `tatara-reconciler::boundary::evaluate_process_phase` — verb
/// `"fetch"`, wrapping the `Api<Process>::get_opt(&process_ref)`
/// fetch that the `ConditionKind::ProcessPhase` boundary evaluator
/// dispatches for every dependency probe / postcondition Process
/// phase read.
/// * `tatara-export-worker::main::read_artifact` — verb `"get"`,
/// wrapping the `Api<Process>::get(name)` fetch on the
/// `ProcessSnapshotSource` arm that serializes the owning Process's
/// spec + status into the export artifact stream.
///
/// Both sites walked the SAME shape — take a verb, the target
/// Process's namespace + name, and the underlying error's display —
/// and produced the SAME `"<verb> process <ns>/<name>: <error>"`
/// diagnostic. Post-lift each callsite reads
/// `process_api::error_ctx(<verb>, ns, name)` and pipes the returned
/// context string through [`crate::kube_error::KubeResultExt::kube_ctx_with`]
/// (the boundary consumer) or through [`anyhow::Context::with_context`]
/// (the export-worker consumer, whose `kube::Error` bubbles through
/// anyhow's own `Error + Send + Sync + 'static` bound); both tails
/// own the same `": {e}"` suffix so the composed diagnostic is
/// byte-identical to the pre-lift shape modulo the intentional
/// TitleCase-kind drift-close.
///
/// ### Wire-form drift close
///
/// The lift intentionally changes `process` (lowercase) to `Process`
/// (TitleCase) at both consumers' operator-facing diagnostics —
/// closing a workspace-wide wire-form drift where the plural-list
/// axis at [`crate::list::error_ctx`] pinned TitleCase (`"Processes"`),
/// the ConfigMap-write axis at [`crate::configmap::error_ctx`] pinned
/// TitleCase (`"ConfigMap"`), but the singular-fetch axis at these
/// two consumer sites had drifted to lowercase (`"process"`). Post-
/// lift every substrate-owned failure-diagnostic head across the
/// fleet uses the kube-canonical TitleCase kind spelling so a
/// fleet-wide `grep 'Process default/api'` on operator log streams
/// matches EVERY Process-scoped failure body — the fetch corner
/// alongside the list corner alongside the ConfigMap-write corner.
///
/// A future normalization step — a `tracing`-annotated span carrying
/// the verb + qualified-ref for post-hoc audit, a per-verb structured-
/// error kind so operators filter by fetch-verb rather than substring-
/// match on the message body, a wire-time hedging of the verb spelling
/// (`"GET"` vs `"get"` per a fleet convention), injection of a per-
/// cluster prefix for a shared-controller deployment — lands at THIS
/// ONE substrate primitive and every downstream Process-scoped
/// failure diagnostic across the fleet picks up the upgrade
/// mechanically. Future third + fourth consumers (a receipt-GC
/// controller that fetches a Process by owner-ref for a reap decision,
/// a cross-namespace routing walker that reads a Process to derive an
/// Ingress alias) inherit the primitive at their own callsites with
/// no per-site drift surface.
///
/// Theory anchor: THEORY.md §VI.1 (generation over composition — the
/// 3-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, drifted the fixed
/// `"Process"` resource-kind literal back to lowercase, dropped the
/// qualified-ref routing, or narrowed the accepted verb set to a
/// hardcoded closed set surfaces at `process_api::tests::error_ctx_*`
/// rather than as silent operator-facing skew across the two consumer
/// sites).