Skip to content

Commit fe10204

Browse files
committed
wip
1 parent de8b477 commit fe10204

File tree

7 files changed

+88
-7
lines changed

7 files changed

+88
-7
lines changed

crates/lib/src/cli.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ async fn upgrade(
943943
}
944944
} else {
945945
// Check if image exists in bootc storage (/usr/lib/bootc/storage)
946-
let imgstore = sysroot.get_ensure_imgstore()?;
946+
let imgstore = storage.get_ensure_imgstore()?;
947947

948948
let image_ref_str = crate::utils::imageref_to_container_ref(imgref);
949949

@@ -958,7 +958,7 @@ async fn upgrade(
958958
};
959959

960960
let fetched = if use_unified {
961-
crate::deploy::pull_unified(repo, imgref, None, opts.quiet, prog.clone(), sysroot)
961+
crate::deploy::pull_unified(repo, imgref, None, opts.quiet, prog.clone(), storage)
962962
.await?
963963
} else {
964964
crate::deploy::pull(repo, imgref, None, opts.quiet, prog.clone()).await?
@@ -1077,7 +1077,7 @@ async fn switch_ostree(
10771077
let new_spec = RequiredHostSpec::from_spec(&new_spec)?;
10781078

10791079
// Check if image exists in bootc storage (/usr/lib/bootc/storage)
1080-
let imgstore = sysroot.get_ensure_imgstore()?;
1080+
let imgstore = storage.get_ensure_imgstore()?;
10811081

10821082
let target_ref_str = crate::utils::imageref_to_container_ref(&target);
10831083

@@ -1092,7 +1092,7 @@ async fn switch_ostree(
10921092
};
10931093

10941094
let fetched = if use_unified {
1095-
crate::deploy::pull_unified(repo, &target, None, opts.quiet, prog.clone(), sysroot).await?
1095+
crate::deploy::pull_unified(repo, &target, None, opts.quiet, prog.clone(), storage).await?
10961096
} else {
10971097
crate::deploy::pull(repo, &target, None, opts.quiet, prog.clone()).await?
10981098
};

crates/lib/src/deploy.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ pub(crate) async fn new_importer(
9393
Ok(imp)
9494
}
9595

96+
/// Wrapper for pulling a container image with a custom proxy config (e.g. for unified storage).
97+
pub(crate) async fn new_importer_with_config(
98+
repo: &ostree::Repo,
99+
imgref: &ostree_container::OstreeImageReference,
100+
config: ostree_ext::containers_image_proxy::ImageProxyConfig,
101+
) -> Result<ostree_container::store::ImageImporter> {
102+
let mut imp = ostree_container::store::ImageImporter::new(repo, imgref, config).await?;
103+
imp.require_bootable();
104+
Ok(imp)
105+
}
106+
96107
pub(crate) fn check_bootc_label(config: &ostree_ext::oci_spec::image::ImageConfiguration) {
97108
if let Some(label) =
98109
labels_of_config(config).and_then(|labels| labels.get(crate::metadata::BOOTC_COMPAT_LABEL))
@@ -414,8 +425,17 @@ pub(crate) async fn prepare_for_pull_unified(
414425
};
415426
let ostree_imgref = OstreeImageReference::from(containers_storage_imgref);
416427

417-
// Use the standard preparation flow but reading from containers-storage
418-
let mut imp = new_importer(repo, &ostree_imgref).await?;
428+
// Configure the importer to use bootc storage as an additional image store
429+
use std::process::Command;
430+
let mut config = ostree_ext::containers_image_proxy::ImageProxyConfig::default();
431+
let mut cmd = Command::new("skopeo");
432+
// Use the actual physical path to bootc storage, not the alias
433+
let storage_path = format!("/sysroot/{}", crate::podstorage::CStorage::subpath());
434+
crate::podstorage::set_additional_image_store(&mut cmd, &storage_path);
435+
config.skopeo_cmd = Some(cmd);
436+
437+
// Use the preparation flow with the custom config
438+
let mut imp = new_importer_with_config(repo, &ostree_imgref, config).await?;
419439
if let Some(target) = target_imgref {
420440
imp.set_target(target);
421441
}

crates/lib/src/podstorage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl CStorage {
387387
Ok(())
388388
}
389389

390-
fn subpath() -> Utf8PathBuf {
390+
pub(crate) fn subpath() -> Utf8PathBuf {
391391
Utf8Path::new(crate::store::BOOTC_ROOT).join(SUBPATH)
392392
}
393393
}

crates/lib/src/utils.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ pub(crate) fn path_relative_to(from: &Path, to: &Path) -> Result<PathBuf> {
277277
return Ok(final_path);
278278
}
279279

280+
/// Converts an ImageReference to a container reference string suitable for use with container storage APIs.
281+
/// For registry transport, returns just the image name. For other transports, prepends the transport.
282+
pub(crate) fn imageref_to_container_ref(imgref: &crate::spec::ImageReference) -> String {
283+
if imgref.transport == "registry" {
284+
// For registry transport, the image name is already in the right format
285+
imgref.image.clone()
286+
} else {
287+
// For other transports (containers-storage, oci, etc.), prepend the transport
288+
format!("{}:{}", imgref.transport, imgref.image)
289+
}
290+
}
291+
280292
#[cfg(test)]
281293
mod tests {
282294
use super::*;
@@ -337,4 +349,39 @@ mod tests {
337349
assert!(have_executable("true").unwrap());
338350
assert!(!have_executable("someexethatdoesnotexist").unwrap());
339351
}
352+
353+
#[test]
354+
fn test_imageref_to_container_ref() {
355+
use crate::spec::ImageReference;
356+
357+
// Test registry transport (should return only the image name)
358+
let registry_ref = ImageReference {
359+
transport: "registry".to_string(),
360+
image: "quay.io/example/foo:latest".to_string(),
361+
signature: None,
362+
};
363+
assert_eq!(
364+
imageref_to_container_ref(&registry_ref),
365+
"quay.io/example/foo:latest"
366+
);
367+
368+
// Test containers-storage transport
369+
let storage_ref = ImageReference {
370+
transport: "containers-storage".to_string(),
371+
image: "localhost/bootc".to_string(),
372+
signature: None,
373+
};
374+
assert_eq!(
375+
imageref_to_container_ref(&storage_ref),
376+
"containers-storage:localhost/bootc"
377+
);
378+
379+
// Test oci transport
380+
let oci_ref = ImageReference {
381+
transport: "oci".to_string(),
382+
image: "/path/to/image".to_string(),
383+
signature: None,
384+
};
385+
assert_eq!(imageref_to_container_ref(&oci_ref), "oci:/path/to/image");
386+
}
340387
}

tmt/plans/integration.fmf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,17 @@ execute:
112112
how: fmf
113113
test:
114114
- /tmt/tests/test-28-factory-reset
115+
116+
/test-29-install-unified-flag:
117+
summary: Verify install help exposes experimental unified storage flag
118+
discover:
119+
how: fmf
120+
test:
121+
- /tmt/tests/test-28-install-unified-flag
122+
123+
/test-30-switch-to-unified:
124+
summary: Onboard to unified storage and verify subsequent operations use it
125+
discover:
126+
how: fmf
127+
test:
128+
- /tmt/tests/test-29-switch-to-unified
File renamed without changes.

0 commit comments

Comments
 (0)