Skip to content

Commit f222c1e

Browse files
authored
Merge pull request #1110 from cgwalters/copy-to-storage-init-c-storage
storage: Ensure global c/storage is initialized via podman
2 parents cc025ed + 37d9b6e commit f222c1e

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

lib/src/image.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use serde::Serialize;
1414
use crate::{
1515
boundimage::query_bound_images,
1616
cli::{ImageListFormat, ImageListType},
17+
imgstorage::ensure_floating_c_storage_initialized,
1718
};
1819

1920
/// The name of the image we push to containers-storage if nothing is specified.
@@ -138,6 +139,7 @@ pub(crate) async fn push_entrypoint(source: Option<&str>, target: Option<&str>)
138139
name: target.to_owned(),
139140
}
140141
} else {
142+
ensure_floating_c_storage_initialized();
141143
ImageReference {
142144
transport: Transport::ContainerStorage,
143145
name: IMAGE_DEFAULT.to_string(),

lib/src/imgstorage.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,31 @@ fn new_podman_cmd_in(storage_root: &Dir, run_root: &Dir) -> Result<Command> {
119119
Ok(cmd)
120120
}
121121

122+
/// Ensure that "podman" is the first thing to touch the global storage
123+
/// instance. This is a workaround for https://github.com/containers/bootc/pull/1101#issuecomment-2653862974
124+
/// Basically podman has special upgrade logic for when it is the first thing
125+
/// to initialize the c/storage instance it sets the networking to netavark.
126+
/// If it's not the first thing, then it assumes an upgrade scenario and we
127+
/// may be using CNI.
128+
///
129+
/// But this legacy path is triggered through us using skopeo, turning off netavark
130+
/// by default. Work around this by ensuring that /usr/bin/podman is
131+
/// always the first thing to touch c/storage (at least, when invoked by us).
132+
///
133+
/// Call this function any time we're going to write to containers-storage.
134+
pub(crate) fn ensure_floating_c_storage_initialized() {
135+
if let Err(e) = Command::new("podman")
136+
.args(["system", "info"])
137+
.stdout(Stdio::null())
138+
.run()
139+
{
140+
// Out of conservatism we don't make this operation fatal right now.
141+
// If something went wrong, then we'll probably fail on a later operation
142+
// anyways.
143+
tracing::warn!("Failed to query podman system info: {e}");
144+
}
145+
}
146+
122147
impl Storage {
123148
/// Create a `podman image` Command instance prepared to operate on our alternative
124149
/// root.

tests/booted/test-image-pushpull-upgrade.nu

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ def initial_build [] {
3131
let td = mktemp -d
3232
cd $td
3333

34-
# Work around https://github.com/containers/bootc/pull/1101#issuecomment-2653862974
35-
# Basically things break unless "podman" initializes the c/storage instance right now.
36-
podman images -q o>/dev/null
37-
3834
bootc image copy-to-storage
3935
let img = podman image inspect localhost/bootc | from json
4036

tests/booted/test-logically-bound-switch.nu

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ let st = bootc status --json | from json
1717
let booted = $st.status.booted.image
1818

1919
def initial_setup [] {
20-
# Work around https://github.com/containers/bootc/pull/1101#issuecomment-2653862974
21-
# Basically things break unless "podman" initializes the c/storage instance right now.
22-
podman images -q o>/dev/null
2320
bootc image copy-to-storage
2421
podman images
2522
podman image inspect localhost/bootc | from json

0 commit comments

Comments
 (0)