Kubernetes Generated-Site Memory Safety Implementation Plan
For Codex: Use
superpowers:test-driven-developmentfor each behavior change andsuperpowers:verification-before-completionbefore claiming completion.
Goal: Make future generated-site Deployments advertise realistic memory, roll a single replica without a temporary duplicate, probe a lightweight health endpoint, and spread replicas across nodes.
Scope: Renderer and Kubernetes plugin settings only. Existing Work rows, generated repositories, live Deployments, routes, clusters, and node sizing are explicitly out of scope for this code change.
Design: The renderer defaults memory requests to a 512Mi admission floor, the smallest request above the measured roughly 468–499 MiB low-water working sets. This floor is not a sufficiency claim for sites measured in the 0.4–0.8 GiB range; those need higher measured per-Work requests. Platform-managed sources normalize legacy explicit requests below 512Mi during deploy only after validating the effective request/limit pair; custom clusters retain their values and the full Kubernetes quantity syntax. A settings hook rejects malformed managed quantities, request-over-limit, and new managed request/limit values below the floor. Single-replica Deployments use a surge-free 0/1 rollout, explicitly accepting a brief outage while the replacement becomes Ready; startup keeps / to warm the catalogue, readiness/liveness use /api/health, and a soft hostname topology spread preference applies to the existing pod selector.
Task 1: Lock renderer behavior with failing tests
Files:
- Modify:
packages/plugins/k8s/src/__tests__/manifest.renderer.spec.ts
- Add tests for the
512Midefault and explicit override. - Add tests for single-replica
maxSurge: 0/maxUnavailable: 1, its intentional brief-outage tradeoff, and multi-replica1/0. - Add tests that startup keeps
/for catalogue warm-up while readiness and liveness use/api/health. - Add a test for a soft hostname topology spread preference using the Deployment selector, avoiding tainted-control-plane hard-constraint deadlocks.
- Run
pnpm test -- src/__tests__/manifest.renderer.spec.tsand confirm the new assertions fail for the expected missing behavior.
Task 2: Implement renderer safety defaults
Files:
- Modify:
packages/plugins/k8s/src/manifest.renderer.ts
- Render
512Miwhen no memory request is supplied. - Render a surge-free strategy for one replica while retaining ordinary rolling availability for multiple replicas.
- Preserve the startup probe on
/and point readiness/liveness at/api/health. - Add a hostname topology spread preference with
maxSkew: 1,ScheduleAnyway, and the existing selector. - Re-run the renderer test and confirm it passes.
Task 3: Lock managed-cluster settings behavior with failing tests
Files:
- Modify:
packages/plugins/k8s/src/__tests__/k8s.plugin.spec.ts
- Assert schema defaults without restricting Kubernetes' DecimalSI, BinarySI, or exponent syntax.
- Assert validation accepts
512Mi,0.5Gi, and exponent forms on managed sources and preserves valid custom-cluster quantities. - Assert validation rejects malformed managed quantities, request greater than limit, and managed request/limit values below
512Mi. - Assert deploy normalizes a legacy managed
256Mioverride to512Mi, fails before any API write when the effective limit is too low, and preserves a custom-cluster256Mioverride. - Run
pnpm test -- src/__tests__/k8s.plugin.spec.tsand confirm the new assertions fail for the expected missing behavior.
Task 4: Implement settings validation and legacy normalization
Files:
- Modify:
packages/plugins/k8s/src/k8s.plugin.ts
- Add exact Kubernetes DecimalSI, BinarySI, and DecimalExponent quantity parsing for managed-floor comparisons.
- Add schema defaults without a syntax-narrowing pattern.
- Add
validateSettings()for managed quantity syntax, request/limit ordering, and managed-source minimum request/limit values while leaving custom-cluster validation to its API server. - Normalize legacy sub-minimum managed requests at deploy render time without changing stored Work settings, but fail safely before any API write if the effective limit cannot cover the request.
- Re-run the focused tests and confirm they pass.
Task 5: Verify the complete plugin change
- Run
pnpm test -- src/__tests__/manifest.renderer.spec.ts src/__tests__/k8s.plugin.spec.ts. - Run the package typecheck/build commands exposed by
packages/plugins/k8s/package.json. - Run
git diff --checkand inspect the rendered manifest diff for one- and two-replica inputs. - Record rollback as reverting the renderer/plugin commit; no live resource changes are part of this code commit.