Repository navigation
Commit 57ee69a
authored
Refs #353 (part 2d: the `CoderAIGatewayKey` half of option B′, sweep).
Refs #156. Stacked on #385 (records). Review only the top commit. I
retarget this PR to `main` after #385 lands.
## Summary
The cleanup record sweep from #375 now also handles `CoderAIGatewayKey`
records. After a namespace deletion with an external database, the
leftover keys are deleted in Coder once the namespace comes back with a
control plane on the same Coder deployment. A different deployment at
the same URL is never swept. Provider sweeping is unchanged.
## Design note (option B′,
#353 (comment))
The sweep keeps every rule of #375. The only new part is how one
record's resources are deleted. That part now goes through a per-kind
table (`cleanupRecordKinds`): the object type to look up, the words for
the Event, and the sweep function.
| Invariant | Providers (#375, unchanged) | Keys (this PR) |
| --- | --- | --- |
| 4. Who sweeps | A ready control plane in the record's namespace whose
live `/buildinfo` deployment ID equals the record's | Same |
| 5. What is deleted | The recorded provider ID, or the provider whose
display name is the nonce | Every listed key whose name is the record's
prefix `ck8s-<UID without dashes>-` plus a serial. The prefix is checked
against the record's UID first (assertion). No other key is touched. |
| 6. When | Object with that UID gone (live read), 5 minutes after the
last create | Same. The object is gone, so no serial bound applies:
after the settle window no create of the object can still commit. |
| 7. Record removed | Delete answered with success or Coder's own 404 |
A site owner's LIST shows no key with the prefix. The pass deletes and
lists again, at most twice. A failed LIST or DELETE, or a 404 that is
not Coder's own, keeps the record (retry in 1 minute). |
| 8. No match | Metric and `NoMatchingDeployment` Event | Same, with the
kind label `CoderAIGatewayKey`. The Event says "the AI Gateway keys". |
The sweeper also wakes a key record when its `CoderAIGatewayKey` is
deleted, as it does for providers.
## Validation
- New tests in `cleanup_sweep_key_test.go`:
- `TestCleanupSweepAIGatewayKeys`: the settle window, no match, a
different deployment at the same URL, and then the sweep. The sweep
deletes the current, the retiring and an orphan key. It leaves a
person's key and another object's `ck8s-` key, and the metrics change.
- `TestCleanupSweepAIGatewayKeyCases`: a living object, the same name
with a new UID, a proxy 404, a LIST that still shows a key, an operator
user that is not a site owner, and a control plane in another namespace.
- Red then green: 6 mutations, each caught by a test: keys not swept,
"gone" without a confirming LIST, no prefix filter, no site-owner check,
any 404 confirming a delete, and an object lookup by name only.
- Local gates: build-installer, codegen, docs-reference, drift,
verify-vendor, build, lint, govulncheck, test, test-integration, race,
docs-check, actionlint. All passed.
- Kind dogfood with a licensed Coder on 5bb2486 (same Go code as the
head; the round-2 commit changes only docs):
#386 (comment). A
namespace deletion left 2 keys. A different deployment at the same URL
and a control plane in another namespace swept nothing. The namespace
came back on the same database, and then 0 keys and 0 records were left.
## Risks
- The provider path changes only in its log wording (`Swept the Coder
resources of a deleted object`). Its Event text is the same as before.
- A sweep of keys lists every key in the deployment (Coder has no
filter). That is one LIST per record per sweep, the same LIST the key
controller already sends.
---
_Generated with [`xum`](https://github.com/coder/xum) • Model:
`anthropic:claude-opus-5-5` • Thinking: `high`_
---------
Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 45dc78b commit 57ee69a
3 files changed
Lines changed: 312 additions & 21 deletions
File tree
- docs/how-to
- internal/controller
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
155 | 164 | | |
156 | 165 | | |
157 | | - | |
| 166 | + | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
| |||
191 | 200 | | |
192 | 201 | | |
193 | 202 | | |
194 | | - | |
| 203 | + | |
195 | 204 | | |
196 | 205 | | |
197 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | | - | |
93 | | - | |
94 | | - | |
| 96 | + | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
149 | 152 | | |
150 | 153 | | |
151 | 154 | | |
152 | | - | |
153 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
157 | | - | |
158 | | - | |
| 161 | + | |
| 162 | + | |
159 | 163 | | |
160 | 164 | | |
161 | 165 | | |
| |||
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
184 | | - | |
185 | | - | |
| 188 | + | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
189 | | - | |
| 193 | + | |
190 | 194 | | |
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
194 | 198 | | |
195 | | - | |
| 199 | + | |
196 | 200 | | |
197 | 201 | | |
198 | 202 | | |
199 | 203 | | |
200 | | - | |
| 204 | + | |
201 | 205 | | |
202 | 206 | | |
203 | 207 | | |
| |||
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
210 | | - | |
| 214 | + | |
211 | 215 | | |
212 | 216 | | |
213 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
214 | 234 | | |
215 | 235 | | |
216 | 236 | | |
| |||
309 | 329 | | |
310 | 330 | | |
311 | 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 | + | |
312 | 370 | | |
313 | 371 | | |
314 | 372 | | |
| |||
317 | 375 | | |
318 | 376 | | |
319 | 377 | | |
320 | | - | |
| 378 | + | |
321 | 379 | | |
322 | 380 | | |
323 | 381 | | |
| |||
0 commit comments