Commit 018b8eb
fix(infra): deterministic APIResourceSchema name hash (stop etcd-filling leak)
schemaPrefix hashed the CRD's OpenAPIV3Schema with fmt %v. OpenAPIV3Schema
is full of pointer fields (Default, Items, AdditionalProperties, …), and
fmt %v prints nested pointer fields by *address*, not value. Those
addresses change every reconcile, so the hash — and thus the immutable
APIResourceSchema name (tmpl<hash>.templates.infrastructure.kedge.faros.sh)
— was non-deterministic. Every reconcile minted a brand-new schema and
never deleted the old one.
In a long-lived environment this leaked ~4.5k APIResourceSchemas (~55MB in
/registry, mirrored in /cache) into a single logical cluster. On the next
control-plane restart, kcp's cold-start LIST of all schemas pushed etcd
past its memory limit into a permanent OOMKill loop, taking the root shard
(and the console) down.
The controller path already hashed via json.Marshal but kept a %v
fallback; the install path still used %v directly.
- install/apiexport.go: hash json.Marshal(schema); stable, address-free
fallback instead of %v.
- controller/template/apiexport.go: drop the %v fallback for the same.
- install/apiexport_test.go: regression test — identical content
(incl. Default pointer fields) must hash equal across allocations,
and a real content change must still change the name.
Both callsites now frame the hash identically, so bootstrap-install and
the runtime controller produce the same name for the same schema.
Note: this stops new leaks. Recovering an already-affected cluster still
requires bumping etcd memory, GC-ing the orphaned schemas, and an etcd
defrag/compact.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent c774a9a commit 018b8eb
3 files changed
Lines changed: 91 additions & 2 deletions
File tree
- providers/infrastructure
- controller/template
- install
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
206 | 210 | | |
207 | 211 | | |
208 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
309 | 325 | | |
310 | 326 | | |
311 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments