Skip to content

Commit 65b59a3

Browse files
committed
fix: tighten shared supervisor naming, removal deadlines, and route probes
The shared supervisor's resource name appended its suffix before truncating, so a release fullname of 51 or 52 characters produced the gateway Service's own name. A fullname without room for the suffix now keeps a prefix and a hash of the whole fullname. Removing a session waits up to 20 s for its workload to stop and 5 s for the session runtime to shut down, but the driver gave DELETE the same 15 s budget as other session-control calls and reported normal removals as failures. The contract now defines the removal grace and a 45 s removal deadline, and deleting a sandbox no longer waits on a session whose workload is already going away. The shared host runs no supervisor OTLP trace or OCSF exporter. The driver warns at startup when the gateway configures that export, and the docs state the limit. experimental-host keeps its Unix-only imports in its Unix entry point. The e2e route probe fails when the supervisor neither refuses nor challenges a connection, or keeps a challenged connection open after a malformed TLS answer, and it checks that every probe reached the supervisor Pod. Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent c22d37f commit 65b59a3

9 files changed

Lines changed: 205 additions & 56 deletions

File tree

‎crates/openshell-driver-kubernetes/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ fails closed.
215215

216216
The topology does not support upstream proxies or provider SPIFFE identity, and
217217
the shared supervisor is a single point of failure for the sandboxes it hosts.
218+
Shared sessions export no supervisor OTLP traces or OCSF events; the driver
219+
warns at startup when the gateway configures that export.
218220
When the setting is removed, reconciliation suspends shared generations, and a
219221
restart creates the dedicated generation's boundary Service the shared one never
220222
had.

