From 836cdd81bc78fff1d019b5a30f9985ccfd9c1245 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 16 Jun 2024 12:10:00 +0000 Subject: [PATCH] install: Fix install config kargs + to-filesystem I think this got broken in a refactoring; add test coverage. In general all the heavy lifting should move out of `baseline.rs`; a good way to do that is probably to take the next step of making it its own crate that doesn't depend on the bootc core logic perhaps. Closes: https://github.com/containers/bootc/issues/570 Signed-off-by: Colin Walters --- hack/Containerfile | 8 +++++++- .../install-test-configs}/50-test-kargs.toml | 0 lib/src/install.rs | 8 ++++++++ lib/src/install/baseline.rs | 8 -------- tests-integration/src/install.rs | 7 +++++++ 5 files changed, 22 insertions(+), 9 deletions(-) rename {ci/usr/lib/bootc/install => hack/install-test-configs}/50-test-kargs.toml (100%) diff --git a/hack/Containerfile b/hack/Containerfile index 63e654f7..3c414126 100644 --- a/hack/Containerfile +++ b/hack/Containerfile @@ -17,10 +17,16 @@ RUN mkdir -p /build/target/dev-rootfs # This can hold arbitrary extra content RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome make test-bin-archive && mkdir -p /out && cp target/bootc.tar.zst /out FROM $base +# We support e.g. adding cloud-init ARG variant= COPY hack/provision-derived.sh /tmp RUN /tmp/provision-derived.sh "$variant" && rm -f /tmp/*.sh +# Also copy in some default install configs we use for testing +COPY hack/install-test-configs/* /usr/lib/bootc/install/ +# Inject our built code COPY --from=build /out/bootc.tar.zst /tmp -COPY --from=build /build/target/dev-rootfs/ / RUN tar -C / --zstd -xvf /tmp/bootc.tar.zst && rm -vf /tmp/* +# Also copy over arbitrary bits from the target root +COPY --from=build /build/target/dev-rootfs/ / +# Test our own linting RUN bootc container lint diff --git a/ci/usr/lib/bootc/install/50-test-kargs.toml b/hack/install-test-configs/50-test-kargs.toml similarity index 100% rename from ci/usr/lib/bootc/install/50-test-kargs.toml rename to hack/install-test-configs/50-test-kargs.toml diff --git a/lib/src/install.rs b/lib/src/install.rs index b6c91c44..dcc1eef7 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -642,10 +642,18 @@ async fn initialize_ostree_root_from_self( imgref: src_imageref, }; + let install_config_kargs = state + .install_config + .as_ref() + .and_then(|c| c.kargs.as_ref()) + .into_iter() + .flatten() + .map(|s| s.as_str()); let kargs = root_setup .kargs .iter() .map(|v| v.as_str()) + .chain(install_config_kargs) .chain(state.config_opts.karg.iter().flatten().map(|v| v.as_str())) .collect::>(); let mut options = ostree_container::deploy::DeployOpts::default(); diff --git a/lib/src/install/baseline.rs b/lib/src/install/baseline.rs index 559b6eb6..ad470c55 100644 --- a/lib/src/install/baseline.rs +++ b/lib/src/install/baseline.rs @@ -401,19 +401,11 @@ pub(crate) fn install_create_rootfs( fstype: MountSpec::AUTO.into(), options: Some("ro".into()), }); - let install_config_kargs = state - .install_config - .as_ref() - .and_then(|c| c.kargs.as_ref()) - .into_iter() - .flatten() - .map(ToOwned::to_owned); let kargs = root_blockdev_kargs .into_iter() .flatten() .chain([rootarg, RW_KARG.to_string()].into_iter()) .chain(bootarg) - .chain(install_config_kargs) .collect::>(); mount::mount(&rootdev, &rootfs)?; diff --git a/tests-integration/src/install.rs b/tests-integration/src/install.rs index fae06479..fc390bb7 100644 --- a/tests-integration/src/install.rs +++ b/tests-integration/src/install.rs @@ -88,11 +88,18 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments) std::fs::write(&tmp_keys, b"ssh-ed25519 ABC0123 testcase@example.com")?; cmd!(sh, "sudo {BASE_ARGS...} {target_args...} -v {tmp_keys}:/test_authorized_keys {image} bootc install to-filesystem {generic_inst_args...} --acknowledge-destructive --karg=foo=bar --replace=alongside --root-ssh-authorized-keys=/test_authorized_keys /target").run()?; + // Test kargs injected via CLI cmd!( sh, "sudo /bin/sh -c 'grep foo=bar /boot/loader/entries/*.conf'" ) .run()?; + // And kargs we added into our default container image + cmd!( + sh, + "sudo /bin/sh -c 'grep localtestkarg=somevalue /boot/loader/entries/*.conf'" + ) + .run()?; let deployment = &find_deployment_root()?; let cwd = sh.push_dir(format!("/proc/self/fd/{}", deployment.as_raw_fd())); cmd!(