Repository navigation
feat(sandbox): node-level uploader that fills the shared golden store - #5843
Conversation
ee30d0f to
2f539d6
Compare
8d1d643 to
9b3929f
Compare
|
Rebased on current
Also in the rebase:
Re-verified from scratch after the rebase, not from cache: |
The golden's path carries only a repo hash, derived from the clone URL. That is enough node-locally, where the cache is one trust domain, but not for a store shared across nodes: two organizations cloning the same public template land on the same key, so an archive published by one would restore into the other's sandbox. The daemon is the only process holding both facts — the org from Studio's config push and the golden it writes — so it records them together. A golden with no readable org is ineligible for the shared tier, which is the safe default. orgId already reached buildConfigPayload via EnsureOptions.tenant; it was simply never put on the wire. Inverted the test that asserted the operator-only payload, since the org is now sent too. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Nothing publishes to the L2 store today, so it is permanently empty: a sandbox pod's mount is read-only by design. This adds the missing half — a DaemonSet that carries goldens from a node's L1 hostPath into the shared store. WHY NOT A SIDECAR IN THE SANDBOX POD. Writing a store shared across nodes needs write access, and a sandbox runs untrusted code: a package manager installs cached content as-is, so a tenant able to write it could poison another node's boot. The tenant's write path therefore stops at its own node's hostPath, which is already the accepted trust domain there. What that buys over a sidecar: - the sandbox PodSpec is untouched — no per-pod request, no effect on how many sandboxes pack onto a node (which #91 just tuned), and nothing new that can degrade the health probe Studio tears the pod down on. - the writable mount exists once per node in infrastructure, not inside every tenant's pod. - CPU is capped (50m/500m) without competing with a user's dev server. The compression is the expensive part and no boot waits on it. Asserted in the rendered output: the SandboxTemplate never references the writable claim, and the DaemonSet mounts the hostPath read-only. KEYED BY ORG, which is what makes fleet-wide publishing acceptable. A repo hash comes from the clone URL, so two orgs cloning the same public template collide on one key — node-locally that is a single trust domain, fleet-wide it would let one org's tree restore into another's sandbox. The daemon stamps the org beside each golden and a golden without one is SKIPPED rather than uploaded under an unscoped key, so an archive with an unknown owner cannot exist. WHAT IT UPLOADS is not configurable, and cannot be. Sandboxes are multi-tenant and run third-party code, so the set of (repo, lockfile) pairs is unknowable ahead of time — there is no list to curate and no image to pre-bake. It forwards what a real boot produced and the daemon already judged healthy enough to publish node-locally. Same binary as the daemon, via a `golden-uploader` subcommand: the archive format lives in internal/setup, which Go's internal rule keeps unimportable from outside the module, and reusing the sandbox image means no second artifact to build or keep in lockstep. It is not the daemon — no HTTP server, no lifecycle, no tenant. Cost, for the record: one PUT per (org, repo, lockfile) across the whole fleet, because an existing key is a HEAD and a skip. Everything after that is compression CPU, which is why the limit is low and the sweep is sequential. Tests use real files and real tar/zstd: upload keyed by org, skip without provenance, steady-state sweep that recompresses nothing, an archive that actually restores on a cold root, two orgs on one repo getting separate archives, in-flight publishes skipped, and both no-op paths. 26 tests pass in internal/setup. Chart 0.12.0, default off. Requires depsCache.enabled + depsCache.remote.enabled and a writable volume source; the dynamic storageClassName path must supply goldenUploader.pvcName, since a StorageClass cannot express the read-only/read-write split this relies on. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
9b3929f to
ce88414
Compare
PR: #5843 feat(sandbox): node-level uploader that fills the shared golden store Bump type: minor - @decocms/sandbox (packages/sandbox/package.json): 1.45.0 -> 1.46.0 - deploy/helm/sandbox-env (chart 0.13.1) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.46.0 Deploy-Scope: both
Stacked on #5824 — that PR adds the L2 restore; this one adds the publish. Base is its branch, so the diff here is only this change and GitHub will retarget to
mainwhen #5824 merges.Neither is useful alone: #5824 restores from a store nothing fills, and this fills a store nothing reads. Merge both or neither.
The gap this closes
A sandbox pod's L2 mount is read-only by design, so nothing a tenant boots can publish. The store is therefore permanently empty, and #5824's restore always misses. This is the missing half.
Why a DaemonSet and not a sidecar
Writing a store shared across nodes needs write access, and a sandbox runs untrusted code — a package manager installs cached content as-is, so a tenant able to write it could poison another node's boot. The tenant's write path stops at its own node's hostPath, which is already the accepted trust domain there (
depsCache's own comment: "Do NOT widen to a shared cache without making it read-only to tenant pods"). This carries goldens the rest of the way.Asserted against the rendered output, not just intended: the SandboxTemplate never references the writable claim, and the DaemonSet mounts the hostPath
readOnly: true.Keyed by org — this is what makes fleet-wide publishing acceptable
A repo hash is derived from the clone URL, so two orgs cloning the same public template land on one key. Node-locally that is a single trust domain; fleet-wide it would let one org's tree restore into another's sandbox.
The daemon is the only process holding both facts at once — the org from Studio's config push, and the golden it writes — so it records them together beside the tree. A golden without a readable org is skipped rather than uploaded under an unscoped key: an archive whose owner is unknown must not exist.
orgIdalready reachedbuildConfigPayloadviaEnsureOptions.tenant; it was simply never put on the wire. Getting the key right now matters because adding the org later would change every key and invalidate the whole store.What it uploads is not configurable, and cannot be
Sandboxes are multi-tenant and run third-party code, so the set of
(repo, lockfile)pairs is not knowable ahead of time. There is no list to curate and no image to pre-bake — measured: 18 distinct repos in a 41-event sample over 30 days, long tail, no concentration to exploit. It forwards what a real boot produced and the daemon already judged healthy enough to publish node-locally, and nothing else.Cost
One PUT per
(org, repo, lockfile)across the whole fleet — an existing key is a HEAD and a skip. At ~300 MB/archive and ~200 lockfiles that is single-digit dollars a month in S3, and $0 transfer via the VPC Gateway Endpoint. The real cost is compression CPU on the sandbox NodePool, which is why the limit is low and sweeps are sequential.Shape
Same binary as the daemon, via a
golden-uploadersubcommand — the archive format lives ininternal/setup, which Go'sinternal/rule keeps unimportable from outside the module, and reusing the sandbox image means no second artifact to build or keep in lockstep. It is not the daemon: no HTTP server, no lifecycle, no tenant.Chart
0.12.0,goldenUploader.enableddefault off.Testing
Real files, real
tar/zstd, no mocks. 26 tests pass ininternal/setup;go build,go vet,gofmtclean;helm lintclean;bun run fmtclean.node_modulesis skipped, so no partial tree ships.viteexcludedInverted the
build-config-payloadtest that asserted an operator-only payload, since the org is now sent too. FixedsplitGoldenLockDirto return empty strings alongsideok=false— a test caught it handing back a half-parsed key.Chart render verified across: uploader off (nothing), on (DaemonSet + writable PV/PVC, distinct from the tenant's), dynamic path without
pvcName(fails with the reason), dynamic path with it (renders, no PV).Not validated on a real pod. Per the repo norm, "done" is a tailed pod showing an L2 hit; that needs both PRs deployed and
goldenUploader.enabledon, which is adeco-apps-cdchange after these land.Summary by cubic
Adds a node-level
golden-uploaderDaemonSet that moves dependency goldens from each node’s L1 cache to a shared L2 store. Keys are per‑org to prevent cross‑org restores;orgIdnow reaches the daemon and is written beside each golden. Helm chart bumped to 0.13.0 (uploader off by default).New Features
golden-uploadersubcommand) reads a read‑only hostPath and writes to a writable shared store; sequential sweeps with low CPU limits.<pm>-<lock>.tar.zst; existing archives are skipped; remote restore/publish requireorgId..golden-meta.json(orgId/cloneUrl/pm); uploader skips goldens without a readable org.Migration
goldenUploader.enabled: trueand ensuredepsCache.enabledanddepsCache.remote.enabledare true.depsCache.remote.volume.attributes(chart‑provisioned PV/PVC) or setgoldenUploader.pvcNameto an existing claim.depsCache.remote.storageClassName, you must setgoldenUploader.pvcName(the StorageClass cannot express the read‑only/read‑write split).Written for commit ce88414. Summary will update on new commits.