Skip to content

Commit 72fad27

Browse files
committed
refactor(gateway): clarify driver detection results
Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent 126f9b9 commit 72fad27

4 files changed

Lines changed: 33 additions & 18 deletions

File tree

crates/openshell-core/src/config.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,23 @@ impl FromStr for ComputeDriverKind {
113113
}
114114
}
115115

116+
/// Result of automatic compute-driver detection.
117+
#[derive(Debug, Clone, PartialEq, Eq)]
118+
pub struct DriverDetection {
119+
/// Driver selected according to automatic selection priority.
120+
pub selected: Option<ComputeDriverKind>,
121+
/// Every available driver in automatic selection priority order.
122+
pub available: Vec<ComputeDriverKind>,
123+
}
124+
116125
/// Detect available compute drivers based on the runtime environment.
117126
///
118127
/// Priority order: Kubernetes → Podman → Docker.
119128
/// VM is never auto-detected (requires explicit `--drivers vm`).
120129
///
121-
/// Returns every available driver in selection priority order.
122-
///
123130
/// VM is excluded because it requires explicit operator selection.
124131
#[must_use]
125-
pub fn detect_drivers() -> Vec<ComputeDriverKind> {
132+
pub fn detect_drivers() -> DriverDetection {
126133
let mut drivers = Vec::new();
127134

128135
// Kubernetes: check for KUBERNETES_SERVICE_HOST env var (set inside pods)
@@ -140,13 +147,16 @@ pub fn detect_drivers() -> Vec<ComputeDriverKind> {
140147
drivers.push(ComputeDriverKind::Docker);
141148
}
142149

143-
drivers
150+
DriverDetection {
151+
selected: drivers.first().copied(),
152+
available: drivers,
153+
}
144154
}
145155

146-
/// Returns the first available driver in automatic selection priority order.
156+
/// Returns the selected driver in automatic selection priority order.
147157
#[must_use]
148158
pub fn detect_driver() -> Option<ComputeDriverKind> {
149-
detect_drivers().into_iter().next()
159+
detect_drivers().selected
150160
}
151161

152162
/// Check if a binary is available on the system PATH.
@@ -800,8 +810,8 @@ mod tests {
800810
use super::is_reachable_unix_socket;
801811
use super::{
802812
ComputeDriverKind, Config, DEFAULT_SERVICE_ROUTING_DOMAIN, GatewayJwtConfig, detect_driver,
803-
docker_host_unix_socket_path, is_unix_socket, normalize_compute_driver_name,
804-
podman_socket_candidates_from_env, podman_socket_responds,
813+
detect_drivers, docker_host_unix_socket_path, is_unix_socket,
814+
normalize_compute_driver_name, podman_socket_candidates_from_env, podman_socket_responds,
805815
};
806816
#[cfg(unix)]
807817
use std::io::{Read as _, Write as _};
@@ -1063,8 +1073,13 @@ mod tests {
10631073
std::env::set_var("KUBERNETES_SERVICE_HOST", "127.0.0.1");
10641074
}
10651075

1066-
let result = detect_driver();
1067-
assert_eq!(result, Some(ComputeDriverKind::Kubernetes));
1076+
let detection = detect_drivers();
1077+
assert_eq!(detection.selected, Some(ComputeDriverKind::Kubernetes));
1078+
assert_eq!(
1079+
detection.available.first().copied(),
1080+
Some(ComputeDriverKind::Kubernetes)
1081+
);
1082+
assert_eq!(detect_driver(), detection.selected);
10681083

10691084
// Restore the original env var
10701085
unsafe {

crates/openshell-server/src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum Commands {
4040
/// Generate mTLS PKI and write Kubernetes Secrets (Helm pre-install hook).
4141
GenerateCerts(certgen::CertgenArgs),
4242
/// Inspect or update the gateway TOML configuration.
43-
Config(crate::config_edit::ConfigArgs),
43+
Config(crate::config_command::ConfigArgs),
4444
}
4545

4646
#[derive(clap::Args, Debug)]
@@ -230,7 +230,7 @@ pub async fn run_cli() -> Result<()> {
230230

231231
match cli.command {
232232
Some(Commands::GenerateCerts(args)) => certgen::run(args).await,
233-
Some(Commands::Config(args)) => crate::config_edit::run(args, cli.run.config),
233+
Some(Commands::Config(args)) => crate::config_command::run(args, cli.run.config),
234234
None => Box::pin(run_from_args(cli.run, matches)).await,
235235
}
236236
}
@@ -1105,7 +1105,7 @@ mod tests {
11051105
panic!("expected config subcommand");
11061106
};
11071107

1108-
crate::config_edit::run(args, run.config).unwrap();
1108+
crate::config_command::run(args, run.config).unwrap();
11091109

11101110
let loaded = crate::config_file::load(&path).unwrap();
11111111
assert_eq!(

crates/openshell-server/src/config_edit.rs renamed to crates/openshell-server/src/config_command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Typed, comment-preserving updates to the gateway TOML configuration.
4+
//! CLI handlers for inspecting and updating the gateway TOML configuration.
55
66
use std::fs;
77
use std::io::Write;

crates/openshell-server/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod auth;
2727
pub mod certgen;
2828
pub mod cli;
2929
mod compute;
30-
mod config_edit;
30+
mod config_command;
3131
pub mod config_file;
3232
mod defaults;
3333
mod grpc;
@@ -840,8 +840,8 @@ fn configured_compute_driver(
840840
) -> Result<ConfiguredComputeDriver> {
841841
match config.compute_drivers.as_slice() {
842842
[] => {
843-
let detected = openshell_core::config::detect_drivers();
844-
let Some(driver) = detected.first().copied() else {
843+
let detection = openshell_core::config::detect_drivers();
844+
let Some(driver) = detection.selected else {
845845
return Err(Error::config(
846846
"no compute driver configured and auto-detection found no suitable driver; \
847847
install and start Docker or Podman, or install the VM driver and select it \
@@ -855,7 +855,7 @@ fn configured_compute_driver(
855855
));
856856
}
857857

858-
log_auto_detected_driver(config, driver, &detected);
858+
log_auto_detected_driver(config, driver, &detection.available);
859859
Ok(ConfiguredComputeDriver::Builtin(driver))
860860
}
861861
[driver] => resolve_configured_compute_driver(driver, driver_startup),

0 commit comments

Comments
 (0)