‎crates/openshell-driver-kubernetes/src/driver.rs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,14 @@ impl KubernetesComputeDriver {
10031003
.experimental_shared_supervisor
10041004
.clone()
10051005
.map(SharedSupervisor::new);
1006+
if shared_supervisor.is_some()
1007+
&& (config.supervisor_otlp_endpoint.is_some()
1008+
|| config.supervisor_ocsf_export.is_some())
1009+
{
1010+
warn!(
1011+
"the experimental gateway supervisor topology does not export supervisor OTLP traces or OCSF events; shared sessions keep console logs and gateway log push"
1012+
);
1013+
}
10061014
let driver = Self {
10071015
client,
10081016
watch_client,
@@ -4317,8 +4325,11 @@ impl KubernetesComputeDriver {
43174325
match tokio::time::timeout(KUBE_API_TIMEOUT, delete_api.api.delete(&kube_name, &dp)).await {
43184326
Ok(Ok(_response)) => {
43194327
info!(sandbox_id = %sandbox_id, namespace = %obj_namespace, "Sandbox deleted from Kubernetes");
4320-
if let Some(placement) = &placement {
4321-
self.remove_shared_session(placement).await;
4328+
// The workload is going away, so its session cannot stop it
4329+
// gracefully; end the session without delaying the delete.
4330+
if let Some(placement @ SupervisorPlacement::Shared { .. }) = placement {
4331+
let driver = self.clone();
4332+
tokio::spawn(async move { driver.remove_shared_session(&placement).await });
43224333
}
43234334
{
43244335
let pod_api = Api::<Pod>::namespaced(self.client.clone(), &obj_namespace);

‎crates/openshell-driver-kubernetes/src/shared_supervisor.rs‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bytes::Bytes;
1313
use http_body_util::{BodyExt as _, Full};
1414
use kube::core::DynamicObject;
1515
use openshell_sandbox_backend::session_control::{
16-
SESSIONS_PATH, SessionList, SessionRegistration, SessionStatusReport,
16+
SESSION_REMOVAL_TIMEOUT, SESSIONS_PATH, SessionList, SessionRegistration, SessionStatusReport,
1717
};
1818

1919
use crate::config::ExperimentalSharedSupervisorConfig;
@@ -27,6 +27,8 @@ pub const ANNOTATION_SUPERVISOR_SESSION: &str = "openshell.ai/sandbox-runtime-su
2727
pub const GATEWAY_TOPOLOGY: &str = "gateway";
2828

2929
/// Bound on one session-control request, including connection and TLS.
30+
/// Removals wait for the session's workload to stop and use the contract's
31+
/// longer bound instead.
3032
const SESSION_CONTROL_TIMEOUT: Duration = Duration::from_secs(15);
3133

3234
/// Where a generation's supervisor runs, as recorded when it started.
@@ -152,16 +154,18 @@ impl SharedSupervisor {
152154
path: &str,
153155
body: Option<Vec<u8>>,
154156
) -> Result<(http::StatusCode, Bytes), KubernetesDriverError> {
155-
tokio::time::timeout(
156-
SESSION_CONTROL_TIMEOUT,
157-
self.request_once(method, path, body),
158-
)
159-
.await
160-
.map_err(|_| {
161-
KubernetesDriverError::Message(
162-
"timed out calling the shared supervisor session-control API".to_string(),
163-
)
164-
})?
157+
let deadline = if method == http::Method::DELETE {
158+
SESSION_REMOVAL_TIMEOUT
159+
} else {
160+
SESSION_CONTROL_TIMEOUT
161+
};
162+
tokio::time::timeout(deadline, self.request_once(method, path, body))
163+
.await
164+
.map_err(|_| {
165+
KubernetesDriverError::Message(
166+
"timed out calling the shared supervisor session-control API".to_string(),
167+
)
168+
})?
165169
}
166170

167171
async fn request_once(

‎crates/openshell-sandbox-backend/src/session_control.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! Sandbox Protocol credentials it carries; it confers no other identity.
1212
1313
use std::sync::Arc;
14+
use std::time::Duration;
1415

1516
use openshell_isolation_interface::contract::BackendError;
1617
use serde::{Deserialize, Serialize};
@@ -21,6 +22,13 @@ use crate::boundary_protocol::{SandboxRuntimeDescriptor, SandboxTransport};
2122
pub const SESSIONS_PATH: &str = "/v1/sessions";
2223
/// Largest registration body a supervisor accepts.
2324
pub const MAX_REGISTRATION_BYTES: usize = 256 * 1024;
25+
/// Time a shared supervisor gives a removed session's workload to stop
26+
/// before cancelling the session.
27+
pub const SESSION_REMOVAL_GRACE: Duration = Duration::from_secs(20);
28+
/// Bound on answering a removal request: the grace period, the session
29+
/// runtime's shutdown, file cleanup, and the connection itself. A removal
30+
/// continues on the supervisor if its caller stops waiting.
31+
pub const SESSION_REMOVAL_TIMEOUT: Duration = Duration::from_secs(45);
2432

2533
/// PEM private key that never appears in `Debug` output.
2634
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]

‎crates/openshell-supervisor/README.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ one process for the Kubernetes gateway topology experiment. It is Unix-only.
124124
session control. SIGTERM and SIGINT stop every session, which ends their
125125
workloads' supervision.
126126

127-
Sessions get no upstream proxy, extra CA bundle, OCSF OTLP export, or provider
128-
workload identity: the Kubernetes driver refuses the topology when an upstream
129-
proxy or provider SPIFFE identity is configured, so a workload never silently
130-
loses them.
127+
Sessions get no upstream proxy, extra CA bundle, or provider workload identity:
128+
the Kubernetes driver refuses the topology when an upstream proxy or provider
129+
SPIFFE identity is configured, so a workload never silently loses them. The
130+
host also initializes no OTLP trace or OCSF exporters, because one process
131+
cannot export each session's records with that session's collector headers and
132+
identity. Its console logs and each session's gateway log push remain, and the
133+
Kubernetes driver warns at startup when the gateway configures supervisor
134+
export.

‎crates/openshell-supervisor/src/experimental.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
//! Supervisor shared by the sandboxes of one gateway (experimental).
55
66
use clap::Parser;
7-
use miette::{IntoDiagnostic, Result, WrapErr};
7+
use miette::Result;
88
use std::net::SocketAddr;
99
use std::path::PathBuf;
10-
use std::time::Duration;
11-
12-
/// Time a removed or shut-down session may take to stop its workload.
13-
const SESSION_REMOVAL_GRACE: Duration = Duration::from_secs(20);
1410

1511
#[derive(Debug, Parser)]
1612
#[command(name = "openshell-supervisor experimental-host")]
@@ -51,6 +47,7 @@ pub fn run(raw_args: &[String]) -> Result<()> {
5147

5248
#[cfg(unix)]
5349
fn run_platform(args: Args) -> Result<()> {
50+
use miette::{IntoDiagnostic as _, WrapErr as _};
5451
use std::sync::Arc;
5552
use std::sync::atomic::AtomicBool;
5653
use tracing_subscriber::{Layer as _, layer::SubscriberExt as _, util::SubscriberInitExt as _};
@@ -108,7 +105,7 @@ fn run_platform(args: Args) -> Result<()> {
108105
gateway_endpoint: args.openshell_endpoint.clone(),
109106
session_root: args.session_root.clone(),
110107
runtime_listen: args.runtime_listen,
111-
removal_grace: SESSION_REMOVAL_GRACE,
108+
removal_grace: openshell_sandbox_backend::session_control::SESSION_REMOVAL_GRACE,
112109
},
113110
)?;
114111
let control = tokio::net::TcpListener::bind(args.session_control_listen)

‎deploy/helm/openshell/templates/_helpers.tpl‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,19 @@ raw gateway configuration so openshell.effectiveKubernetesConfig can use it.
363363
{{- end }}
364364

365365
{{/*
366-
Name of the shared supervisor Deployment, Service, and session-control Secrets.
366+
Name of the shared supervisor Deployment, Service, and session-control Secrets:
367+
the fullname with a fixed suffix, within the 63-character Service name limit.
368+
A fullname without room for the suffix keeps a prefix and a hash of the whole
369+
fullname, so the name never collapses into another release resource's name.
367370
*/}}
368371
{{- define "openshell.experimentalSupervisorName" -}}
369-
{{- printf "%s-experimental-supervisor" (include "openshell.fullname" .) | trunc 52 | trimSuffix "-" -}}
372+
{{- $suffix := "-experimental-supervisor" -}}
373+
{{- $base := include "openshell.fullname" . -}}
374+
{{- $room := sub 63 (len $suffix) | int -}}
375+
{{- if gt (len $base) $room -}}
376+
{{- $base = printf "%s-%s" ($base | trunc (sub $room 9 | int) | trimSuffix "-") ($base | sha256sum | trunc 8) -}}
377+
{{- end -}}
378+
{{- printf "%s%s" $base $suffix -}}
370379
{{- end }}
371380

372381
{{/*

‎deploy/helm/openshell/tests/experimental_supervisor_test.yaml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ tests:
174174
asserts:
175175
- failedTemplate:
176176
errorMessage: experimental_supervisor_topology=gateway in operator workspace mode requires operator_namespace_label of the form key=value
177+
- it: keeps a distinct name when the release fullname leaves no room for the suffix
178+
template: templates/experimental-supervisor.yaml
179+
set:
180+
fullnameOverride: openshell-gateway-release-with-a-very-long-name-0052
181+
gatewayConfig:
182+
openshell.drivers.kubernetes:
183+
experimental_supervisor_topology: gateway
184+
asserts:
185+
- matchRegex:
186+
path: metadata.name
187+
pattern: ^openshell-gateway-release-with-[0-9a-f]{8}-experimental-supervisor$
188+
documentIndex: 1
189+
- notEqual:
190+
path: metadata.name
191+
value: openshell-gateway-release-with-a-very-long-name-0052
192+
documentIndex: 1
177193
- it: omits the gateway CA when gateway TLS is disabled
178194
template: templates/experimental-supervisor.yaml
179195
set:

0 commit comments

Comments
 (0)