Skip to content

Commit ceaa9cf

Browse files
committed
refactor(compute): register compiled drivers
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent a42a0ad commit ceaa9cf

8 files changed

Lines changed: 622 additions & 153 deletions

File tree

‎.agents/skills/debug-openshell-cluster/SKILL.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ The target deployment flow is:
1919
4. The CLI registers a reachable gateway endpoint with `openshell gateway add`.
2020
5. The gateway creates sandboxes through the selected compute driver.
2121

22+
The standard gateway binary explicitly installs its compiled Docker, Podman,
23+
Kubernetes, and VM registrations at startup. With no configured driver, the
24+
gateway probes only installed registrations in priority order (Kubernetes,
25+
Podman, then Docker); VM has no probe and remains opt-in. A custom gateway
26+
binary may install a different set, so confirm the binary's registered drivers
27+
when auto-detection reports that no suitable driver is available.
28+
2229
For local evaluation only, TLS may be disabled and the gateway can be reached through `http://127.0.0.1:<port>`.
2330

2431
## Prerequisites

‎architecture/compute-runtimes.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ The gateway records driver identity and version from the startup capability
9191
response. Elevated gateway info reports that initialized driver snapshot instead
9292
of re-querying drivers on each request.
9393

94+
## Compiled Driver Selection
95+
96+
The gateway binary explicitly installs the compute drivers compiled into that
97+
binary before entering server startup. The server selects a configured driver
98+
by normalized registry name. When no driver is configured, it evaluates only
99+
the installed drivers' probes and chooses the lowest registered priority.
100+
Drivers without a probe, including VM, remain opt-in.
101+
102+
This follows the same composition model as SQLx's `Any` drivers: the binary
103+
defines the available implementation set, while the runtime consumes a generic
104+
registry. Adding or removing a compiled driver therefore changes registration
105+
rather than the server's selection flow. Alternate gateway binaries can install
106+
their own `ComputeDriverFactory` registrations and hand the completed registry
107+
to `run_cli_with_compute_drivers`; factories receive merged driver config and
108+
finish through the same in-process runtime adapter. A configured UDS endpoint
109+
still takes precedence over a compiled registration with the same name.
110+
94111
## Stop and Start Lifecycle
95112

96113
The gateway persists lifecycle intent before mutating compute:

‎crates/openshell-core/src/config.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ pub fn detect_driver() -> Option<ComputeDriverKind> {
208208
None
209209
}
210210

211-
fn is_podman_available() -> bool {
211+
/// Return whether a responsive local Podman API socket is available.
212+
#[must_use]
213+
pub fn is_podman_available() -> bool {
212214
detect_podman_socket().is_some()
213215
}
214216

@@ -266,7 +268,9 @@ fn podman_socket_candidates_from_env(
266268
candidates
267269
}
268270

269-
fn is_docker_available() -> bool {
271+
/// Return whether a responsive local Docker API socket is available.
272+
#[must_use]
273+
pub fn is_docker_available() -> bool {
270274
detect_docker_socket().is_some()
271275
}
272276

‎crates/openshell-server/src/cli.rs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ use crate::certgen;
1717
use crate::compute::driver_config::GuestTlsPaths;
1818
use crate::config_file::{self, ConfigFile, GatewayFileSection};
1919
use crate::defaults::{self, LocalTlsPaths};
20-
use crate::{ServerStartupConfig, run_server, tracing_bus::TracingLogBus};
20+
use crate::{
21+
ComputeDriverRegistry, ServerStartupConfig, install_default_compute_drivers, run_server,
22+
tracing_bus::TracingLogBus,
23+
};
2124

2225
/// `OpenShell` gateway process - gRPC and HTTP server with protocol multiplexing.
2326
///
@@ -220,6 +223,11 @@ pub fn command() -> Command {
220223
}
221224

222225
pub async fn run_cli() -> Result<()> {
226+
run_cli_with_compute_drivers(install_default_compute_drivers()).await
227+
}
228+
229+
/// Run the gateway CLI with the compute drivers linked by the binary.
230+
pub async fn run_cli_with_compute_drivers(compute_drivers: ComputeDriverRegistry) -> Result<()> {
223231
rustls::crypto::ring::default_provider()
224232
.install_default()
225233
.map_err(|e| miette::miette!("failed to install rustls crypto provider: {e:?}"))?;
@@ -229,7 +237,7 @@ pub async fn run_cli() -> Result<()> {
229237

230238
match cli.command {
231239
Some(Commands::GenerateCerts(args)) => certgen::run(args).await,
232-
None => Box::pin(run_from_args(cli.run, matches)).await,
240+
None => Box::pin(run_from_args(cli.run, matches, compute_drivers)).await,
233241
}
234242
}
235243

@@ -469,7 +477,11 @@ fn prepare_server_config(args: &mut RunArgs, matches: &ArgMatches) -> Result<Ser
469477
})
470478
}
471479

