Skip to content

feat(kubernetes): initContainers, lifecycle hooks, shareProcessNamespace, hostNetwork - #4886

Closed
nathanielheitsch wants to merge 9 commits into
different-ai:devfrom
nathanielheitsch:feat/kubernetes-provisioner-extended
Closed

nathanielheitsch wants to merge 9 commits into
different-ai:devfrom
nathanielheitsch:feat/kubernetes-provisioner-extended

Conversation

@nathanielheitsch

@nathanielheitsch nathanielheitsch commented Sep 11, 2026 •

Copy link
Copy Markdown

Why

This is a follow-up to #4680 (the kubernetes worker provisioner). That PR added 15 optional worker-pod overrides — scheduling, security, metadata, and networking knobs — so operators can run workers on their own clusters with their own registry, node placement, and security constraints. This PR adds the four remaining knobs an enterprise or self-hosted operator may need, completing the customization surface.

What it adds

All optional, all default unset (the manifest is unchanged unless a value is set):

Helm value (config.kubernetes.*) Env var What it does
workerInitContainers KUBERNETES_WORKER_INIT_CONTAINERS init containers that run before the worker (e.g. clone a repo, warm a model cache)
workerLifecycleHooks KUBERNETES_WORKER_LIFECYCLE_HOOKS lifecycle hooks (postStart, preStop) on the worker container
workerShareProcessNamespace KUBERNETES_WORKER_SHARE_PROCESS_NAMESPACE share the pod's process namespace with the worker (sidecars that signal the worker process)
workerHostNetwork KUBERNETES_WORKER_HOST_NETWORK use the host network namespace (inference endpoints reachable only on the node)

shareProcessNamespace and hostNetwork are string "true" in the chart, parsed to boolean in env.ts — consistent with the stringly helm values.

Same collision/provisioner-wins rule as #4680: these are additive, never override the provisioner's own fields.

What is deliberately NOT here

