Skip to content

Commit be2ae67

Browse files
committed
storage: Ensure global c/storage is initialized via podman
Two of our tests (and an unknown set of users may) run `bootc image copy-to-storage` which happens to invoke skopeo to target /var/lib/containers/storage. If this happens to be the *first* thing to write to that c/storage instance it triggers a bug around the podman image network setup. Signed-off-by: Colin Walters <[email protected]>
1 parent 8decbcd commit be2ae67

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
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.

0 commit comments

Comments
 (0)