Skip to content

Commit ac66187

Browse files
committed
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]>
1 parent bcbe7af commit ac66187

3 files changed

Lines changed: 35 additions & 73 deletions

File tree

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

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,26 @@ pub fn default_supervisor_image() -> String {
5050
}
5151

5252
fn default_supervisor_image_tag() -> String {
53-
resolve_supervisor_image_tag(
54-
option_env!("OPENSHELL_IMAGE_TAG"),
55-
option_env!("IMAGE_TAG"),
53+
resolve_supervisor_image_tag(&[
54+
option_env!("OPENSHELL_IMAGE_TAG").unwrap_or(""),
55+
option_env!("IMAGE_TAG").unwrap_or(""),
5656
env!("CARGO_PKG_VERSION"),
57-
)
57+
])
5858
}
5959

60-
/// Resolve the supervisor image tag from build-time inputs.
60+
/// Resolve the supervisor image tag from an ordered list of candidates.
6161
///
62-
/// Priority: `OPENSHELL_IMAGE_TAG` > `IMAGE_TAG` > `CARGO_PKG_VERSION`.
63-
/// Falls back to `"dev"` when the Cargo version is empty or `"0.0.0"`.
64-
/// Replaces `+` with `-` for OCI tag compatibility.
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.
6565
#[must_use]
66-
pub fn resolve_supervisor_image_tag(
67-
openshell_image_tag: Option<&str>,
68-
image_tag: Option<&str>,
69-
cargo_pkg_version: &str,
70-
) -> String {
71-
let tag = openshell_image_tag
72-
.filter(|tag| !tag.is_empty())
73-
.or_else(|| image_tag.filter(|tag| !tag.is_empty()))
74-
.unwrap_or_else(|| {
75-
if cargo_pkg_version.is_empty() || cargo_pkg_version == "0.0.0" {
76-
"dev"
77-
} else {
78-
cargo_pkg_version
79-
}
80-
});
81-
82-
tag.replace('+', "-")
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('+', "-")
8373
}
8474

8575
/// CDI device identifier for requesting all NVIDIA GPUs.
@@ -1111,33 +1101,27 @@ mod tests {
11111101
fn supervisor_image_tag_prefers_explicit_build_tags() {
11121102
use super::resolve_supervisor_image_tag;
11131103
assert_eq!(
1114-
resolve_supervisor_image_tag(Some("1.2.3"), Some("sha"), "0.0.0"),
1115-
"1.2.3",
1116-
);
1117-
assert_eq!(
1118-
resolve_supervisor_image_tag(None, Some("sha"), "0.0.0"),
1119-
"sha",
1120-
);
1121-
assert_eq!(resolve_supervisor_image_tag(None, None, "1.2.3"), "1.2.3",);
1122-
assert_eq!(
1123-
resolve_supervisor_image_tag(Some(""), Some(""), "0.0.0"),
1124-
"dev",
1104+
resolve_supervisor_image_tag(&["1.2.3", "sha", "0.0.0"]),
1105+
"1.2.3"
11251106
);
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");
11261110
assert_eq!(
1127-
resolve_supervisor_image_tag(Some("latest"), None, "1.2.3"),
1128-
"latest",
1111+
resolve_supervisor_image_tag(&["latest", "", "1.2.3"]),
1112+
"latest"
11291113
);
11301114
}
11311115

11321116
#[test]
11331117
fn supervisor_image_tag_sanitizes_build_metadata_for_oci() {
11341118
use super::resolve_supervisor_image_tag;
11351119
assert_eq!(
1136-
resolve_supervisor_image_tag(None, None, "0.0.37-dev.156+g1d3b741ee"),
1120+
resolve_supervisor_image_tag(&["", "", "0.0.37-dev.156+g1d3b741ee"]),
11371121
"0.0.37-dev.156-g1d3b741ee",
11381122
);
11391123
assert_eq!(
1140-
resolve_supervisor_image_tag(Some("0.0.37-dev.156+g1d3b741ee"), None, "0.0.0"),
1124+
resolve_supervisor_image_tag(&["0.0.37-dev.156+g1d3b741ee", "", "0.0.0"]),
11411125
"0.0.37-dev.156-g1d3b741ee",
11421126
);
11431127
}

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +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-
/// Return the default `ghcr.io/nvidia/openshell/supervisor:<tag>` reference
82-
/// used when no supervisor binary override is provided.
83-
pub fn default_docker_supervisor_image() -> String {
84-
format!(
85-
"{}:{}",
86-
openshell_core::config::DEFAULT_SUPERVISOR_IMAGE_REPO,
87-
default_docker_supervisor_image_tag()
88-
)
89-
}
90-
91-
fn default_docker_supervisor_image_tag() -> String {
92-
openshell_core::config::resolve_supervisor_image_tag(
93-
option_env!("OPENSHELL_IMAGE_TAG"),
94-
option_env!("IMAGE_TAG"),
95-
env!("CARGO_PKG_VERSION"),
96-
)
97-
}
98-
9981
/// Queried by the Docker driver to decide when a sandbox's supervisor
10082
/// relay is live. Implementations return `true` once a sandbox has an
10183
/// active `ConnectSupervisor` session registered.
@@ -3048,7 +3030,9 @@ fn resolve_supervisor_bin_source(
30483030

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

30543038
pub(crate) async fn resolve_supervisor_bin(

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

Lines changed: 8 additions & 14 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}",
@@ -2059,29 +2059,23 @@ fn configured_supervisor_image_takes_precedence_over_local_binaries() {
20592059
fn docker_supervisor_image_tag_prefers_explicit_build_tags() {
20602060
use openshell_core::config::resolve_supervisor_image_tag;
20612061
assert_eq!(
2062-
resolve_supervisor_image_tag(Some("1.2.3"), Some("sha"), "0.0.0"),
2063-
"1.2.3",
2064-
);
2065-
assert_eq!(
2066-
resolve_supervisor_image_tag(None, Some("sha"), "0.0.0"),
2067-
"sha",
2068-
);
2069-
assert_eq!(resolve_supervisor_image_tag(None, None, "1.2.3"), "1.2.3",);
2070-
assert_eq!(
2071-
resolve_supervisor_image_tag(Some(""), Some(""), "0.0.0"),
2072-
"dev",
2062+
resolve_supervisor_image_tag(&["1.2.3", "sha", "0.0.0"]),
2063+
"1.2.3"
20732064
);
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");
20742068
}
20752069

20762070
#[test]
20772071
fn docker_supervisor_image_tag_sanitizes_build_metadata_for_docker() {
20782072
use openshell_core::config::resolve_supervisor_image_tag;
20792073
assert_eq!(
2080-
resolve_supervisor_image_tag(None, None, "0.0.37-dev.156+g1d3b741ee"),
2074+
resolve_supervisor_image_tag(&["", "", "0.0.37-dev.156+g1d3b741ee"]),
20812075
"0.0.37-dev.156-g1d3b741ee",
20822076
);
20832077
assert_eq!(
2084-
resolve_supervisor_image_tag(Some("0.0.37-dev.156+g1d3b741ee"), None, "0.0.0",),
2078+
resolve_supervisor_image_tag(&["0.0.37-dev.156+g1d3b741ee", "", "0.0.0"]),
20852079
"0.0.37-dev.156-g1d3b741ee",
20862080
);
20872081
}

0 commit comments

Comments
 (0)