Skip to content

Commit 1070213

Browse files
authored
fix(core): pin supervisor image tag to gateway version for all drivers (#2070)
* fix(core): pin supervisor image tag to gateway version for all drivers The Podman and Kubernetes drivers defaulted the supervisor image to `:latest` via DEFAULT_SUPERVISOR_IMAGE, while the Docker driver already resolved a version-pinned tag. Extract the tag resolution logic into openshell-core so all three drivers use the same OPENSHELL_IMAGE_TAG > IMAGE_TAG > CARGO_PKG_VERSION priority chain. Closes #2068 Signed-off-by: Florent Benoit <[email protected]> * refactor(core): simplify supervisor image tag resolver to slice-based API Remove the Docker driver's wrapper functions and call openshell_core::config::default_supervisor_image() directly. Simplify resolve_supervisor_image_tag to accept &[&str] instead of three separate parameters. Signed-off-by: Florent Benoit <[email protected]> Signed-off-by: Florent Benoit <[email protected]> --------- Signed-off-by: Florent Benoit <[email protected]> Signed-off-by: Florent Benoit <[email protected]>
1 parent 233d207 commit 1070213

9 files changed

Lines changed: 105 additions & 86 deletions

File tree

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

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,40 @@ pub const DEFAULT_DOCKER_NETWORK_NAME: &str = "openshell-docker";
3737
/// Default domain used for browser-facing sandbox service URLs.
3838
pub const DEFAULT_SERVICE_ROUTING_DOMAIN: &str = "openshell.localhost";
3939

40-
/// Default OCI image for the openshell-sandbox supervisor binary.
41-
pub const DEFAULT_SUPERVISOR_IMAGE: &str = "ghcr.io/nvidia/openshell/supervisor:latest";
40+
/// Default OCI repository for the supervisor image (no tag).
41+
pub const DEFAULT_SUPERVISOR_IMAGE_REPO: &str = "ghcr.io/nvidia/openshell/supervisor";
42+
43+
/// Return the default supervisor image reference with a version-pinned tag.
44+
#[must_use]
45+
pub fn default_supervisor_image() -> String {
46+
format!(
47+
"{DEFAULT_SUPERVISOR_IMAGE_REPO}:{}",
48+
default_supervisor_image_tag()
49+
)
50+
}
51+
52+
fn default_supervisor_image_tag() -> String {
53+
resolve_supervisor_image_tag(&[
54+
option_env!("OPENSHELL_IMAGE_TAG").unwrap_or(""),
55+
option_env!("IMAGE_TAG").unwrap_or(""),
56+
env!("CARGO_PKG_VERSION"),
57+
])
58+
}
59+
60+
/// Resolve the supervisor image tag from an ordered list of candidates.
61+
///
62+
/// Returns the first non-empty, non-`"0.0.0"` candidate, falling back to
63+
/// `"dev"` when none qualifies. Replaces `+` with `-` for OCI tag
64+
/// compatibility.
65+
#[must_use]
66+
pub fn resolve_supervisor_image_tag(candidates: &[&str]) -> String {
67+
candidates
68+
.iter()
69+
.copied()
70+
.find(|t| !t.is_empty() && *t != "0.0.0")
71+
.unwrap_or("dev")
72+
.replace('+', "-")
73+
}
4274

4375
/// CDI device identifier for requesting all NVIDIA GPUs.
4476
pub const CDI_GPU_DEVICE_ALL: &str = "nvidia.com/gpu=all";
@@ -1064,4 +1096,42 @@ mod tests {
10641096
}
10651097
}
10661098
}
1099+
1100+
#[test]
1101+
fn supervisor_image_tag_prefers_explicit_build_tags() {
1102+
use super::resolve_supervisor_image_tag;
1103+
assert_eq!(
1104+
resolve_supervisor_image_tag(&["1.2.3", "sha", "0.0.0"]),
1105+
"1.2.3"
1106+
);
1107+
assert_eq!(resolve_supervisor_image_tag(&["", "sha", "0.0.0"]), "sha");
1108+
assert_eq!(resolve_supervisor_image_tag(&["", "", "1.2.3"]), "1.2.3");
1109+
assert_eq!(resolve_supervisor_image_tag(&["", "", "0.0.0"]), "dev");
1110+
assert_eq!(
1111+
resolve_supervisor_image_tag(&["latest", "", "1.2.3"]),
1112+
"latest"
1113+
);
1114+
}
1115+
1116+
#[test]
1117+
fn supervisor_image_tag_sanitizes_build_metadata_for_oci() {
1118+
use super::resolve_supervisor_image_tag;
1119+
assert_eq!(
1120+
resolve_supervisor_image_tag(&["", "", "0.0.37-dev.156+g1d3b741ee"]),
1121+
"0.0.37-dev.156-g1d3b741ee",
1122+
);
1123+
assert_eq!(
1124+
resolve_supervisor_image_tag(&["0.0.37-dev.156+g1d3b741ee", "", "0.0.0"]),
1125+
"0.0.37-dev.156-g1d3b741ee",
1126+
);
1127+
}
1128+
1129+
#[test]
1130+
fn default_supervisor_image_is_version_pinned() {
1131+
use super::default_supervisor_image;
1132+
let image = default_supervisor_image();
1133+
assert!(image.starts_with("ghcr.io/nvidia/openshell/supervisor:"));
1134+
let tag = image.rsplit_once(':').unwrap().1;
1135+
assert!(!tag.is_empty());
1136+
}
10671137
}

