Repository navigation
feat(deploy/k8s): P6 on Kubernetes, slice 1 — container tier on Kind and OpenShift (#423) - #427
Conversation
Design for running the P6 process model (supervisor + forked workers, relay, Redis, MU1 control plane, remote-worker container sandboxes) as Kubernetes workloads on Kind and OpenShift, as a standalone deploy/k8s/ kustomization. Registers it as P6.1 in the milestone registry. Part of epic rossoctl#426. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ress (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…e host (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… and unit (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…s too (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…is (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…d policy (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ain, probes (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…pods Role (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…age tests (rossoctl#423) Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… mock model (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…while disconnected (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… Route (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…s hardening in a test (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…inning, images (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…soctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…keys attach hardening (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…sence, prints access (rossoctl#423) An unreadable TLS Secret or moca-settings aborts the run instead of reading as missing; secret_value (unused) is removed. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…-shot restart (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…search, drain, persistence (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…diagnosable failures (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…rossoctl#423) `kubectl run -i` attaches only once it observes the pod Running, and an attach does not replay output written before it. On a fresh kind cluster the Running event arrived late enough that the generator's four lines were lost: kubectl exited 0 with empty stdout and setup.sh died with "the key generator produced no usable SH_SESSION_TOKEN_PRIVATE_KEY". The generator now waits for its stdin to close, which happens only over the established attach (kubectl forwards the </dev/null it is given), and only then writes. A 60 s timeout bounds the wait if the attach never comes; kubectl's log fallback then reads the lines. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…urs SIGTERM (kind e2e, rossoctl#423) As the container's PID 1, Node has no default SIGTERM action, so the mock ignored the stop signal and held every supervisor pod for the full 120 s termination grace, long after the supervisor had drained and exited (crictl: supervisor Exited, mock-model Running). Every rollout and the smoke's drain claim paid that, and a later smoke run could pick the lingering pod for its drain check. Exiting on SIGTERM alone would break the drain: a plain container gets the signal together with the supervisor, so the model would vanish under the turn the supervisor is still finishing. The mock is therefore a native sidecar (an init container with restartPolicy Always), which the kubelet stops only after the supervisor has exited. Pod deletion now takes the 5 s preStop, and the drain claim still passes. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ive pod (kind e2e, rossoctl#423) `kc ... &` backgrounds a subshell running the kc function, so $! and the kill hit the subshell and orphaned kubectl. The orphans kept 18080/18081/ 18090 bound: the re-forward after the drain claim could not bind and the smoke silently kept talking to the old, terminating pod, and the processes outlived the smoke. kc_exec execs kubectl, so the background job is kubectl itself. The drain claim also took .items[0], which on a re-run within the grace period was the pod the previous run had deleted: deleting it again proved nothing. It now picks a pod with no deletionTimestamp. The restart claim also counts init-container restarts, now that the kind-ci mock model is a native sidecar. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…IPE-prone grep (kind e2e, rossoctl#423) Claims 4 and 10 piped `kubectl exec ... redis-cli --scan` into `grep -qx`. grep -q exits at its first match; when session:<sid> was listed before session:<sid>:seq, kubectl died of SIGPIPE writing the rest, and under pipefail the present key failed the claim (PIPESTATUS 141 0, seen on kind). The check is now an exact `redis-cli EXISTS session:<sid>`, the same assertion without the race. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…box detaches (rossoctl#423) The relay wrote a sandbox's presence record once, at Hello, and dropped a failure. If Redis was not reachable when the sandbox attached -- routine on Kubernetes, where setup.sh applies every workload at once -- the stream stayed attached, the worker never re-Hello'd, and sh:sandbox:records never listed it, so no turn could lease it and setup.sh died waiting for presence (Task 16, C1). The put now retries with exponential backoff (250 ms doubling to a 10 s cap, no attempt limit) for as long as that same session stays attached. Each attempt first checks that the session map still holds the exact session object created for the stream, so nothing is written after teardown's remove, nor on behalf of a later reattach under the same id; teardown also cancels the pending timer. Each failure logs one line with the (already redacted) message. Timers are injectable through RelayDeps.timers so the tests do not wait. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…onger crash the worker (rossoctl#423) makeRuntimeReporter built its node-redis client with no 'error' listener. node-redis re-emits a dropped socket as 'error' on the client, and with no listener that is an uncaught exception, so every worker that had served a turn exited on a Redis restart and took its in-flight turns with it (Task 16, C2: worker_exit code 1 after deleting redis-0). The reporter's try/catch covers its awaited commands, not the emitter. The client now gets a one-line, message-only 'error' listener, paired with a bounded reconnect: with a listener but node-redis's default strategy a refused connect() never settles, and the reporter's catch could never re-arm. Past the bound the next command rejects ClientClosedError and the existing catch rebuilds the client. knative-server does not depend on @moca/session-backend, so the pairing is inline, as in RedisRecordStore and RedisWorkQueue. The createClient sweep found one more worker-process client without a listener: getBundleRedis in harness/src/run-leaf.ts (POST /runs with a configRef), memoised for the process's life. It now uses resilientClientOptions + swallowRedisErrors (harness already depends on session-backend) and re-arms when the client has given up (!isOpen). It is exported for its test. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…n gives up (rossoctl#423) Past the reconnect bound node-redis closes the client for good while ready stays resolved, so the relay's one long-lived store rejected every presence put/remove after a Redis restart. connectOnce now reconnects the same client when it is no longer open; a closed flag keeps a store closed on purpose (dropMemo) from being reopened, and close() is idempotent. Corrects the relay.ts comment on ordering and re-arm. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…sion never exit silently (rossoctl#423) A re-run reset every input it was not given: moca-settings was rebuilt from the environment only, the control plane went to 0 replicas without SH_GITHUB_CLIENT_ID, SH_SANDBOX_COUNT fell back to 2 and the OCP image override vanished. write_settings now keeps the stored value of each unset variable (an explicitly empty one still clears it) and replica and wait decisions use the resolved client id. SH_SANDBOX_COUNT and, on OCP, --image/--sandbox-image persist in the non-secret ConfigMap moca-setup. A failed read of either ConfigMap aborts the run. Value flags with no value and unrecognised `kind version` output now die with a message. setup.test.sh also asserts the Kind applies really ran with --context kind-moca, for kind and kind-ci. README documents sticky inputs, how to clear one, and that kind create cluster switches the current context. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…l#423) cleanup kept $OUT only when FAIL>0, so an early exit 1 (a port-forward that never came up) or a set -e death in claims 10 and 11 deleted the logs of exactly the runs that needed them. cleanup now captures the exit status first and keeps $OUT when rc != 0 or FAIL > 0; *.hdr files are still always removed. Claims 10 and 11 and the post-drain forward turn kubectl errors into FAIL lines, so the run reaches its summary. New cluster-free tests/smoke.test.sh pins all three paths. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… yaml devDependency (rossoctl#423) The earlier regeneration also rewrote every vitest peer suffix and dropped the rollup libc fields. The lockfile is now upstream/main's plus the packages/supervisor yaml importer entry, and pnpm 9 (the version CI pins) installs it with --frozen-lockfile. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ecret and Redis probe wording (rossoctl#423) Spec §10's restricted-v2 row now matches README §9.1: the fallback drops runAsUser, runAsGroup and fsGroup so restricted-v2 assigns all three, and says why keeping fsGroup fails. "The only Secret in moca-sandbox" becomes "the only Secret any MOCA object references", since OpenShift adds per-ServiceAccount pull Secrets (README §6, namespaces.yaml, spec §2.1/§3.3/§9.2, a setup.sh comment). Spec §3.4's probe is `redis-cli ping | grep -q PONG`, because redis-cli exits 0 on NOAUTH. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ossoctl#423) SH_ADMIN_HOST is 0.0.0.0 on Kubernetes and loopback on the VM; the log line is how an operator sees which one a pod bound. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ectl kustomize (rossoctl#423) The per-run overlay (Route hosts, image overrides, replicas, settings hash) was only checked as text. generated-overlay.test.ts now writes it with setup.sh's own write_overlay (sourced by a fixture, so the two cannot drift) into deploy/k8s/.generated/test-ocp, renders it, and asserts both Route hosts, the image tag and digest rewrites, replicas 1 and 3, and the settings-hash annotation. write_overlay takes an optional output directory for this. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…k passes (rossoctl#423) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ossoctl#423) main passes .generated/$TARGET, so shellcheck no longer flags an argument no caller passes (SC2120); generated-overlay.test.ts passes its own. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
Reviewed in full — manifests, setup.sh, smoke.sh, CI workflow, and the TS resilience changes with their tests. (Posted as COMMENT rather than APPROVE only because GitHub refuses approval on one's own PR.)
What this is: slice 1 of epic #426 — the P6 runtime (supervisor + forked workers, relay, Redis, MU1 control plane, remote-worker sandboxes) as ordinary Kubernetes workloads from a new standalone deploy/k8s/ kustomization, on Kind and OpenShift, plus the Redis-resilience fixes the substrate exposed (re-arm after node-redis gives up, 'error' listeners on every long-lived client, credential redaction from Redis URLs, relay presence retry, control-plane fast-fail /readyz).
Checked: security contexts and the two-way default-deny + per-workload NetworkPolicies; the split relay attach/exec Services and the sandbox-namespace secret boundary (attach token only); setup.sh's secret discipline (server-side apply, no value on argv, never-rotate semantics, sticky inputs — all pinned by the mock-based bash tests, including the argv-leak and failed-GET-doesn't-rotate assertions, which are exactly right); smoke.sh's token-in-file handling and log retention on failure; the CI workflow (SHA-pinned actions, sha256-verified kind, contents: read only); Redis URL redaction with tests asserting the password never appears in errors or logs.
Only nits/suggestions inline — nothing blocking. The test discipline in this PR is exceptional.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: K8s manifests, Shell, CI/GitHub Actions, TypeScript, Docs, Tests
Agent/IDE config (.claude/.vscode): none
Commits: 43, all DCO-signed
CI status: all 14 checks passing (k8s-kind-e2e green)
Assisted-By: Claude Code
| TARGET=kind-ci | ||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --target) TARGET="${2-}"; shift 2 ;; |
There was a problem hiding this comment.
nit: --target given without a value exits silently — shift 2 with one argument left fails under set -e with no message. setup.sh guards exactly this with need_value (its comment even names the failure mode); the same guard here would be symmetric.
There was a problem hiding this comment.
Fixed in 471203f. smoke.sh now uses the same need_value guard as setup.sh, so --target with no value exits 2 with smoke.sh: --target needs a value. There is a test in deploy/k8s/tests/smoke.test.sh; it fails on the previous code, which ignored the missing value and ran the whole smoke.
| import { createClient, type RedisClientType } from 'redis'; | ||
|
|
||
| /** | ||
| * Inline implementation of redactUrl (canonical copy at @moca/session-backend). |
There was a problem hiding this comment.
suggestion: this inline copy of redactUrl can drift from the canonical one in @moca/session-backend (which harness/src/redact-url.ts re-exports), and the session-backend tests won't exercise this copy. The no-dependency rationale is documented, but a shared micro-package — or a test pinning both copies to the same fixtures — would keep the security-relevant redactor single-sourced.
There was a problem hiding this comment.
Addressed in c869648, without adding a package dependency: both copies now run one shared fixture, packages/session-backend/test/fixtures/redact-url-cases.json (6 cases, now including a percent-encoded password). The canonical tests in session-backend iterate it, and a new packages/work-queue/test/redact-url-parity.test.ts runs work-queue's inline copy (exported from queue.ts for the test only, not from the package index) against the same file. I checked that it bites: changing the inline copy's replacement made 4 of 7 cases fail. A shared micro-package would be the next step if a third copy ever appears.
| type: RuntimeDefault | ||
| containers: | ||
| - name: redis | ||
| image: docker.io/redis:7-alpine # the tag deploy/vm/setup-vm.sh pins |
There was a problem hiding this comment.
suggestion: docker.io/redis:7-alpine is tag-pinned while the OCP overlay digest-pins ghostunnel. For a workload that holds sh:sandbox:records and the session store, consider digest-pinning Redis too (the tag in deploy/vm/setup-vm.sh can stay the source of the version, with the manifest resolving it to a digest).
There was a problem hiding this comment.
Done in d273769. Redis is now docker.io/redis:7-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499, the tag's multi-arch index. The registry and the Docker Hub API agree on it (pushed 2026-09-21). It is set through the base images: transformer, which carries it into every overlay. The tag stays deploy/vm/setup-vm.sh's: a manifest test asserts the pin is tag@digest and that the tag appears in setup-vm.sh, so a tag bump on the VM path fails CI until the digest moves too. The kustomization comment says how to move it.
review) The same need_value guard setup.sh uses: a value flag given last made shift 2 fail under set -e with no message. Tested in smoke.test.sh. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ossoctl#427 review) Both copies now run one shared fixture (session-backend/test/fixtures/redact-url-cases.json), so a change to either that the other does not match fails a test instead of drifting. work-queue keeps its no-dependency inline copy; it is exported from queue.ts for the test only. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
docker.io/redis:7-alpine@sha256:858f009f…3499 (the tag's multi-arch index) through the base images transformer. The tag stays deploy/vm/setup-vm.sh's; a manifest test asserts the pin is tag@digest and that the tag matches the VM path's. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…le token TTLs (#432) Follow-ups from the OpenShift acceptance run (#423) and the #427 reviews. - --target ocp writes .generated/ocp/moca-ca.crt: the supervisor's certificate when it is self-issued, plus the cluster's default ingress CA (openshift-config-managed/default-ingress-cert ca-bundle.crt), which signs the control plane's edge Route. Reading the ingress CA is best effort; a failure is a warning. - The supervisor CA file is rebuilt from the Secret's tls.crt on every run (ocp and ocp-single), and print_access prints the NODE_EXTRA_CA_CERTS line on every run, so a re-run or a second checkout repeats it. - SH_API_TOKEN_TTL_SECONDS and SH_SESSION_TOKEN_TTL_SECONDS are sticky moca-settings keys read by the control plane; empty means its default. A malformed value is refused, given or stored. Fixes #432 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
--target kind and --target kind-ci share one Kind cluster, hence one moca-settings. Since settings became sticky (#427), a kind run after a kind-ci run read the CI placeholder Iv1.k8s-smoke-unused back as if an operator had set it: the control plane came up at 1 replica with an id nobody can log in with, instead of 0 replicas and the "no client id" warning. The placeholder predates stickiness, which retroactively turned a render-time default into persisted configuration. Name the placeholder CI_CLIENT_ID and discard it on read-back when the target is not kind-ci, the same shape public_harness_url already uses to drop a stored value that no longer suits the target. kind-ci re-derives it every run, so the key stays present and non-empty (base/control-plane .yaml refs it without optional: true, and the control plane's required() rejects an empty value), the ConfigMap keeps its ten-key shape, and the settings hash is byte-identical across the change -- a kind-ci re-run still converges without rolling a pod. Fixes #429 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Summary
Slice 1 of epic #426 (closes the build part of #423): the P6 runtime as ordinary Kubernetes workloads. That is the supervisor with its forked workers, the relay, Redis, the MU1 control plane and
remote-workercontainer sandboxes, on Kind and OpenShift, from a new standalonedeploy/k8s/kustomization. It shares nothing withdeploy/knative/. ADR-0037 records that this is P6 on a Kubernetes substrate, not the Knative path that RA1 deprecates.Spec:
docs/specs/2026-10-02-p6-on-kubernetes-slice1-design.md(v1.1, with implementation notes in §0.1).What's in it
Manifests (
deploy/k8s/base,overlays/{kind,kind-ci,ocp})moca,moca-sandboxandmoca-credentials, all Pod Securityrestricted. Each has a two-way default deny, with a NetworkPolicy per workload in place of the VM's nftables andisolate=strict.preStoppause, and its probes use the new admin/healthzand/readyz.redis.conf(never on argv), AOF on a PVC, and only three callers can reach it.SANDBOX_ID. The only Secret any MOCA object references in that namespace is the attach token. Egress is the open internet, minus private, CGNAT and link-local ranges.deploy/k8s/setup.shkind-mocakube context.deploy/k8s/smoke.shCI
.github/workflows/k8s-e2e.yml: Kind v0.33.0, pinned by sha256, runningsetup.sh --target kind-ci --buildplus the smoke.Code changes (small, and the same on the VM and Compose paths)
SH_ADMIN_HOST(default loopback), plus/healthzand/readyzon the admin listener./readyzfails fast while disconnected.RedisRecordStore: re-arms after an established connection gives up, so presence survives a Redis restart.'error'listeners, so a Redis restart no longer crashes workers mid-turn.Testing
make lint,make typecheck,make test-deployandpnpm -r testare green at the head.packages/supervisor/test/k8s/run on realkubectl kustomizeoutput for every overlay, and for a generated OCP overlay produced bysetup.sh.setup.sh --target kind-ci --buildand then the smoke gave PASS=11 FAIL=0, twice. Re-runningsetup.shchanged no pods and no secrets. An earlier throwaway-cluster spike verified kubelet probes under default-deny, Redis under its configured UID, sandbox attach, port-forward and sandbox isolation.HTTPS_PROXYbeforekind create, and point CoreDNS at public resolvers.Not done here
deploy/k8s/README.md§9, and its results will go on P6 on Kubernetes, slice 1: supervisor, relay, Redis, control plane and container sandboxes as K8s workloads #423.RedisRecordStore's re-arm, for a microtask-window race;/metrics, which would make the OpenShift L4 check direct.4787374is missing itsAssisted-Bytrailer; history was left unrewritten.🤖 Generated with Claude Code