Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .agents/skills/helm-dev-environment/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ shared process namespace. The sidecar sends SIGKILL to the supervisor as the
same UID; it needs no host PID namespace, capabilities, or runtime socket.
The default k3d/kind test continues to kill through the node container runtime.

`mise run e2e:kubernetes:shared-supervisor-node` runs the
`supervisor_topology: node` e2e (`ci/values-supervisor-node.yaml`) on a
two-node k3d cluster.

### Shared supervisor high availability

`mise run e2e:kubernetes:shared-supervisor-spiffe-node-local` validates direct
Expand Down
8 changes: 7 additions & 1 deletion .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test-group = "kubernetes-ha"
# they kill members or gateways, or scale the pool. Never run them at once.
# Test names, not binary(), for the reason above.
[[profile.e2e-kubernetes.overrides]]
filter = "test(/^(losing_a_supervisor_pod_moves_its_sandboxes_without_restarting_them|scaling_a_supervisor_pool_up_and_down_keeps_its_sandboxes_running|pool_sessions_follow_their_supervisors_gateway|shared_supervisor_acts_as_each_sandboxs_stable_spiffe_identity|supervisors_spread_evenly_across_gateways)$/)"
filter = "test(/^(losing_a_supervisor_pod_moves_its_sandboxes_without_restarting_them|scaling_a_supervisor_pool_up_and_down_keeps_its_sandboxes_running|pool_sessions_follow_their_supervisors_gateway|shared_supervisor_acts_as_each_sandboxs_stable_spiffe_identity|supervisors_spread_evenly_across_gateways|each_workload_is_served_by_its_own_nodes_supervisor|a_supervisor_claiming_another_nodes_member_id_is_refused)$/)"
test-group = "kubernetes-shared-supervisor-pool"

# Scaling the pool runs two bounded Helm upgrades (up to 6 minutes each), waits
Expand All @@ -59,6 +59,12 @@ slow-timeout = { period = "60s", terminate-after = 15 }
filter = "test(/^supervisors_spread_evenly_across_gateways$/)"
slow-timeout = { period = "60s", terminate-after = 20 }

# Restarting a node supervisor waits for its replacement to receive the
# supervisor token, attach, and re-adopt the node's instances.
[[profile.e2e-kubernetes.overrides]]
filter = "test(/^each_workload_is_served_by_its_own_nodes_supervisor$/)"
slow-timeout = { period = "60s", terminate-after = 12 }

# Relative to the profile store dir (`e2e/rust/target/nextest/e2e-kubernetes/`).
[profile.e2e-kubernetes.junit]
path = "../../../../../results/e2e-kubernetes.xml"
31 changes: 31 additions & 0 deletions crates/openshell-driver-kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ fails closed.
`shared_supervisor.token_secret_name` Secret in `service_namespace`, which
the supervisor Pod mounts, and names a missing Secret or a denied patch in
the retried error.
- **Pod identity.** The driver registers
`shared_supervisor.service_account_name`, the ServiceAccount the supervisor
Pods run as, with the controller (`require_host_identity`). A projected
ServiceAccount token sent with a supervisor token must resolve to a live Pod
of that account. With `shared_supervisor.require_identity_token`, a
supervisor token without one is refused, so a copy of the token Secret alone
admits no caller.
- **Create and start.** The driver creates a per-sandbox egress allowance
`os-shared-control-<id>` from the workload Pod to the Pods the shared
supervisor's Service selects, on the runtime port, binds its UID and
Expand Down Expand Up @@ -280,6 +287,30 @@ When the setting is removed, reconciliation suspends shared generations, and a
restart creates the dedicated generation's boundary Service the shared one never
had.

#### Node topology

`supervisor_topology = "node"` runs the same shared pool with one supervisor
per node, and pins each generation to the supervisor on its workload's node.
The driver binds pool members to nodes (`bind_members_to_nodes`): the gateway
accepts a supervisor only when the Pod its identity token resolves to is
scheduled on the node it claims as its pool member ID.

