Skip to content

feat(homelab): route RAM workspace claims to the RAM pool or, explicitly, to NVMe - #5496

Draft
shepherdjerred wants to merge 4 commits into
ci-ram-poolfrom
ci-ram-workspace-route
Draft

shepherdjerred wants to merge 4 commits into
ci-ram-poolfrom
ci-ram-workspace-route

Conversation

@shepherdjerred

Copy link
Copy Markdown
Owner

Why

The RAM pool from #5495 needs a storage class, and every RAM workspace claim needs one decision: clone the pool's own golden workspace (ZFS clones only within a pool), or run on NVMe because the pool is absent, unseeded or full. Two overlapping full-graph verifies can exceed the 24 GiB pool, so a claim must stop going to RAM before the pool fills.

PR 2 of 5. Nothing routes to these classes until the agents (PR 4a) and the woodpecker-ram-workspace-enabled flag (PR 4b).

Rollout order. Merging PR 4b is the rollout: its production override turns woodpecker-ram-workspace-enabled on, so lanes route as soon as it syncs; there is no later switch-on step. So the gates come before merges: the server-side dry-run compile of the routing CEL (Verification below) must pass before this PR merges, and the canary in the liskov README must pass before PR 4b merges.

What

  • Storage classes ci-workspace-ram (workspaces) and ci-golden-ram (the RAM golden claim): thin, zstd-1, Delete, liskov only. RAM workspaces are 12Gi, the per-clone quota.
  • The ci-ram-pool pod's pool container writes the pool's health, GUID and free space every 15 s. A new unprivileged ci-ram-pool-route container publishes ConfigMap ci-workspace-route from that and both golden ConfigMaps: ready, full (under the 12Gi quota plus 2 GiB free), seeding (no golden for this pool generation, as after every reboot) or absent (missing, not ONLINE, or stale). An API error stops the publisher instead of publishing a guess.
  • The publisher is the only container with a service-account token: the pod sets automountServiceAccountToken: false and a projected token (with the cluster CA) is mounted only in ci-ram-pool-route, so the privileged pool container has none. Every kubectl call carries --request-timeout=10s. Each publish writes publishedAt (epoch seconds), so the ConfigMap's resourceVersion changes every 15 s even on an idle pool, and records a heartbeat; a liveness probe restarts the publisher once its last successful publish is 60 s old. publishedAt is informational: the routing CEL requires only its six routing keys, and a test pins that.
  • One mutating policy routes every unsourced ci-workspace-ram claim, so there is no reinvocation ordering with the NVMe clone policy. ready clones the RAM golden and labels ci.sjer.red/workspace-route=ram. Any other state, or a missing ConfigMap, makes it a 32Gi ci-workspace claim cloned from the NVMe golden, labelled nvme-degraded. Every claim also carries ci.sjer.red/workspace-route-state and, when degraded, a reason annotation. Guards reject a RAM claim that is not a labelled 12Gi RAM-golden clone, and an NVMe claim cloned from a RAM golden.
  • Degraded mode is explicit, not a silent fallback. The repository's rule is that missing required infrastructure fails loudly rather than being papered over. The RAM pool is not required for any workflow to be correct: it is a wear optimization, and the NVMe path it degrades to is the same fully supported path every other workflow uses. Every degraded claim is labelled with its state and reason, counted, and alerted, and the flag is the off switch. The wiki's CI admission explanation says this.
  • Alerts. Routing to NVMe because the pool is full is routine, so it is tracked, not paged:
    • CIRamWorkspaceUnavailable (warning) fires when claims are routed to NVMe for 15 minutes as absent, seeding or unpublished: an outage, or a reseed that is not finishing.
    • ci_workspace:ram_route_claims:count6h and ci_workspace:ram_route_share:ratio6h record each state's share. A panel draws it beside the CI pool writer budgets.
    • CIRamPoolUndersized records a capacity finding in the Alerts ledger without email (a new category = "ci-capacity" route) when the full share stays above 36% of at least 20 claims for 30 minutes. PR 1's CIRamPoolOverReservation moves to the same ledger-only route.
    • CIRamRouteStale (warning) fires when kube_configmap_metadata_resource_version for woodpecker-ci/ci-workspace-route has not changed in 5 minutes for 10 minutes: nothing is publishing, and the policy would keep applying the last route. kube-state-metrics already exports the series (configmaps are a default collector; the metric is listed in its configmap docs).
  • kube-state-metrics exports both claim labels and the route ConfigMap's state label. That is Delivery configuration prometheus/prod/16: it changes from main's /15 only by the allowlist (/14's deployments= entry kept) and the ledger route. ops-verify (FM-322) confirms nothing else claims /15. The rollout owner registers and rebinds it after merge (toolkit deploy catalog reconcile --machine, then toolkit deploy rebind prometheus/prod --configuration prometheus/prod/15).

Demo

No claim made today is evaluated by the new CEL.

  • The routing mutation matches only has(object.spec.storageClassName) && object.spec.storageClassName == 'ci-workspace-ram' with no data source, and its guard matches only that class. A test pins both. No agent creates such a claim until PR 4a/4b.
  • The existing NVMe clone policy is untouched. Rendered from main and from this branch, its mutation, guard and bindings are identical:
$ diff clone-policy-main.yaml clone-policy-pr2.yaml && echo identical
identical

An earlier commit on this branch had added a RAM-snapshot exclusion to the NVMe guard. That would have put new CEL on every CI claim, so it was reverted. The routing policy never names a RAM snapshot for an NVMe claim, and the ZFS driver refuses cross-pool clones anyway.

Routing decisions from the real publisher script, run against a fake kubectl (workspace-route.test.ts):

pool status RAM golden route state claim becomes
ONLINE, 20 GiB free this pool generation ready ci-workspace-ram 12Gi, clone of ci-workspace-golden-ram-…, route=ram
ONLINE, 14 GiB − 1 byte free (a first large verify has grown) this pool generation full ci-workspace 32Gi, clone of the NVMe golden, route=nvme-degraded
ONLINE, exactly 14 GiB free this pool generation ready RAM
ONLINE previous pool generation (after a reboot), or none seeding NVMe, degraded
missing, older than 60 s, MISSING or SUSPENDED any absent NVMe, degraded, with the reason
ConfigMap read fails — — publisher exits non-zero; nothing applied

Expected full-routed share, the basis for the 36% threshold (Monte Carlo, .spike/full_share_sim_a12.ts, rerun for PR 1's ashift 12):

  • Inputs: two verify slots busy, golden 6.06 GiB on the pool, the measured verify mix, and unique data per run of 1.1, 2.3 and 8.0 GB (base, Rust, full graph) at the measured zstd-1 ashift-12 ratio. Sites, scout-site-archives and tofu-validate run at their daily rates.
  • Run durations are estimated from the tiers.ts p50 and p90.
case full share
shorter Rust and full-graph runs 11.8%
measured mix (today) 15.3%
twice today's full-graph share, 25-minute full-graph runs 36.3%

The simulated pool peaks at 21.9 GiB and never reaches the 24 GiB cap at today's two-verify concurrency. A sustained full share above 36% means the mix is heavier than the pessimistic case: the pool is undersized.

Alert tests (promtool):

  • Unavailable fires after 15 minutes of seeding-routed claims. It stays quiet for a pool that is full all day.
  • Undersized fires at 70% of 20 claims after 30 minutes. It stays quiet at 20%, and at 67% of only 15 claims.
  • RouteStale fires 15 minutes after the route stops changing (pending at 10 minutes of no change), and stays quiet while the publisher keeps stamping publishedAt on an idle pool.

Verification

  • Required before this PR merges (operator, live API server, persists nothing): compile every rendered admission policy with a server-side dry run, and block the merge on any Invalid value or compilation error:
    cd packages/homelab/src/cdk8s && bun run build
    OUT=$(mktemp)
    yq 'select(.kind | test("AdmissionPolicy"))' dist/cluster-admission.k8s.yaml > "$OUT"   # 34 objects
    kubectl apply --server-side --dry-run=server --force-conflicts --field-manager=admission-preflight -f "$OUT"
    After the sync, status.typeChecking on woodpecker-workspace-route.sjer.red and woodpecker-workspace-route-guard.sjer.red must be empty.
  • Required before PR 4b merges (merging it is the rollout): the canary in the liskov README ("Canary the RAM workspace routing"). It reads back the mutated canary claims for ready, absent and ready again, using a canary binding and ConfigMap the production binding skips (ci.sjer.red/workspace-route-canary).
  • bunx turbo run build typecheck test lint --filter=@homelab/cdk8s --filter=homelab --filter=@shepherdjerred/ops-model: pass.
  • bun run generate:catalog: prometheus/prod/16 as above. bun run check:kubeconform (packages/homelab): 1531 resources, 0 invalid.
  • bunx turbo run jscpd quality-ratchet knip --filter=//: jscpd and quality-ratchet pass; knip fails only on an unused @base-ui/react in packages/mail/package.json from main's feat(mail): shared console shell, banner, description list and email preview #5483, which this stack does not touch. bunx lefthook run pre-commit: pass.
  • bun run verify:extended -- --filter='...[origin/main...HEAD]': 72/72 at the pre-rebase stack top (ce27b2e17e); to be re-run on the final heads before any PR is marked ready.
  • Not run: the routing CEL is checked as rendered text, not evaluated (no local evaluator); the API server compiles it when ArgoCD applies it. No live routing happens before PR 4b.

🤖 Generated with Claude Code

shepherdjerred and others added 4 commits November 28, 2026 15:03
…tly, to NVMe

Why
The RAM pool from the previous change needs a storage class, and every RAM
workspace claim needs one decision: clone the pool's own golden workspace, or
run on NVMe because the pool is absent, unseeded or full. ZFS clones only
within a pool, so the NVMe golden cannot serve a RAM claim. Two overlapping
full-graph verifies can exceed the 24 GiB pool, so a claim must stop going to
RAM before the pool fills, not after.

What
- Storage classes `ci-workspace-ram` (workspaces) and `ci-golden-ram` (its
  golden claim), both thin, zstd-1, Delete, liskov only; RAM workspaces are
  12Gi, the per-clone quota.
- The ci-ram-pool DaemonSet's pool container writes the pool's health, GUID
  and free space every 15 s; a new unprivileged `ci-ram-pool-route` container
  turns that and both golden ConfigMaps into `ci-workspace-route`: `ready`,
  `full` (under the 12Gi quota plus 2 GiB free), `seeding` (no golden for this
  pool generation, as after every reboot) or `absent` (missing, not ONLINE, or
  stale). An API error stops the publisher rather than publishing a guess.
- One mutating policy routes every unsourced `ci-workspace-ram` claim from that
  ConfigMap, so no ordering with the NVMe clone policy matters: `ready` clones
  the RAM golden and labels `ci.sjer.red/workspace-route=ram`; anything else,
  or a missing ConfigMap, becomes a 32Gi `ci-workspace` claim cloned from the
  NVMe golden, labelled `nvme-degraded` with a reason annotation. Guards reject
  a RAM claim that is not a labelled 12Gi RAM-golden clone, and an NVMe claim
  cloned from a RAM golden.
- `CIRamWorkspaceDegraded` fires after 15 minutes of degraded claims. The
  kube-state-metrics allowlist gains the claim route label and the route
  ConfigMap's state label, keeping /14's `deployments=` entry: Delivery
  configuration prometheus/prod/15.
- Wiki `ci-admission.md` explains the routing and why the degraded mode is
  not a silent fallback; the liskov README covers the publisher.

Verification
- bunx turbo run build typecheck test lint --filter=@homelab/cdk8s
  --filter=homelab --filter=@shepherdjerred/ops-model: 37/37 pass.
- workspace-route.test.ts runs the real publisher script against a fake
  kubectl: ready; full one byte under 14 GiB (and ready at exactly 14 GiB);
  seeding after a pool-generation change; absent for missing, stale, MISSING
  and SUSPENDED status; no NVMe source when none is selected or the name is a
  RAM golden; an API error exits without applying.
- bun run generate:catalog: prometheus/prod/15 differs from /14 only in the
  kube-state-metrics label allowlist.
- bun run check:kubeconform (packages/homelab): 1531 resources, 0 invalid.
- bunx lefthook run pre-commit: pass.
- Not run: the CEL is checked as rendered text, not evaluated (no local
  evaluator); the API server compiles it when ArgoCD applies it. No live
  routing happens until the agents and flag in later changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and track the full share

Why
Routing a claim to NVMe because the RAM pool is full is routine: at the
measured mix about 12% of claims find the pool full. An alert on every
degraded claim would fire most of the day.

What
- Every routed claim also carries `ci.sjer.red/workspace-route-state`, the
  state it was decided in (ready, full, seeding, absent, or unpublished when no
  route was published), added in one labels patch when the claim has none.
- `ci_workspace:ram_route_claims:count6h` and
  `ci_workspace:ram_route_share:ratio6h` count each claim once over 6h by
  state; a share panel sits beside the CI pool writer budgets.
- `CIRamWorkspaceUnavailable` (warning) replaces `CIRamWorkspaceDegraded`: it
  fires only for claims routed to NVMe for 15 minutes as absent, seeding or
  unpublished.
- `CIRamPoolUndersized` records a capacity finding in the Alerts ledger
  without email (new `category = "ci-capacity"` route) when the full share
  stays above 30% of at least 20 claims for 30 minutes. 30% is the top of the
  sizing model's 9% to 30% range (12% at the measured mix).
- kube-state-metrics exports the new claim label; prometheus/prod/15 now
  carries the allowlist and the ledger route.

Verification
- bunx turbo run build typecheck test lint --filter=@homelab/cdk8s
  --filter=homelab --filter=@shepherdjerred/ops-model: pass.
- promtool tests: the 6h counts and shares count each claim once; Unavailable
  fires after 15 minutes of seeding-routed claims and stays quiet for full and
  briefly unpublished routing; Undersized fires at 70% of 20 claims after 30
  minutes and stays quiet at 20% and with only 15 claims.
- Alert routing test: ci-capacity warnings go to alerts-ledger-only, CI
  warnings to alerts.
- bun run generate:catalog: prometheus/prod/15 differs from /14 only in the
  kube-state-metrics allowlist (keeping deployments=) and the ledger route.
- bun run check:kubeconform: 0 invalid; jscpd, quality-ratchet, knip: pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…te it on a compile check and canary

Why
The routing CEL is checked only as rendered text, and the NVMe clone guard
that every CI workspace claim passes through had gained a new expression. A
bad expression there would break golden clones for all of CI.

What
- Revert the NVMe clone guard's RAM-snapshot exclusion: the NVMe clone
  mutation and guard render byte-identical to main again. The routing policy
  never names a RAM snapshot for an NVMe claim, and the ZFS driver refuses a
  cross-pool clone anyway.
- The routing mutation and its guard match only `ci-workspace-ram` claims (the
  mutation also only unsourced ones); a test pins the exact matchConditions.
  No agent creates such a claim before the RAM agents and flag land.
- The production routing binding skips claims labelled
  `ci.sjer.red/workspace-route-canary`, so an operator's canary binding and
  ConfigMap can route a canary claim without touching the live route.
- liskov README: a server-side dry-run compile check of every rendered
  admission policy before merge, and a canary that reads back the mutated
  claim for ready, absent and ready again before the flag routes work.

Verification
- bunx turbo run build typecheck test lint --filter=@homelab/cdk8s
  --filter=homelab: 33/33.
- Rendered NVMe clone policy (mutation, guard, bindings) from main and from
  this branch: identical.
- The dry-run file selection lists all 34 admission objects, including the
  route policy and guard.
- Not run: the dry run and the canary themselves (operator, live API server).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ert when it stops publishing

Why
The whole ci-ram-pool pod mounted a service-account token, so the privileged
pool container held API credentials it never uses. Nothing bounded the
publisher's API calls, and an idle pool published an unchanged route, so a
hung or dead publisher was indistinguishable from a quiet one while the
routing policy kept applying its last route. PR 1's ashift 12 also moved the
full-share model behind CIRamPoolUndersized.

What
- The pod sets automountServiceAccountToken: false; a projected token and the
  cluster CA are mounted only in ci-ram-pool-route, at the path kubectl's
  in-cluster configuration reads.
- Every publisher kubectl call carries --request-timeout=10s. Each publish
  writes publishedAt (epoch seconds), so the route ConfigMap's resourceVersion
  changes every 15 seconds, and a heartbeat; a liveness probe restarts the
  publisher once its last successful publish is 60 seconds old. The routing
  CEL still requires only its six routing keys, so publishedAt is tolerated; a
  test pins that.
- CIRamRouteStale (warning, 10m): changes() of
  kube_configmap_metadata_resource_version for woodpecker-ci/ci-workspace-route
  over 5m is 0. kube-state-metrics' configmap collector exports the series, so
  the prometheus/prod Helm configuration does not change.
- CIRamPoolOverReservation moves to the ci-capacity ledger-only route this
  branch adds.
- Full-share model rerun at ashift 12 (golden 6.06 GiB, unique data per verify
  1.1 / 2.3 / 8.0 GB): about 15% of claims find the pool full, 12% to 36%
  across the sensitivity range, so CIRamPoolUndersized's threshold moves from
  30% to 36%, the top of that range as before.
- Wiki and liskov README: merging the flag's change is the rollout (its
  production override is on), so the server-side dry-run compile comes before
  the routing policy merges and the canary before the flag's change merges;
  the publisher's token, timeout, heartbeat and stale alert.

Verification
- bun run scripts/run-test.ts (packages/homelab/src/cdk8s) over
  src/resources/monitoring, src/resources/woodpecker, ci-ram-pool,
  cluster-baseline, kueue-config, src/misc, grafana/storage, backup-policy,
  helm-template and argo-applications/observability: 93 files, 621 tests
  pass, including promtool tests for CIRamRouteStale and the publisher tests
  for publishedAt, the heartbeat and the request timeout.
- bunx turbo run build typecheck lint --filter=@homelab/cdk8s: pass.
- bun run generate:catalog: no change to the prometheus/prod registration.
- bunx lefthook run pre-commit: pass.
- Not run: the server-side dry-run compile and the canary (operator, live API
  server); no live change was made.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shepherdjerred

Copy link
Copy Markdown
Owner Author

@greptile-apps

greptile-apps Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository. Configure in Code Review Settings.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant