Repository navigation
feat(k8s): run one shared supervisor per node - #6074
Gal-Zaidman wants to merge 18 commits into
Conversation
|
@FrostGod can you please review? |
f016810 to
62c3514
Compare
|
sure @Gal-Zaidman , I can look into this sometime in the first half of the week. |
BlockedThe required Branch Checks and Helm Lint runs for this fork PR are awaiting GitHub Actions approval. The first team code review is deferred until the workflow approval blocker clears. Action required: A maintainer needs to approve the Branch Checks and Helm Lint runs in GitHub Actions. Gator metadata
|
There was a problem hiding this comment.
gator-agent
PR Review Status
The workflow approval blocker cleared, and the team reviewed the current head. Five blocking findings remain, including a node isolation regression during topology changes.
Action required: Please address the five inline findings and push an updated head for follow-up review.
Blocking findings
GATOR-62c35145-01(Critical) Require verified node identity for pool assignmentsGATOR-62c35145-02(Warning) Expire supervisor authorization with the Pod identityGATOR-62c35145-03(Warning) Preserve existing gateway topology configuration on upgradeGATOR-62c35145-04(Warning) Fence deferred launch against a concurrent stopGATOR-62c35145-05(Warning) Retry transient Kubernetes reads after scheduling
Carried findings: None
Non-blocking suggestions: None
Gator metadata
- Validation: Accepted issue #6026 covers the per-node supervisor topology.
- Docs: Existing Fern gateway and Kubernetes guides were updated.
- Checks: DCO, Helm Lint, and Trivy Changes passed. Branch Checks are pending.
- E2E: Kubernetes E2E is applicable. Current-head Kubernetes jobs were skipped.
- Head SHA:
62c351459cf0b59ccc417942d6e825d69e0c6a02 - Base SHA:
659b45f3bed896897de20a8b67289916a3d9fffc - Merge base SHA:
659b45f3bed896897de20a8b67289916a3d9fffc - Patch ID:
86cbf48d2503077dd06c46c5711b4e42a15f383a - Gator payload:
19 - Review mode:
initial - Specialist consults: review-security
- Previous reviewed SHA: none
- Review budget exhausted: no
- Maintainer decision required: no
- Next state:
gator:in-review
| pub token_secret_name: String, | ||
| /// `ServiceAccount` in `service_namespace` the supervisor Pods run as; a | ||
| /// pod-bound token for it accompanies the supervisor token. | ||
| pub service_account_name: String, |
There was a problem hiding this comment.
gator-agent
Warning — GATOR-62c35145-03 · Preserve existing gateway topology configuration on upgrade
Summary
Operators upgrading with an existing file-based gateway topology configuration now fail at startup because the shared supervisor table requires a ServiceAccount name even when Pod identity enforcement is disabled.
Fix
Accept an omitted account for gateway topology when identity enforcement is disabled. Require an explicit account in node topology or when identity is enforced, and reject supplied Pod credentials when no resolver is configured.
Verify
Load the existing four-field TOML fixture and verify legacy supervisor attachment still works. Check that missing account configuration fails for node topology and explicit identity enforcement.
Agent context
crates/openshell-driver-kubernetes/src/config.rs:244
There was a problem hiding this comment.
Fixed in e505af1. service_account_name is optional again. The gateway
topology can omit it, and then the gateway accepts the supervisor token
alone, as before. Config validation requires it only in the node topology or
with require_identity_token. Supervisors send the identity token only when
started with --identity-token-file, which --node-supervisor requires. A
gateway without the account refuses an identity token it can't verify.
There was a problem hiding this comment.
A few general points:
- Readiness is a TCP check, so a supervisor that can't attach to the gateway still counts as ready and the DaemonSet rollout keeps going. It would be safer if ready meant attached.
- E2E: no test yet for a node supervisor restart (sandboxes freeze, then resume), the new-node race, or a taint mismatch.
- Docs: for dense nodes (for example 360 sandboxes per node), mention raising kubelet
maxPodsand the node's pod CIDR.
| if read_awaiting().await.is_none() { | ||
| return; | ||
| } | ||
| let launch = Box::pin(self.launch_sandbox_runtime_generation(generation, Some(node))).await; |
There was a problem hiding this comment.
If the node's supervisor hasn't attached yet, this launch fails and the sandbox is rolled back. With the cluster autoscaler that's the normal case: the new node and the supervisor DaemonSet Pod come up together. Could we wait for the member to attach, within runtime_bootstrap_grace_seconds, before launching?
There was a problem hiding this comment.
Done in 21c0008. After the sandbox Pod is scheduled, the launch now waits, up to runtime_bootstrap_grace_seconds, for that node's supervisor to connect, so a new autoscaled node works. If it never connects, the sandbox fails with "no supervisor attached on node X". The HA guide also says to raise the grace if your autoscaler adds nodes slower than 5 minutes.
| } | ||
| let launch = Box::pin(self.launch_sandbox_runtime_generation(generation, Some(node))).await; | ||
| if let Err(error) = launch { | ||
| warn!(sandbox = cr_name, %error, "sandbox-runtime launch on the scheduled node failed; rolling back"); |
There was a problem hiding this comment.
Could this also emit a Kubernetes Event on the Sandbox, or a metric? Today the user just sees the sandbox deleted, and the reason is only in the gateway logs.
There was a problem hiding this comment.
this one is partly done in 0c7fa11. When a new sandbox can't be launched on its node, it now goes to Error with the reason, for example "no supervisor attached on node X within 300s". openshell sandbox create shows that reason to the user, and the sandbox is deleted about 30 seconds later. So the reason isn't hidden in the gateway logs anymore.
I didn't add a Kubernetes Event or a metric yet. Both need a bit more thought (permissions to create Events, and names that we'd have to keep stable), so if needed this should probably land in a dedicated follow-up to handle K8S events and metrics.
Do you want me to open an issue to track such an effort?
| app.kubernetes.io/component: supervisor | ||
| spec: | ||
| {{- if $node }} | ||
| # No surge: two live members with one node's ID would keep superseding each |
There was a problem hiding this comment.
With one supervisor per node, a crash or rollout freezes every sandbox on that node. We've seen about 360 sandboxes on a single 192-vCPU Vera node. Worth considering two members per node (for example node/a and node/b), with takeover allowed only within the node. Fine as a follow-up.
There was a problem hiding this comment.
Agreed, and like you said, it makes sense as a follow-up. This PR relies on
"one supervisor per node, named after the node" in several places, so
supporting two per node needs its own design. I'll open an issue and update
RFC 0018 for it.
Until then, priorityClassName keeps the supervisor from being evicted
before its sandboxes, and the default rollout only pauses one node at a time.
| type: RollingUpdate | ||
| rollingUpdate: | ||
| maxSurge: 0 | ||
| maxUnavailable: 1 |
There was a problem hiding this comment.
Can we make maxUnavailable a Helm value (default 1, allowing something like 10%)? With about 2,000 nodes, one node at a time makes a rollout take a very long time.
There was a problem hiding this comment.
Done in 79b9abb: supervisor.updateStrategy.maxUnavailable, default 1, takes a number or a percentage like "10%". maxSurge stays 0, so two supervisors never run on the same node. The values comment notes that a higher value pauses more nodes' sandboxes at once.
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- with .Values.supervisor.nodeSelector }} | ||
| nodeSelector: |
There was a problem hiding this comment.
Could we also add supervisor.priorityClassName? If the kubelet evicts the supervisor under memory pressure before the sandboxes, the whole node freezes.
There was a problem hiding this comment.
Done in 79b9abb. supervisor.priorityClassName is empty by default, like the gateway's. The docs recommend system-node-critical for the node topology, so other Pods are evicted before the supervisor, and mention that some clusters need a ResourceQuota to allow that class outside kube-system.
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- with .Values.supervisor.tolerations }} | ||
| tolerations: |
There was a problem hiding this comment.
Sandboxes can still be scheduled to a node without a supervisor (a taint or node-pool mismatch) and then get rolled back. Could the driver add required pod affinity from the sandbox Pod to the supervisor Pods on kubernetes.io/hostname, so the scheduler only picks nodes that have one?
There was a problem hiding this comment.
Fixed in 788712f. In the node topology, the driver gives each sandbox's
workload Pod a required Pod affinity, on kubernetes.io/hostname, to the
Pods the supervisor Service selects. The scheduler then places sandboxes only
on nodes running a supervisor. A sandbox that fits no such node stays
Pending and fails when runtime_bootstrap_grace_seconds ends. A restart
sets the rule again, and a restart outside this topology clears it. Users'
own affinity rules aren't affected, because the driver sets no other workload
affinity. The rule matches only the supervisor Pods in one namespace, so it
should be cheap for the scheduler. I haven't measured it on a large cluster.
| */}} | ||
| {{- define "openshell.supervisorMaxInstancesPerMember" -}} | ||
| {{- if include "openshell.supervisorNodeTopology" . -}} | ||
| 1024 |
There was a problem hiding this comment.
Forcing 1024 also raises the gateway-to-supervisor message size limit about 8x, since it scales with this cap. Real usage is bounded by kubelet maxPods, so maybe keep honoring maxInstancesPerMember here, or use a lower default.
There was a problem hiding this comment.
Done in 79b9abb. The node topology no longer forces 1,024. It defaults to 300, which is above the kubelet's default maxPods, and an explicit supervisor.pool.maxInstancesPerMember now wins in both topologies. That also brings the message size limit down to match. The HA guide says to set it to at least your nodes' maxPods.
|
@FrostGod on the dense-nodes docs from your review: added in a675ca9. The node-topology section of the HA guide now covers what limits sandboxes per node: the per-supervisor cap and kubelet |
Record the per-node model as the next one after the per-gateway model. Each shared supervisor proves its Pod with a pod-bound token, a per-node supervisor can claim only its own node's member ID, and a per-node sandbox never falls back to a supervisor on another node. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
All shared supervisor Pods present the same gateway-minted supervisor token, so anyone holding a copy of the token Secret could attach as a supervisor. The gateway now accepts the supervisor token only beside a projected ServiceAccount token (audience openshell-supervisor) that TokenReview and a live-Pod check resolve to a Pod of shared_supervisor.service_account_name. - shared_supervisor.service_account_name is required; the driver registers it with the controller, and the gateway refuses to start the topology without it. - The supervisor sends the token from --identity-token-file in the x-openshell-host-identity-token header, re-read on every attempt. - Helm renders the supervisor ServiceAccount without RBAC, runs the supervisor as it, and mounts a 10-minute projected token. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
Accept supervisor_topology = "node". The gateway records the node that a supervisor's pod identity token proves on HostIdentity, and in the node topology the driver binds pool members to nodes, so the gateway refuses host streams whose pool member ID is not that node. Launches stay refused until node-local placement lands. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
Carry the pool member through SharedSupervision::launch, PlacementRequest, the stored assignment record, and recovery, and restrict launch, takeover, and unowned placement of a pinned instance to that member. With members bound to nodes, the pool never places an unpinned instance: one launched under the gateway topology stays where it is until the recovery timeout ends it. In the node topology the Kubernetes driver ungates the workload Pod, waits for the scheduler to bind it, launches on that node's supervisor, records the member on the Sandbox resource for recovery, and creates the bootstrap Secret last. Supervisors started with --node-supervisor (OPENSHELL_SUPERVISOR_NODE) no longer leave the pool on shutdown, and a suspended generation forgets its member. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
With supervisor_topology = "node", the chart renders the supervisor as a DaemonSet on every node, started with --node-supervisor and with the node name as each Pod's pool member ID. The Service keeps runtimes on their own node with internalTrafficPolicy: Local, and the node topology renders no PodDisruptionBudget or HPA. supervisor.tolerations and supervisor.nodeSelector place supervisors on tainted or selected sandbox nodes, such as GPU nodes. Adds the e2e:kubernetes:shared-supervisor-node task on a two-node k3d cluster, and documents the topology, its platform preconditions, and that switching topologies ends running shared sandboxes. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
With supervisor_topology = "node", create and restart now return after the driver removes the scheduling gate. The bootstrap launches on the node once the scheduler binds the workload Pod, and a failed launch or a Pod that isn't scheduled within runtime_bootstrap_grace_seconds is logged and rolls the bootstrap back like any stale bootstrap. A shared supervisor now marks its boundary as stopping on every requested stop, so stopping a workload that is already gone no longer waits for a reconnect to time out and stall later instance removals. Update the Kubernetes HA docs, the driver README, and the debug-openshell-cluster skill to match. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…ishes The node-topology launch runs after create returns, outside the gateway's lifecycle lock. Its member and release writes now re-check on every conflict retry that the sandbox still awaits this launch, so a stop, delete, or newer attempt served by another replica is never overwritten; the existing failure path then withdraws the placed instance. A transient error reading the sandbox before the launch is retried until the bootstrap grace instead of abandoning the launch. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
On a new node the workload Pod and the node's supervisor start together, so a launch that runs as soon as the Pod is bound found no pool member and rolled the sandbox back. The deferred launch now waits, within the bootstrap grace, until the gateway's pool view has the node's supervisor live and not leaving. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…on that node Only node-topology replicas check a supervisor's claimed node at attach, so during a topology switch a supervisor attached through a gateway-topology replica could claim any node and be granted that node's pinned instances. Every session already carries the node its Pod identity token proves; the membership record now stores it, and launch, recovery placement, and takeover grant a pinned instance only to a member whose record proves that node. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
The gateway checked a supervisor's Pod identity token once per stream and ended the stream only when the supervisor token expired, up to an hour later, so a stream outlived the Pod that proved its node. The stream now ends at the earlier expiry of the two tokens; the host already re-reads both on every reconnect, and its sandboxes keep running across it. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
… and priority settings The node topology forced every supervisor's cap to 1024, sizing each gateway message for that many sandboxes. It now defaults to 300, above the kubelet's default maxPods, and an explicit supervisor.pool.maxInstancesPerMember overrides it in either topology. supervisor.updateStrategy.maxUnavailable sets how many node supervisors a rollout replaces at once, and supervisor.priorityClassName sets the supervisor Pods' PriorityClass; system-node-critical is recommended for the node topology. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
List the limits that bound how many sandboxes one node runs in the node supervisor topology: the node's Pod address range, the pool cap, and the supervisor's PriorityClass. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
A create in the node topology returns before its launch, so a later failure deleted the sandbox with no reason the creator could see. The launch now records the cause in openshell.ai/sandbox-runtime-launch-failure, which the driver reports as Ready=False SandboxRuntimeLaunchFailed so the gateway shows the create as failed. The reaper deletes such a sandbox on its next pass, and gives a stale node-topology create a generic cause first. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
… cluster Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…dbox nodes Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…logy A warm spare reserves shared supervisor capacity before its Pod is scheduled, so it carries no node pin. With supervisor_topology = "node" any node's supervisor could take it, the Pod could then run on another node, and recovery refuses unpinned instances there. Node-topology replicas now refuse unpinned placement, which warm preparation uses. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…ut a service account working A shared_supervisor table written before service_account_name existed failed to load after upgrade. The gateway topology now accepts it without the account and verifies only the supervisor token, refusing a pod-bound identity token it has no account to verify. The node topology and require_identity_token still require the account. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…ing a supervisor In the node supervisor topology, each generation's workload Pod now requires Pod affinity, on kubernetes.io/hostname, to a Pod the supervisor Service selects. The scheduler no longer places a sandbox on a node without a supervisor, where it would wait out the bootstrap grace and fail. A restart outside the node topology clears the rule. The gateway topology and dedicated supervisors are unchanged. Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
5cbc431 to
788712f
Compare
|
@FrostGod replying to the rest of your review. About the missing e2e tests:
About readiness meaning "attached to the gateway": Agreed, the readiness check only looks at the port. The gateway topology has the same |
Summary
Add a
nodesupervisor topology for Kubernetes. One shared supervisor runs on each node as a DaemonSet, and each sandbox is served by the supervisor on the node its workload Pod is scheduled to. RFC 0018 records the per-node model.Related Issue
Closes #6026
Changes
--identity-token-filepresent a projected ServiceAccount token (audienceopenshell-supervisor) that binds a session to its Pod and node. The gateway verifies any token it receives and ends the stream when that token expires, so these supervisors reconnect about every 8 minutes.require_identity_token(Helmsupervisor.requireIdentityToken, defaultfalse) makes the token mandatory, and the node topology always requires it.shared_supervisor.service_account_nameis optional in the gateway topology: without it, the gateway accepts the supervisor token alone, as before, so existing hand-written configs keep working.supervisor_topology = "node"binds pool members to nodes. Sandbox Pods get a required Pod affinity to a supervisor Pod on their node, so the scheduler places them only on nodes running a supervisor. After the scheduler binds the workload Pod, the driver waits for that node's supervisor and launches the sandbox on it. The launch never overwrites a stop, delete, or newer attempt made meanwhile. A create that cannot be launched withinruntime_bootstrap_grace_secondsentersErrorwith its cause, whichopenshell sandbox createreports, and is deleted within 30 seconds; a restart that cannot be launched ends stopped.supervisor_topology: nodeundergatewayConfigrenders the supervisor as a DaemonSet that rolls withmaxSurge: 0andsupervisor.updateStrategy.maxUnavailable(default1).maxInstancesPerMemberdefaults to 300 in the node topology and stays overridable from 1 to 1,024.supervisor.priorityClassNameis empty by default; the docs recommendsystem-node-critical.requireIdentityToken, settings for dense sandbox nodes, and raisingruntime_bootstrap_grace_secondsfor autoscaled node pools), the driver and supervisor-control READMEs, the debug skill, and a newe2e:kubernetes:shared-supervisor-nodetask.test:e2e-kuberneteslabel.Release Notes
Kubernetes deployments can run one shared supervisor per node with
supervisor_topology: node. When upgrading a gateway-topology deployment, setsupervisor.requireIdentityToken=trueonly after every supervisor has rolled to the new version.Testing
kubectl_jsonimport that breaks the HA test build onmainas well; that fix is tracked separately. On the current head, rebased onmain, the node topology lane passed on a two-node k3d cluster (conformance 93/93 and the node topology tests, with no failures).Checklist