Repository navigation
feat: add shareProcessNamespace to pod spec (defaults to true) - #476
alexander-morris wants to merge 2 commits into
Conversation
Enables PID namespace sharing so the Kubernetes pause container becomes PID 1 and automatically reaps zombie processes. Long-running OpenClaw gateway pods spawn background processes (git, QMD memory, shells, plugin activity) which become defunct under a Node.js PID 1 that does not call waitpid(). Over time, zombies accumulate, degrading pod health and causing probe failures. With shareProcessNamespace enabled, the pause container reaps all orphaned processes automatically. Users can opt out with `spec.shareProcessNamespace: false` if needed. Fixes stubbi#471 Signed-off-by: Alexander Morris <[email protected]>
stubbi
left a comment
There was a problem hiding this comment.
Thanks for tackling this Alex - PID-namespace sharing is a clean k8s-native fix for the zombie-reaping issue in #471, and the production validation data is great to see. A few items before this can land:
Required changes
Docs (CLAUDE.md mandates this for every CRD field change):
-
README.md— add an entry to the feature table and ideally a short config snippet showing how to opt out -
docs/api-reference.md— documentspec.shareProcessNamespace: type, default, behavior, security implications
E2E test:
- Add a case under
test/e2e/e2e_suite_test.goverifying that the generated StatefulSet'sPodSpec.ShareProcessNamespacedefaults totrueand can be overridden tofalse. The existinginit-plugins/init-skillscases are good models.
Unit test:
- Add a builder test in
internal/resources/resources_test.gocovering: (a) default true when unset, (b) explicit false, (c) explicit true. See theAutomountServiceAccountTokentests around line 1121 / 8268 / 9351 for the pattern.
.gitignore:
- Remove the
managerline. The standard build output isbin/manager, which is already covered bybin/. A baremanagerat the repo root is a local artifact (likely from runninggo buildoutside Make) and shouldn't ship in the project gitignore - that belongs in your global gitignore.
Discussion / nice-to-have
- Security implication of the default flip: with
shareProcessNamespace: true, every container in the pod can see and signal every other container's processes. For users running sidecars (Tailscale, Ollama, browser), this means a compromised sidecar couldkillthe gateway, and vice versa. This is generally an acceptable tradeoff for the zombie-reaping benefit, but it should be called out in the api-reference doc, and we should make sure existing sidecar containers don't rely on PID-isolation assumptions. - Existing-instance behavior: changing the default to
truewill trigger a pod restart on everyOpenClawInstanceafter upgrade. Worth mentioning in the PR description / changelog so users running production fleets aren't surprised. - Helper redundancy (minor):
shareProcessNamespace()returningPtr(true)when the field is nil is belt-and-suspenders, since the kubebuilder default fillsnil->trueat the API server. Not a blocker - it's defensive against pre-existing instances stored before the CRD upgrade, which is reasonable. - Field placement:
ShareProcessNamespaceis currently appended afterPodAnnotationsin the spec. Consider grouping it near the other pod-level security/runtime fields (e.g. nearSecurityContext-adjacent fields) for better discoverability. Not a blocker.
The core change looks correct and the production data is convincing. Once docs + tests are in and the gitignore line is dropped, this should be ready to merge.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Closing this one out in favor of #485, which picks up your production-validated Thanks for the thorough writeup and for running the 28-agent / 7-hour soak - the data was what convinced me to make the field default to Follow-up: please holler if you'd like to be a reviewer on #485, or if you spot anything in the new docs/tests that drifts from how you actually used the field in production. |
## Summary Adds `spec.shareProcessNamespace` (default `true`) to `OpenClawInstance`. When enabled, all containers in the pod share a PID namespace and the Kubernetes `pause` container becomes PID 1, automatically reaping zombie processes that accumulate under the Node.js gateway (which does not call `waitpid()` on orphaned children). Closes #471. Supersedes #476 — incorporates @alexander-morris's production-validated approach with the docs, unit tests, e2e tests, and field placement requested in [the review on #476](#476 (review)). ## Background [#471](#471) reported 28 defunct processes accumulating under PID 1 on a production OpenClaw pod (QMD, git, shells, plugin helpers). Image-level fixes (`tini` in the entrypoint) are the most durable long-term solution and are tracked upstream at openclaw/openclaw#74083, but operator users have no clean way to wrap the entrypoint today. PID-namespace sharing is the standard Kubernetes-native answer and stacks harmlessly with a future upstream init process. @alexander-morris validated the approach in production (28 agents, 7+ hours, zero zombie accumulation, zero unrelated restarts on 24/28 pods). ## Changes **Core:** - `api/v1alpha1/openclawinstance_types.go` — `ShareProcessNamespace *bool` with `+kubebuilder:default=true`, placed next to `Security` (pod-level runtime/security cluster) per review feedback on #476. - `internal/resources/statefulset.go` — `shareProcessNamespace()` helper; treats `nil` as `true` so instances stored before the field existed still get the fix on next reconcile. **Generated (do not hand-edit):** - `api/v1alpha1/zz_generated.deepcopy.go` - `config/crd/bases/openclaw.rocks_openclawinstances.yaml` - `charts/openclaw-operator/templates/crds/openclaw.rocks_openclawinstances.yaml` **Tests:** - `internal/resources/resources_test.go` — three new builder cases: default-true (field unset), explicit-true, explicit-false. Pattern matches the existing `AutomountServiceAccountToken` tests. - `test/e2e/e2e_suite_test.go` — two new specs in the controller suite: default-true and explicit-false override. Pattern matches the adjacent `runtimeClassName` spec. **Docs:** - `README.md` — new feature-table row and a "Shared Process Namespace" subsection with opt-out snippet and security trade-off. - `docs/api-reference.md` — `spec.shareProcessNamespace` field reference with type/default/behavior, security implication, and upgrade note about pod-template rollout for existing instances. ## Security trade-off (called out in docs) With sharing enabled, every container in the pod can see and signal every other container's processes. A compromised sidecar (Tailscale, Ollama, browser, custom) could send signals to the gateway and vice versa. For most deployments the zombie-reaping benefit clearly outweighs this; users with mutually-distrusting sidecars can opt out per instance and reap inside their image (`tini`/`dumb-init`). ## Upgrade impact Flipping the default to `true` means every existing `OpenClawInstance` will get a one-time pod-template change on next reconcile, rolling pods. Operators running large fleets should plan a maintenance window. Called out in the api-reference upgrade note. ## Test plan - [x] `go test ./internal/resources/` passes (3 new tests covering default/true/false) - [x] `make lint` passes (golangci-lint v1.64.5) - [x] `go vet ./...` clean - [x] `make generate manifests sync-chart-crds` regenerates cleanly (no manual edits to generated files) - [ ] E2E suite passes in CI on a real kind cluster (new specs follow the existing `runtimeClassName` pattern) ## Credit Production validation and original PR by @alexander-morris in #476. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: alexander-morris <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Adds
spec.shareProcessNamespacefield toOpenClawInstanceCRD, defaulting totrue. When enabled, the Kubernetes pause container becomes PID 1 and automatically reaps zombie processes.Problem
Long-running OpenClaw gateway pods spawn background processes (git, QMD memory, shells, plugin activity) which become defunct under a Node.js PID 1 that does not call
waitpid(). Over time, zombies accumulate, degrading pod health and causing probe failures that kill the pod.See #471 for the original report (28 zombies observed on a production pod).
Changes
api/v1alpha1/openclawinstance_types.go: AddedShareProcessNamespace *boolfield with+kubebuilder:default=trueinternal/resources/statefulset.go: AddedshareProcessNamespace()helper, wired into PodSpecTesting
go test ./internal/resources/ -v)/pauseon all podsFixes #471