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
//! Substrate primitive for the delete-verb wire idiom over any kube
//! [`Resource`].
//!
//! Owns the 2-link chain
//!
//! ```text
//! api.delete(&name, &DeleteParams::default()).await
//! ```
//!
//! that every controller-side writer hand-authored pre-lift at each
//! reap / drain / SIGTERM-cascade / PR-close site.
//!
//! Sibling to the wire-verb family already lifted in
//! [`crate::create`] and [`crate::patch`]. Together the three modules
//! own the three K8s HTTP verbs the workspace's controllers stamp at
//! their idempotent-write sites:
//!
//! - [`crate::create::default`] — POST (create) with `PostParams::default()`.
//! - [`crate::patch::merge`] / [`crate::patch::merge_status`] /
//! [`crate::patch::apply_patch_params`] — PATCH (merge + SSA).
//! - [`default`] (this primitive) — DELETE with `DeleteParams::default()`.
//!
//! Pre-lift the 2-link `api.delete(&name, &DeleteParams::default())`
//! chain recurred at SEVEN hand-authored consumer sites across THREE
//! crates:
//! - `tatara-pool-reconciler::controller_pool::apply_pool_decision`
//! `PoolDecision::ReapExcess` arm — the reap-excess Free-member
//! DELETE.
//! - `tatara-pool-reconciler::controller_pool::apply_pool_decision`
//! `PoolDecision::ReplaceMembers` arm — the replace-member DELETE
//! (respawn on next tick).
//! - `tatara-pool-reconciler::controller_pool::apply_pool_decision`
//! `PoolDecision::Drain` arm — the drain-all-members DELETE.
//! - `tatara-pool-reconciler::controller_pool::apply_convergence_action`
//! `ConvergenceAction::SignalSigterm` arm — the desired-loop
//! scale-down DELETE (SIGTERM oldest excess).
//! - `tatara-pool-reconciler::controller_pool::apply_convergence_action`
//! `ConvergenceAction::ReapFailed` arm — the desired-loop
//! reap-failed-member DELETE.
//! - `tatara-reconciler::phase_machine` (Exiting fan-out) — the
//! SIGTERM-cascade child-DELETE that terminates every owned child
//! Process before the parent's Zombie transition.
//! - `tatara-github-watcher::handler::handle_pr_event` (`PrAction::Closed`
//! arm) — the PR-close allocation DELETE (paired with the
//! [`crate::kube_error::is_not_found`] 404-tolerance guard for
//! idempotent re-delivery).
//!
//! One of the seven pairs the delete call with the
//! [`crate::kube_error::is_not_found`] 404-tolerance guard already
//! lifted in [`crate::kube_error`] — the "delete-or-treat-404-as-ok"
//! compound the watcher stamps for idempotent PR-close re-delivery.
//! Post-lift both halves of that compound ([`default`] +
//! [`crate::kube_error::is_not_found`]) ride through ONE substrate
//! owner apiece so the compound reads exactly `delete::default(&api,
//! &name) → is_not_found` at that callsite. The other six pool +
//! reconciler sites discard the result (`let _ = process_api.delete
//! (...)`) — the finalizer / owner-ref cascade owns the eventual
//! outcome; a 404 there is already the terminal state the caller
//! wanted, and a transient error re-fires on the next reconcile tick.
//!
//! ### Naming
//!
//! The primitive is named [`default`] — the `DeleteParams::default()`
//! slot is the axis it closes, mirroring [`crate::create::default`]
//! (which closes the peer `PostParams::default()` slot on the create
//! axis). A caller reads `delete::default(&api, &name)` and understands
//! they are dispatching through the default `DeleteParams` posture —
//! foreground / background / orphan cascade left to the K8s API
//! server's default (Background for most resources), no
//! `grace_period_seconds` override, no `preconditions` on
//! `resourceVersion` or `uid`, no `dry_run`. A future write that needs
//! a bounded grace period (a SIGKILL-fast scale-down) or a
//! Foreground-cascade block (a delete-must-not-return-until-children-
//! are-gone posture) composes a bespoke `DeleteParams` at the callsite
//! rather than routing through this primitive — the primitive names
//! the DEFAULT posture, not the general-purpose DELETE builder.
use Either;
use ;
use Status;
use Resource;
use DeserializeOwned;
use Debug;
/// Delete a kube [`Resource`] through its namespaced or cluster-scoped
/// [`Api`] with the default [`DeleteParams`] posture.
///
/// Owns the 2-link wire-side chain
/// `api.delete(&name, &DeleteParams::default())` at ONE substrate owner
/// across every workspace consumer. Sibling to
/// [`crate::create::default`] on the wire-verb axis (DELETE vs POST),
/// and to [`crate::patch::merge`] on the same axis (DELETE vs PATCH).
///
/// A future normalization of the delete posture (an injectable
/// `grace_period_seconds` slot for bounded-grace scale-downs, a
/// `PropagationPolicy::Foreground` gate for delete-must-block-until-
/// children-gone postures, a `preconditions.uid` slot for optimistic
/// concurrency at reap sites, a dry-run gate) lands at THIS ONE
/// function and every downstream consumer inherits the upgrade
/// mechanically — no per-site edit at any of the seven listed callers
/// or at future consumers (a future receipt-GC controller, a future
/// pool-tombstone reaper, a future cross-namespace cascade sweeper).
///
/// The returned `Either<K, Status>` matches `Api::delete` verbatim: a
/// server that returns the pre-delete resource body populates the
/// `Left` arm; a server that returns a bare `Status` (the more common
/// path for finalized deletes and for cluster-scoped resources)
/// populates the `Right`. Every current consumer either discards the
/// result (`let _ = process_api.delete(...)`) or matches only on
/// `Ok(_) | Err(_)`, so the concrete `Either` shape flows through
/// without a per-site change; a future consumer that needs to
/// distinguish "the API returned the pre-delete body" from "the API
/// returned bare status" reads the `Either` directly at its callsite.
///
/// Theory anchor: THEORY.md §VI.1 (generation over composition — the
/// 2-link `api.delete(&name, &DeleteParams::default())` chain recurred
/// at 7 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 drifts `DeleteParams::default()`
/// to a non-default posture — a stray `grace_period_seconds`, an
/// accidental `PropagationPolicy::Foreground`, a `preconditions.uid`
/// — surfaces at `delete::tests::*` rather than as silent operator-
/// facing skew across the seven consumer sites (a hung reap because
/// the server blocks on children, a fast-SIGKILL scale-down that
/// tramples a still-shutting-down probe, a mistaken uid-precondition
/// that refuses to reap a recreated slot)).
pub async