Skip to content

Commit

Permalink
Add support for configmaps
Browse files Browse the repository at this point in the history
This is part of containers#22
  • Loading branch information
cgwalters committed Jun 18, 2023
1 parent 730c07e commit 6b0a900
Show file tree
Hide file tree
Showing 9 changed files with 919 additions and 25 deletions.
7 changes: 6 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ hex = "^0.4"
fn-error-context = "0.2.0"
gvariant = "0.4.0"
indicatif = "0.17.0"
k8s-openapi = { version = "0.17.0", features = ["v1_25"], optional = true }
libc = "^0.2"
liboverdrop = "0.1.0"
once_cell = "1.9"
Expand All @@ -36,11 +37,15 @@ tempfile = "3.3.0"
toml = "0.7.2"
xshell = { version = "0.2", optional = true }
uuid = { version = "1.2.2", features = ["v4"] }
reqwest = { version = "0.11.14", features = ["json"] }
serde_yaml = "0.9.17"

[features]
default = ["install"]
default = ["install", "k8s-base"]
# This feature enables `bootc install`. Disable if you always want to use an external installer.
install = []
# This feature enables `bootc config`. Disable if you don't want to support dynamic reconfiguration.
k8s-base = ["k8s-openapi"]
# Implementation detail of man page generation.
docgen = ["clap_mangen"]
# This feature should only be enabled in CI environments.
Expand Down
47 changes: 25 additions & 22 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ostree_ext::container as ostree_container;
use ostree_ext::container::SignatureSource;
use ostree_ext::keyfileext::KeyFileExt;
use ostree_ext::ostree;
use ostree_ext::ostree::Deployment;
use ostree_ext::sysroot::SysrootLock;
use std::ffi::OsString;
use std::os::unix::process::CommandExt;
Expand Down Expand Up @@ -109,6 +110,9 @@ pub(crate) enum Opt {
/// Add a transient writable overlayfs on `/usr` that will be discarded on reboot.
#[clap(alias = "usroverlay")]
UsrOverlay,
/// Manipulate configuration
#[clap(subcommand)]
Config(crate::config::ConfigOpts),
/// Install to the target block device
#[cfg(feature = "install")]
Install(crate::install::InstallOpts),
Expand Down Expand Up @@ -208,24 +212,16 @@ async fn pull(

/// Stage (queue deployment of) a fetched container image.
#[context("Staging")]
async fn stage(
pub(crate) async fn stage(
sysroot: &SysrootLock,
stateroot: &str,
imgref: &ostree_container::OstreeImageReference,
image: Box<LayeredImageState>,
origin: &glib::KeyFile,
) -> Result<()> {
let cancellable = gio::Cancellable::NONE;
let stateroot = Some(stateroot);
let merge_deployment = sysroot.merge_deployment(stateroot);
let _new_deployment = sysroot.stage_tree_with_options(
stateroot,
image.merge_commit.as_str(),
Some(origin),
merge_deployment.as_ref(),
&Default::default(),
cancellable,
)?;
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
crate::deploy::deploy(sysroot, merge_deployment.as_ref(), stateroot, image, origin).await?;
crate::deploy::cleanup(sysroot).await?;
println!("Queued for next boot: {imgref}");
Ok(())
}
Expand All @@ -244,7 +240,7 @@ pub(crate) fn require_root() -> Result<()> {

/// A few process changes that need to be made for writing.
#[context("Preparing for write")]
async fn prepare_for_write() -> Result<()> {
pub(crate) async fn prepare_for_write() -> Result<()> {
if ostree_ext::container_utils::is_ostree_container()? {
anyhow::bail!(
"Detected container (ostree base); this command requires a booted host system."
Expand All @@ -257,16 +253,21 @@ async fn prepare_for_write() -> Result<()> {
Ok(())
}

pub(crate) fn target_deployment(sysroot: &SysrootLock) -> Result<Deployment> {
let booted_deployment = sysroot.require_booted_deployment()?;
Ok(sysroot.staged_deployment().unwrap_or(booted_deployment))
}

/// Implementation of the `bootc upgrade` CLI command.
#[context("Upgrading")]
async fn upgrade(opts: UpgradeOpts) -> Result<()> {
prepare_for_write().await?;
let sysroot = &get_locked_sysroot().await?;
let repo = &sysroot.repo();
let booted_deployment = &sysroot.require_booted_deployment()?;
let status = crate::status::DeploymentStatus::from_deployment(booted_deployment, true)?;
let osname = booted_deployment.osname();
let origin = booted_deployment
let merge_deployment = &target_deployment(sysroot)?;
let status = crate::status::DeploymentStatus::from_deployment(merge_deployment, true)?;
let osname = merge_deployment.osname();
let origin = merge_deployment
.origin()
.ok_or_else(|| anyhow::anyhow!("Deployment is missing an origin"))?;
let imgref = status
Expand All @@ -278,7 +279,7 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
"Booted deployment contains local rpm-ostree modifications; cannot upgrade via bootc"
));
}
let commit = booted_deployment.csum();
let commit = merge_deployment.csum();
let state = ostree_container::store::query_image_commit(repo, &commit)?;
let digest = state.manifest_digest.as_str();
let fetched = pull(repo, &imgref, opts.quiet).await?;
Expand All @@ -303,11 +304,11 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
prepare_for_write().await?;

let cancellable = gio::Cancellable::NONE;
let sysroot = get_locked_sysroot().await?;
let booted_deployment = &sysroot.require_booted_deployment()?;
let (origin, booted_image) = crate::utils::get_image_origin(booted_deployment)?;
let sysroot = &get_locked_sysroot().await?;
let merge_deployment = &target_deployment(sysroot)?;
let (origin, booted_image) = crate::utils::get_image_origin(merge_deployment)?;
let booted_refspec = origin.optional_string("origin", "refspec")?;
let osname = booted_deployment.osname();
let osname = merge_deployment.osname();
let repo = &sysroot.repo();

let transport = ostree_container::Transport::try_from(opts.transport.as_str())?;
Expand Down Expand Up @@ -373,6 +374,8 @@ where
Opt::Upgrade(opts) => upgrade(opts).await,
Opt::Switch(opts) => switch(opts).await,
Opt::UsrOverlay => usroverlay().await,
#[cfg(feature = "k8s-base")]
Opt::Config(opts) => crate::config::run(opts).await,
#[cfg(feature = "install")]
Opt::Install(opts) => crate::install::install(opts).await,
#[cfg(feature = "install")]
Expand Down
Loading

0 comments on commit 6b0a900

Please sign in to comment.