Zero-CRD Pod Lifecycle & Recreate Upgrade State Machine
This article documents how nogoo9 manages pod creation, container overrides, storage binding, annotation processing, shutdown hooks, concurrency quotas, and recreate-style zero-downtime workspace upgrades without requiring Kubernetes CRDs.
🔁 Workspace Lifecycle State Machine
🔒 Quotas & Concurrency Limits (ADR-026)
Before creating a pod, spawn_workspace evaluates user limits in [src/mcp/spawner/handlers/index.ts](file:///home/eterna2/github/nogoo9-no-crd/src/mcp/spawner/handlers/index.ts):
- Configurable Limit: Set via
--max-workspaces-per-userCLI argument orMAX_WORKSPACES_PER_USERenvironment variable (default: unlimited0). - Non-Admin Scope: Quota enforcement strictly targets non-admin callers. Admin users (
isAdmin: true) bypass concurrency caps to allow administrative operations. - Active Pod Counting: Counts running and pending pods matching
nogoo9/user-sub=<owner>across the current namespace.
🛠️ Pod Spec & Annotation Expansion
When spawn_workspace is invoked, nogoo9 constructs a standard Kubernetes Pod object via [src/k8s/spawner.ts](file:///home/eterna2/github/nogoo9-no-crd/src/k8s/spawner.ts) and [src/k8s/annotations.ts](file:///home/eterna2/github/nogoo9-no-crd/src/k8s/annotations.ts):
Labels & Identity:
nogoo9/type:workspacenogoo9/workspace-id:<workspaceId>nogoo9/user-sub:<ownerSubjectId>nogoo9/template-version:<version>
Annotation Expansion Helpers:
validateRequiredContext: Ensures required runtime context keys are provided.injectInitContainer: Pre-populates files/scripts from S3 or ConfigMaps into workspace volumes before container startup.injectPreStopHook: Attaches lifecycle preStop termination hooks to execute log/state synchronization scripts before pod deletion.
🚀 Non-Blocking Recreate-Style Workspace Upgrades (ADR-024)
Workspace upgrades support both 1-by-1 user upgrades and bulk admin upgrades (upgrade_all_workspaces):
- Owner Preservation: The original
nogoo9/user-sublabel is strictly preserved across template version upgrades. - Non-Blocking Background Tasks: Long-running image pull and pod recreation steps run asynchronously without timing out HTTP/MCP tool calls.
- RWO PVC Storage Safety: For pods with ReadWriteOnce (RWO) persistent volume claims,
nogoo9safely deletes the old pod first to release volume locks before spawning the upgraded pod instance. - Event Streaming: Upgrade progress and any failure state (
nogoo9/last-upgrade-error) are broadcast live viaget_workspace_events.
