Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: Make stateroot configurable #622

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ use crate::store::Storage;
use crate::task::Task;
use crate::utils::sigpolicy_from_opts;

/// The default "stateroot" or "osname"; see https://github.com/ostreedev/ostree/issues/2794
const STATEROOT_DEFAULT: &str = "default";
/// The toplevel boot directory
const BOOT: &str = "boot";
/// Directory for transient runtime state
Expand Down Expand Up @@ -171,6 +169,10 @@ pub(crate) struct InstallConfigOpts {
#[clap(long, hide = true)]
#[serde(default)]
pub(crate) skip_bound_images: bool,

/// The stateroot name to use. Defaults to `default`.
#[clap(long)]
pub(crate) stateroot: Option<String>,
}

#[derive(Debug, Clone, clap::Parser, Serialize, Deserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -567,8 +569,12 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
// Another implementation: https://github.com/coreos/coreos-assembler/blob/3cd3307904593b3a131b81567b13a4d0b6fe7c90/src/create_disk.sh#L295
crate::lsm::ensure_dir_labeled(rootfs_dir, "", Some("/".into()), 0o755.into(), sepolicy)?;

// TODO: make configurable?
let stateroot = STATEROOT_DEFAULT;
let stateroot = state
.config_opts
.stateroot
.as_deref()
.unwrap_or(ostree_ext::container::deploy::STATEROOT_DEFAULT);

Task::new_and_run(
"Initializing ostree layout",
"ostree",
Expand Down Expand Up @@ -638,7 +644,11 @@ async fn install_container(
) -> Result<(ostree::Deployment, InstallAleph)> {
let sepolicy = state.load_policy()?;
let sepolicy = sepolicy.as_ref();
let stateroot = STATEROOT_DEFAULT;
let stateroot = state
.config_opts
.stateroot
.as_deref()
.unwrap_or(ostree_ext::container::deploy::STATEROOT_DEFAULT);
omertuc marked this conversation as resolved.
Show resolved Hide resolved

let container_rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;

Expand Down Expand Up @@ -1099,7 +1109,9 @@ pub(crate) fn setup_sys_mount(fstype: &str, fspath: &str) -> Result<()> {
Task::new(format!("Mounting {fstype} {fspath}"), "mount")
.args(["-t", fstype, fstype, fspath])
.quiet()
.run()
.run()?;

Ok(())
}

/// Verify that we can load the manifest of the target image
Expand Down
13 changes: 13 additions & 0 deletions tests-integration/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub(crate) const BASE_ARGS: &[&str] = &[
"label=disable",
];

// Arbitrary
const NON_DEFAULT_STATEROOT: &str = "foo";

/// Clear out and delete any ostree roots, leverage bootc hidden wipe-ostree command to get rid of
/// otherwise hard to delete deployment files
fn reset_root(sh: &Shell, image: &str) -> Result<()> {
Expand Down Expand Up @@ -144,6 +147,16 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
crate::selinux::verify_selinux_recurse(root, &mut path, false)?;
Ok(())
}),
Trial::test("Install to non-default stateroot", move || {
let sh = &xshell::Shell::new()?;
reset_root(sh, image)?;
cmd!(sh, "sudo {BASE_ARGS...} {target_args...} {image} bootc install to-existing-root --stateroot {NON_DEFAULT_STATEROOT} --acknowledge-destructive {generic_inst_args...}").run()?;
generic_post_install_verification()?;
assert!(
Utf8Path::new(&format!("/ostree/deploy/{NON_DEFAULT_STATEROOT}")).try_exists()?
);
Ok(())
}),
Trial::test("without an install config", move || {
let sh = &xshell::Shell::new()?;
reset_root(sh, image)?;
Expand Down