‎crates/openshell-driver-docker/src/lib.rs‎

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -78,55 +78,6 @@ const HOST_OPENSHELL_INTERNAL: &str = "host.openshell.internal";
7878
const HOST_DOCKER_INTERNAL: &str = "host.docker.internal";
7979
const DOCKER_NETWORK_DRIVER: &str = "bridge";
8080

81-
/// Default image holding the Linux `openshell-sandbox` binary. The gateway
82-
/// pulls this image and extracts the binary to a host-side cache when no
83-
/// explicit `supervisor_bin`, configured `supervisor_image`, sibling binary,
84-
/// or local build is available.
85-
const DEFAULT_DOCKER_SUPERVISOR_IMAGE_REPO: &str = "ghcr.io/nvidia/openshell/supervisor";
86-
87-
/// Return the default `ghcr.io/nvidia/openshell/supervisor:<tag>` reference
88-
/// used when no supervisor binary override is provided.
89-
pub fn default_docker_supervisor_image() -> String {
90-
format!(
91-
"{DEFAULT_DOCKER_SUPERVISOR_IMAGE_REPO}:{}",
92-
default_docker_supervisor_image_tag()
93-
)
94-
}
95-
96-
/// Image tag baked in at compile time to pair the gateway with a matching
97-
/// supervisor image.
98-
///
99-
/// Build pipelines pass `OPENSHELL_IMAGE_TAG` explicitly. The `IMAGE_TAG`
100-
/// fallback covers image build wrappers that already tag the gateway and
101-
/// supervisor together. Standalone release binaries also patch the Cargo
102-
/// package version, so use it when it has been set to a real release value.
103-
fn default_docker_supervisor_image_tag() -> String {
104-
resolve_default_docker_supervisor_image_tag(
105-
option_env!("OPENSHELL_IMAGE_TAG"),
106-
option_env!("IMAGE_TAG"),
107-
env!("CARGO_PKG_VERSION"),
108-
)
109-
}
110-
111-
fn resolve_default_docker_supervisor_image_tag(
112-
openshell_image_tag: Option<&'static str>,
113-
image_tag: Option<&'static str>,
114-
cargo_pkg_version: &'static str,
115-
) -> String {
116-
let tag = openshell_image_tag
117-
.filter(|tag| !tag.is_empty())
118-
.or_else(|| image_tag.filter(|tag| !tag.is_empty()))
119-
.unwrap_or_else(|| {
120-
if cargo_pkg_version.is_empty() || cargo_pkg_version == "0.0.0" {
121-
"dev"
122-
} else {
123-
cargo_pkg_version
124-
}
125-
});
126-
127-
tag.replace('+', "-")
128-
}
129-
13081
/// Queried by the Docker driver to decide when a sandbox's supervisor
13182
/// relay is live. Implementations return `true` once a sandbox has an
13283
/// active `ConnectSupervisor` session registered.
@@ -3079,7 +3030,9 @@ fn resolve_supervisor_bin_source(
30793030

30803031
// Tier 5: pull the release-matched default supervisor image and extract
30813032
// the binary to a host-side cache keyed by image content digest.
3082-
Ok(SupervisorBinSource::Image(default_docker_supervisor_image()))
3033+
Ok(SupervisorBinSource::Image(
3034+
openshell_core::config::default_supervisor_image(),
3035+
))
30833036
}
30843037