HPA (Horizontal Pod Autoscaler). Workers use ReadWriteOnce PVCs — one worker = one pod. Horizontally scaling a single worker to N replicas would MultiAttach-stall the PVCs (two pods can't mount the same RWO volume simultaneously). The 1:1 model scales by provisioning more workers (one per user), not by adding replicas to one. If an operator wants external autoscaling, they'd scale the number of workers via the API, not a per-worker HPA. So HPA wiring would be misleading here.

Testing

  • tsc --noEmit clean.
  • bun test den-api suite passes (24 files, 129 expect calls, exit 0) — including the new initContainers/lifecycle/shareProcessNamespace/hostNetwork injection test.
  • tests/kubernetes-workers.sh chart render test passes.

Stacking

This branches from feat/kubernetes-provisioner (PR #4680). It should merge after #4680; rebase onto dev once #4680 lands.

Stacking note

GitHub does not allow PRs to stack on a branch that only exists in a fork, so this PR targets dev directly. It branches from feat/kubernetes-provisioner (PR #4680) and contains all of #4680's commits plus one new commit (413cdc2). It should merge after #4680. If #4680 lands first, this PR can be rebased onto dev cleanly (the new commit is isolated to the kubernetes provider's config surface).

Adds PROVISIONER_MODE=kubernetes so self-hosted Den deployments can
auto-provision cloud workers as in-cluster workloads instead of relying
on the Daytona or Render providers.

- kubernetes-client.ts: lean Kubernetes REST client over undici (no new
  dependencies), resolving in-cluster ServiceAccount defaults with
  optional KUBERNETES_API_URL/TOKEN/CA_FILE overrides
- kubernetes.ts: per-worker Deployment, ClusterIP Service, token Secret,
  and workspace/data PVCs named from the worker id; provisioning adopts
  existing objects on conflict, wake patches replicas (and a stale
  image), stop scales to zero preserving PVCs, deprovision deletes the
  full object set
- env.ts: kubernetes config block mirroring the daytona block, with
  KUBERNETES_WORKER_IMAGE required when the mode is selected
- dispatch wiring in provisioner.ts, worker-access.ts, cloud-lifecycle.ts
  (idle stop now covers kubernetes), and routes/workers/shared.ts so the
  mode participates in cloud-instance routing like daytona
- cloud-failure.ts: generalize the health-timeout classifier so
  kubernetes health deadlines map to runtime_health_timeout

Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
- tolerate 409 AlreadyExists on PVC/Secret/Service creates in the fresh
  provision path by verifying the existing object and adopting it, so a
  partial create or half-completed deprovision cannot dead-end reprovision
- default KUBERNETES_WORKER_APPROVAL_MODE to auto; manual mode's gated
  writes time out 403 with no approvals responder in a sandbox
- accept the kubernetes provisioner in the remote-session capability and
  cloud-agent-executor runtime gates; routes/cloud stays daytona-gated
- pin the worker Deployment to Recreate strategy so image patches cannot
  MultiAttach-stall behind a rolling surge pod on ReadWriteOnce PVCs
- redact worker tokens from pod log tails embedded in health-timeout errors
- drop OPENWORK_CONNECT_HOST from the container env; the entrypoint binds
  openwork-server with --host 0.0.0.0 and only used CONNECT_HOST for banners
- substitute the DNS-safe worker name (not the raw worker id) into
  WORKER_URL_TEMPLATE and document the placeholder contract
- patch an adopted Deployment's stale container image before reporting
  healthy so the DB imageVersion matches the running pod
- drop the unused base64 helper and unused getPod client method; add the
  getSecret client method used by the conflict-adopt verify path
- expand provisioning tests: 409 adopt, secret delete/recreate, stale-image
  adopt patch, URL template substitution, deprovision 404 tolerance, and
  token redaction in health-timeout diagnostics

Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
…ourney, and docs

- values.yaml: config.kubernetes block + workers.kubernetes RBAC/namespace
  config; secret.kubernetesApiToken (KUBERNETES_API_TOKEN) in the release secret
- configmap.yaml: emit the KUBERNETES_* surface only in kubernetes mode, with
  the worker namespace pinned so rendered RBAC and API calls agree
- kubernetes-workers.yaml: ServiceAccount, optional worker Namespace, and a
  namespaced Role/RoleBinding (no cluster-scoped objects) for the worker
  namespace; den-api.yaml sets serviceAccountName in kubernetes mode
- tests/kubernetes-workers.sh: default/mode/custom/invalid renders, including
  an assert that no ClusterRole or ClusterRoleBinding is ever rendered
- evals: mock-kubernetes-apiserver witness (create/get/patch/delete, strategic
  merge, labelSelector, logs, readiness toggles) with unit tests, and the
  kubernetes-worker-provisioning journey spec covering provision, idle stop,
  wake, stale-image recycle, deprovision, and stub-mode inertia
- docs: README values section + docs/kubernetes-workers.md operator guide
  (architecture, RBAC, lifecycle, data-erasure semantics, troubleshooting)

Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
…ontent type, fail fast on missing worker image

- RBAC now matches the kubernetes client exactly: get/create/patch/delete
  on deployments (the client never uses update or list), get/create/delete
  on services/secrets/pvcs, and get+list on pods (get is required for the
  pods/log subresource reads used by health-timeout diagnostics)
- mock apiserver only applies strategic merge semantics for PATCH requests
  with application/strategic-merge-patch+json, returns 415 otherwise, and
  records the PATCH content type for journey assertions
- chart render fails loudly when config.provisioner.mode=kubernetes and
  config.kubernetes.workerImage is empty, mirroring the SA-name fail-fast

Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
Completes the deferred PR #2: routes/cloud/index.ts now dispatches
getSandboxRecord / inspectSandbox / refreshSignedPreview / stopCloudWorker
through the provisioner-mode-aware defaults (worker-access.ts) instead of
hard-coding the Daytona implementations, and hasDaytonaProvisioner accepts
kubernetes when KUBERNETES_WORKER_IMAGE is set. cloudAvailable therefore
returns true for kubernetes, so the desktop's GET /v1/cloud/instance
resolves and the auto-provisioned worker option appears.

- worker-access.ts: export defaultGetSandboxRecord / defaultInspectSandbox /
  defaultRefreshSignedPreview + the RefreshSignedPreview type
- cloud/index.ts: use those defaults, kubernetes-aware hasDaytonaProvisioner,
  cloudWorkerImage() for latestVersion / update detection

tsc clean; cloud-instance-route 40/40 pass; den-api suite no worse than
baseline (failures are pre-existing missing-local-MySQL).

Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
opencode stores its session/conversation database under
$XDG_DATA_HOME/opencode. The microsandbox entrypoint defaults
XDG_DATA_HOME to $HOME/.local/share, which is the ephemeral container
filesystem — so conversations died on every pod recreation (verified
live: a session created in the workspace was gone after a pod kill,
while a marker file on the /data PVC survived).

Point XDG_DATA_HOME at /data/opencode-xdg/data (the data PVC, mounted
at /data) so the opencode database lands on durable storage. Verified
live: a conversation survives pod deletion and reappears in the new
pod. No image change needed — the entrypoint already mkdirs the dir.

Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
…ata, networking

Adds 15 optional operator overrides for the worker pod spec so
self-hosted and enterprise deployments can run workers on their own
large clusters with their own scheduling, registry, security, and
network constraints. All default unset, leaving the manifest exactly
as the provisioner built it; no behavior change unless a value is set.

Scheduling: workerNodeSelector, workerTolerations, workerAffinity,
workerTopologySpreadConstraints, workerPriorityClassName.
Security: workerPodSecurityContext, workerContainerSecurityContext,
workerImagePullSecrets.
Metadata: workerPodAnnotations, workerPodLabels.
Networking: workerDnsPolicy, workerDnsConfig.
Extensibility: workerExtraVolumes, workerExtraVolumeMounts, workerExtraEnv.

Object/array values are JSON-encoded in the chart configmap and parsed
by den-api (zod-record/array, not over-constrained). Collision handling
is provisioner-wins: the selector labels (openwork.den.worker-id /
openwork.den.provider), the workspace/data volumes, and the worker env
vars (tokens, runtime config) always override operator entries that
collide; colliding operator extras are dropped with a
kubernetes_provisioner warning rather than failing the provision.

Wired through helm values -> configmap KUBERNETES_* env -> env.ts
kubernetes block -> deploymentManifest. Chart test asserts the new
configmap fields render; unit tests cover injection, label/env/volume
collision dropping, and the no-overrides default.

Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
…ace, hostNetwork

Completes the worker pod customization surface started in the
preceding commit. These four are the remaining knobs an enterprise
or self-hosted operator may need on a large cluster:

- workerInitContainers (KUBERNETES_WORKER_INIT_CONTAINERS): run setup
  sidecars before the worker (e.g. clone a repo, warm a model cache).
- workerLifecycleHooks (KUBERNETES_WORKER_LIFECYCLE_HOOKS): postStart /
  preStop hooks on the worker container.
- workerShareProcessNamespace (KUBERNETES_WORKER_SHARE_PROCESS_NAMESPACE):
  share the pod's process namespace (sidecars that need to signal the
  worker process).
- workerHostNetwork (KUBERNETES_WORKER_HOST_NETWORK): use the host
  network namespace (for inference endpoints reachable only on the node).

All default unset, leaving the manifest unchanged. shareProcessNamespace
and hostNetwork are string "true" -> boolean in env.ts (consistent with
helm values being stringly).

HPA is deliberately not included: workers use ReadWriteOnce PVCs (one
worker = one pod), so horizontally autoscaling a single worker to N
replicas would MultiAttach-stall. The 1:1 model scales by provisioning
more workers, not by adding replicas to one.

Signed-off-by: Nathaniel Heitsch <nathaniel@heitsch.dev>
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

@nathanielheitsch is attempting to deploy a commit to the Different AI Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-landing Ready Ready Preview, v0 Sep 11, 2026 2:07am UTC

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Contributor screen: passed

Commit 413cdc238e · run

No hidden characters, dependency, database or obfuscation concerns.

Nothing else runs yet. A maintainer reviews the changes then comments /test to start the AI screen, the tests and the Warden security review.

@nathanielheitsch nathanielheitsch closed this by deleting the head repository Nov 9, 2026

This branch was successfully deployed

1 active deployment
Preview – openwork-landing — 413cdc23 Deployed Sep 11, 2026 by vercel[bot]
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