- **Placement.** The driver removes the scheduling gate and returns from
create or restart before it assigns the instance. The bootstrap task watches
the workload Pod and launches on the node in its `spec.nodeName`. A Pod that
is deleted or replaced, or a node supervisor that refuses the instance, rolls
the bootstrap back. So does a Pod that isn't scheduled within
`runtime_bootstrap_grace_seconds`.
The Sandbox's `openshell.ai/sandbox-runtime-supervisor-member` annotation
records the pinned node. The bootstrap Secret exists before the gate is removed; until the
launch places the route, the supervisor refuses the runtime's dials and the
workload does not start.
- **Recovery and takeover.** Recovery reads the member annotation and skips a
node-topology generation that lacks one. Placement, takeover, and recovery
of a pinned instance only consider its own member, so a lost node
supervisor's instances wait for it to return. A restart clears the
annotation, and the new generation records its own node.

## Sandbox Resource

The driver works with the `agents.x-k8s.io` `Sandbox` custom resource. It
Expand Down
43 changes: 35 additions & 8 deletions crates/openshell-driver-kubernetes/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,13 @@ where
#[serde(rename_all = "snake_case")]
pub enum SupervisorTopology {
Gateway,
/// One shared supervisor per node, serving the sandboxes whose workload
/// Pods run on that node.
Node,
Workspace,
}

/// The supervisor Helm deploys for the gateway topology.
/// The supervisor Helm deploys for the gateway or node topology.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SharedSupervisorConfig {
Expand All @@ -236,6 +239,13 @@ pub struct SharedSupervisorConfig {
/// gateway-minted supervisor token (key `token`); the supervisor Pod
/// mounts it and presents the token on its assignment stream.
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,
/// Refuse a supervisor token without the pod-bound token. A present
/// token is verified either way.
#[serde(default)]
pub require_identity_token: bool,
}

impl SharedSupervisorConfig {
Expand All @@ -251,6 +261,11 @@ impl SharedSupervisorConfig {
if !is_dns_subdomain(&self.token_secret_name) {
return Err("shared_supervisor token_secret_name must be a DNS subdomain name".into());
}
if !is_dns_subdomain(&self.service_account_name) {
return Err(
"shared_supervisor service_account_name must be a DNS subdomain name".into(),
);
}
Ok(())
}

Expand Down Expand Up @@ -602,16 +617,23 @@ impl KubernetesComputeConfig {
match self.supervisor_topology {
None => {
if self.shared_supervisor.is_some() {
return Err("shared_supervisor requires supervisor_topology=gateway".into());
return Err(
"shared_supervisor requires supervisor_topology=gateway or node".into(),
);
}
Ok(())
}
Some(SupervisorTopology::Workspace) => {
Err("supervisor_topology=workspace is not implemented".into())
}
Some(SupervisorTopology::Gateway) => {
Some(topology @ (SupervisorTopology::Gateway | SupervisorTopology::Node)) => {
let topology_name = if topology == SupervisorTopology::Node {
"node"
} else {
"gateway"
};
let shared = self.shared_supervisor.as_ref().ok_or_else(|| {
"supervisor_topology=gateway requires shared_supervisor".to_string()
format!("supervisor_topology={topology_name} requires shared_supervisor")
})?;
shared.validate()?;
if self.sandbox_runtime.app_listener.common.enabled
Expand All @@ -623,10 +645,9 @@ impl KubernetesComputeConfig {
|| self.proxy_auth_secret_name.is_some()
|| self.proxy_ca_bundle.is_some()
{
return Err(
"supervisor_topology=gateway does not support upstream proxy settings"
.into(),
);
return Err(format!(
"supervisor_topology={topology_name} does not support upstream proxy settings"
));
}
Ok(())
}
Expand Down Expand Up @@ -1212,6 +1233,8 @@ mod tests {
service_namespace: "openshell".to_string(),
runtime_port: 8443,
token_secret_name: "openshell-supervisor-token".to_string(),
service_account_name: "openshell-supervisor".to_string(),
require_identity_token: false,
};
let gateway = |shared: Option<SharedSupervisorConfig>| KubernetesComputeConfig {
supervisor_topology: Some(SupervisorTopology::Gateway),
Expand Down Expand Up @@ -1243,6 +1266,10 @@ mod tests {
token_secret_name: "Not_A_Secret_Name".to_string(),
..shared()
},
SharedSupervisorConfig {
service_account_name: "Not_A_Name".to_string(),
..shared()
},
] {
assert!(
gateway(Some(invalid))
Expand Down
Loading