30853038
pub(crate) async fn resolve_supervisor_bin(

‎crates/openshell-driver-docker/src/tests.rs‎

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ fn docker_guest_tls_paths_allows_plain_http_without_tls_flags() {
20182018

20192019
#[test]
20202020
fn default_docker_supervisor_image_uses_nvidia_ghcr_repo() {
2021-
let image = default_docker_supervisor_image();
2021+
let image = openshell_core::config::default_supervisor_image();
20222022
assert!(
20232023
image.starts_with("ghcr.io/nvidia/openshell/supervisor:"),
20242024
"unexpected default image reference: {image}",
@@ -2057,36 +2057,25 @@ fn configured_supervisor_image_takes_precedence_over_local_binaries() {
20572057

20582058
#[test]
20592059
fn docker_supervisor_image_tag_prefers_explicit_build_tags() {
2060+
use openshell_core::config::resolve_supervisor_image_tag;
20602061
assert_eq!(
2061-
resolve_default_docker_supervisor_image_tag(Some("1.2.3"), Some("sha"), "0.0.0"),
2062-
"1.2.3",
2063-
);
2064-
assert_eq!(
2065-
resolve_default_docker_supervisor_image_tag(None, Some("sha"), "0.0.0"),
2066-
"sha",
2067-
);
2068-
assert_eq!(
2069-
resolve_default_docker_supervisor_image_tag(None, None, "1.2.3"),
2070-
"1.2.3",
2071-
);
2072-
assert_eq!(
2073-
resolve_default_docker_supervisor_image_tag(Some(""), Some(""), "0.0.0"),
2074-
"dev",
2062+
resolve_supervisor_image_tag(&["1.2.3", "sha", "0.0.0"]),
2063+
"1.2.3"
20752064
);
2065+
assert_eq!(resolve_supervisor_image_tag(&["", "sha", "0.0.0"]), "sha");
2066+
assert_eq!(resolve_supervisor_image_tag(&["", "", "1.2.3"]), "1.2.3");
2067+
assert_eq!(resolve_supervisor_image_tag(&["", "", "0.0.0"]), "dev");
20762068
}
20772069

20782070
#[test]
20792071
fn docker_supervisor_image_tag_sanitizes_build_metadata_for_docker() {
2072+
use openshell_core::config::resolve_supervisor_image_tag;
20802073
assert_eq!(
2081-
resolve_default_docker_supervisor_image_tag(None, None, "0.0.37-dev.156+g1d3b741ee"),
2074+
resolve_supervisor_image_tag(&["", "", "0.0.37-dev.156+g1d3b741ee"]),
20822075
"0.0.37-dev.156-g1d3b741ee",
20832076
);
20842077
assert_eq!(
2085-
resolve_default_docker_supervisor_image_tag(
2086-
Some("0.0.37-dev.156+g1d3b741ee"),
2087-
None,
2088-
"0.0.0",
2089-
),
2078+
resolve_supervisor_image_tag(&["0.0.37-dev.156+g1d3b741ee", "", "0.0.0"]),
20902079
"0.0.37-dev.156-g1d3b741ee",
20912080
);
20922081
}

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

Lines changed: 2 additions & 2 deletions
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-
use openshell_core::config::DEFAULT_SUPERVISOR_IMAGE;
4+
use openshell_core::config;
55
use serde::{Deserialize, Deserializer, Serialize};
66
use std::path::Path;
77
use std::str::FromStr;
@@ -288,7 +288,7 @@ impl Default for KubernetesComputeConfig {
288288
// is Podman vocabulary and is not a valid Kubernetes value.
289289
image_pull_policy: String::new(),
290290
image_pull_secrets: Vec::new(),
291-
supervisor_image: DEFAULT_SUPERVISOR_IMAGE.to_string(),
291+
supervisor_image: config::default_supervisor_image(),
292292
supervisor_image_pull_policy: String::new(),
293293
supervisor_sideload_method: SupervisorSideloadMethod::default(),
294294
supervisor_topology: SupervisorTopology::default(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async fn main() -> Result<()> {
127127
image_pull_secrets: args.sandbox_image_pull_secrets,
128128
supervisor_image: args
129129
.supervisor_image
130-
.unwrap_or_else(|| openshell_core::config::DEFAULT_SUPERVISOR_IMAGE.to_string()),
130+
.unwrap_or_else(openshell_core::config::default_supervisor_image),
131131
supervisor_image_pull_policy: args.supervisor_image_pull_policy.unwrap_or_default(),
132132
supervisor_sideload_method: args.supervisor_sideload_method,
133133
supervisor_topology: args.supervisor_topology,

‎crates/openshell-driver-podman/src/config.rs‎

Lines changed: 2 additions & 2 deletions
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-
use openshell_core::config::{DEFAULT_STOP_TIMEOUT_SECS, DEFAULT_SUPERVISOR_IMAGE};
4+
use openshell_core::config::DEFAULT_STOP_TIMEOUT_SECS;
55
use std::net::IpAddr;
66
use std::path::PathBuf;
77
use std::str::FromStr;
@@ -255,7 +255,7 @@ impl Default for PodmanComputeConfig {
255255
network_name: DEFAULT_NETWORK_NAME.to_string(),
256256
host_gateway_ip: Self::default_host_gateway_ip(),
257257
stop_timeout_secs: DEFAULT_STOP_TIMEOUT_SECS,
258-
supervisor_image: DEFAULT_SUPERVISOR_IMAGE.to_string(),
258+
supervisor_image: openshell_core::config::default_supervisor_image(),
259259
guest_tls_ca: None,
260260
guest_tls_cert: None,
261261
guest_tls_key: None,

‎crates/openshell-driver-podman/src/container.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,7 @@ mod tests {
18361836
let vol = &image_volumes[0];
18371837
assert_eq!(
18381838
vol["source"].as_str(),
1839-
Some("ghcr.io/nvidia/openshell/supervisor:latest"),
1839+
Some(openshell_core::config::default_supervisor_image().as_str()),
18401840
"image volume source should be the supervisor image"
18411841
);
18421842
assert_eq!(
@@ -1922,8 +1922,9 @@ mod tests {
19221922
let image_volumes = spec["image_volumes"]
19231923
.as_array()
19241924
.expect("image_volumes should be an array");
1925+
let expected_supervisor = openshell_core::config::default_supervisor_image();
19251926
assert!(image_volumes.iter().any(|volume| {
1926-
volume["source"].as_str() == Some("ghcr.io/nvidia/openshell/supervisor:latest")
1927+
volume["source"].as_str() == Some(expected_supervisor.as_str())
19271928
&& volume["destination"].as_str() == Some("/opt/openshell/bin")
19281929
}));
19291930
assert!(image_volumes.iter().any(|volume| {

‎crates/openshell-driver-podman/src/main.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct Args {
9090

9191
/// OCI image containing the openshell-sandbox supervisor binary.
9292
#[arg(long, env = "OPENSHELL_SUPERVISOR_IMAGE")]
93-
supervisor_image: String,
93+
supervisor_image: Option<String>,
9494

9595
/// Host path to the CA certificate for sandbox mTLS.
9696
#[arg(long, env = "OPENSHELL_PODMAN_TLS_CA")]
@@ -130,7 +130,9 @@ async fn main() -> Result<()> {
130130
sandbox_ssh_socket_path: args.sandbox_ssh_socket_path,
131131
network_name: args.network_name,
132132
stop_timeout_secs: args.stop_timeout,
133-
supervisor_image: args.supervisor_image,
133+
supervisor_image: args
134+
.supervisor_image
135+
.unwrap_or_else(openshell_core::config::default_supervisor_image),
134136
guest_tls_ca: args.podman_tls_ca,
135137
guest_tls_cert: args.podman_tls_cert,
136138
guest_tls_key: args.podman_tls_key,

‎docs/reference/gateway-config.mdx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ disable_tls = false
8888
# Shared driver defaults. These inherit into [openshell.drivers.<name>] tables
8989
# when the driver-specific table does not override them.
9090
default_image = "ghcr.io/nvidia/openshell/sandbox:latest"
91-
supervisor_image = "ghcr.io/nvidia/openshell/supervisor:latest"
91+
# Defaults to the gateway version; override to pin a specific build.
92+
# supervisor_image = "ghcr.io/nvidia/openshell/supervisor:<version>"
9293
client_tls_secret_name = "openshell-client-tls"
9394
service_account_name = "openshell-sandbox"
9495
host_gateway_ip = "10.0.0.1"
@@ -172,7 +173,8 @@ service_account_name = "openshell-sandbox"
172173
default_image = "ghcr.io/nvidia/openshell/sandbox:latest"
173174
image_pull_policy = "IfNotPresent"
174175
image_pull_secrets = ["regcred"]
175-
supervisor_image = "ghcr.io/nvidia/openshell/supervisor:latest"
176+
# Defaults to the gateway version; override to pin a specific build.
177+
# supervisor_image = "ghcr.io/nvidia/openshell/supervisor:<version>"
176178
supervisor_image_pull_policy = "IfNotPresent"
177179
# Use the image volume on Kubernetes >= 1.35 (GA in 1.36); switch to "init-container"
178180
# on older clusters or where the ImageVolume feature gate is off.
@@ -228,7 +230,8 @@ grpc_endpoint = "https://host.openshell.internal:17670"
228230
# Skip the image-pull-and-extract step by pointing at a locally built binary.
229231
supervisor_bin = "/usr/local/libexec/openshell/openshell-sandbox"
230232
# When supervisor_bin is omitted, Docker extracts /openshell-sandbox from this image.
231-
supervisor_image = "ghcr.io/nvidia/openshell/supervisor:latest"
233+
# Defaults to the gateway version; override to pin a specific build.
234+
# supervisor_image = "ghcr.io/nvidia/openshell/supervisor:<version>"
232235
guest_tls_ca = "/etc/openshell/certs/ca.pem"
233236
guest_tls_cert = "/etc/openshell/certs/client.pem"
234237
guest_tls_key = "/etc/openshell/certs/client-key.pem"
@@ -270,7 +273,8 @@ network_name = "openshell"
270273
# host_gateway_ip = "192.168.127.254"
271274
sandbox_ssh_socket_path = "/run/openshell/ssh.sock"
272275
stop_timeout_secs = 10
273-
supervisor_image = "ghcr.io/nvidia/openshell/supervisor:latest"
276+
# Defaults to the gateway version; override to pin a specific build.
277+
# supervisor_image = "ghcr.io/nvidia/openshell/supervisor:<version>"
274278
guest_tls_ca = "/etc/openshell/certs/ca.pem"
275279
guest_tls_cert = "/etc/openshell/certs/client.pem"
276280
guest_tls_key = "/etc/openshell/certs/client-key.pem"

0 commit comments

Comments
 (0)