472-
async fn run_from_args(mut args: RunArgs, matches: ArgMatches) -> Result<()> {
480+
async fn run_from_args(
481+
mut args: RunArgs,
482+
matches: ArgMatches,
483+
compute_drivers: ComputeDriverRegistry,
484+
) -> Result<()> {
473485
let prepared = prepare_server_config(&mut args, &matches)?;
474486

475487
let tracing_log_bus = TracingLogBus::new();
@@ -538,7 +550,7 @@ async fn run_from_args(mut args: RunArgs, matches: ArgMatches) -> Result<()> {
538550

539551
info!(bind = %prepared.config.bind_address, "Starting OpenShell server");
540552

541-
let result = Box::pin(run_server(prepared, tracing_log_bus)).await;
553+
let result = Box::pin(run_server(prepared, tracing_log_bus, compute_drivers)).await;
542554

543555
tracing_handle.shutdown();
544556

‎crates/openshell-server/src/compute/driver_config.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ pub struct GuestTlsPaths {
2424
key: PathBuf,
2525
}
2626

27+
impl GuestTlsPaths {
28+
pub(crate) fn as_paths(&self) -> (&std::path::Path, &std::path::Path, &std::path::Path) {
29+
(&self.ca, &self.cert, &self.key)
30+
}
31+
}
32+
2733
impl From<&LocalTlsPaths> for GuestTlsPaths {
2834
fn from(paths: &LocalTlsPaths) -> Self {
2935
Self {
@@ -60,7 +66,10 @@ pub struct RemoteDriverConfig {
6066
pub socket_path: PathBuf,
6167
}
6268

63-
fn driver_config_from_context<T>(context: DriverStartupContext<'_>, driver_name: &str) -> Result<T>
69+
pub fn driver_config_from_context<T>(
70+
context: DriverStartupContext<'_>,
71+
driver_name: &str,
72+
) -> Result<T>
6473
where
6574
T: Default + serde::de::DeserializeOwned,
6675
{

‎crates/openshell-server/src/compute/mod.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ use tonic::{Code, Request, Status};
7777
use tower::service_fn;
7878
use tracing::{Instrument as _, debug, info, warn};
7979

80-
type DriverWatchStream = Pin<Box<dyn Stream<Item = Result<WatchSandboxesEvent, Status>> + Send>>;
81-
type SharedComputeDriver =
80+
pub type DriverWatchStream =
81+
Pin<Box<dyn Stream<Item = Result<WatchSandboxesEvent, Status>> + Send>>;
82+
pub type SharedComputeDriver =
8283
Arc<dyn ComputeDriver<WatchSandboxesStream = DriverWatchStream> + Send + Sync>;
8384

8485
use traced_driver::TracedDriver;
@@ -585,7 +586,7 @@ impl ComputeRuntime {
585586
driver.name = %driver_name,
586587
)
587588
)]
588-
async fn from_driver(
589+
pub(crate) async fn from_driver(
589590
driver_name: String,
590591
driver: SharedComputeDriver,
591592
driver_process: Option<Arc<ManagedDriverProcess>>,

0 commit comments

Comments
 (0)