Skip to content

Commit ebf2c08

Browse files
committed
ephemeral: Handle images with cloud-init
The bootc test suite adds this because of testcloud/tmt, and without providing a metadata source we'll just time out. While we're here, namespace our environment variables. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 5e20ada commit ebf2c08

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

crates/kit/src/run_ephemeral.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
use std::fs::File;
9191
use std::io::{BufWriter, Seek, Write};
9292
use std::os::unix::process::CommandExt;
93-
use std::process::Command;
93+
use std::process::{Command, Stdio};
9494

9595
use bootc_utils::CommandRunExt;
9696
use camino::{Utf8Path, Utf8PathBuf};
@@ -708,6 +708,21 @@ pub(crate) async fn run_impl(opts: RunEphemeralOpts) -> Result<()> {
708708
};
709709
debug!("Container image systemd version: {systemd_version:?}");
710710

711+
// Check if we need to handle cloud-init
712+
let cloudinit = {
713+
Command::new("systemctl")
714+
.args([
715+
"--root=/run/source-image",
716+
"is-enabled",
717+
"cloud-init.target",
718+
])
719+
.stdout(Stdio::null())
720+
.stderr(Stdio::null())
721+
.status()?
722+
.success()
723+
};
724+
tracing::debug!("Target image has cloud-init: {cloudinit}");
725+
711726
// Find kernel and initramfs from the container image (not the host)
712727
let modules_dir = Utf8Path::new("/run/source-image/usr/lib/modules");
713728
let mut vmlinuz_path = None;
@@ -974,6 +989,12 @@ StandardOutput=file:/dev/virtio-ports/executestatus
974989
if opts.common.console {
975990
kernel_cmdline.push("console=ttyS0".to_string());
976991
}
992+
if cloudinit {
993+
// We don't provide any cloud-init datasource right now,
994+
// though in the future it would make sense to do so,
995+
// and switch over our SSH key injection.
996+
kernel_cmdline.push("ds=iid-datasource-none".to_string());
997+
}
977998

978999
kernel_cmdline.extend(opts.common.kernel_args.clone());
9791000

0 commit comments

Comments
 (0)