Skip to content

Commit 84f3edf

Browse files
committed
Add support for configmaps
This is part of #22
1 parent 730c07e commit 84f3edf

File tree

9 files changed

+814
-25
lines changed

9 files changed

+814
-25
lines changed

lib/Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ hex = "^0.4"
1919
fn-error-context = "0.2.0"
2020
gvariant = "0.4.0"
2121
indicatif = "0.17.0"
22+
k8s-openapi = { version = "0.17.0", features = ["v1_25"], optional = true }
2223
libc = "^0.2"
2324
liboverdrop = "0.1.0"
2425
once_cell = "1.9"
@@ -36,11 +37,15 @@ tempfile = "3.3.0"
3637
toml = "0.7.2"
3738
xshell = { version = "0.2", optional = true }
3839
uuid = { version = "1.2.2", features = ["v4"] }
40+
reqwest = { version = "0.11.14", features = ["json"] }
41+
serde_yaml = "0.9.17"
3942

4043
[features]
41-
default = ["install"]
44+
default = ["install", "k8s-base"]
4245
# This feature enables `bootc install`. Disable if you always want to use an external installer.
4346
install = []
47+
# This feature enables `bootc config`. Disable if you don't want to support dynamic reconfiguration.
48+
k8s-base = ["k8s-openapi"]
4449
# Implementation detail of man page generation.
4550
docgen = ["clap_mangen"]
4651
# This feature should only be enabled in CI environments.

lib/src/cli.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use ostree_ext::container as ostree_container;
1414
use ostree_ext::container::SignatureSource;
1515
use ostree_ext::keyfileext::KeyFileExt;
1616
use ostree_ext::ostree;
17+
use ostree_ext::ostree::Deployment;
1718
use ostree_ext::sysroot::SysrootLock;
1819
use std::ffi::OsString;
1920
use std::os::unix::process::CommandExt;
@@ -109,6 +110,9 @@ pub(crate) enum Opt {
109110
/// Add a transient writable overlayfs on `/usr` that will be discarded on reboot.
110111
#[clap(alias = "usroverlay")]
111112
UsrOverlay,
113+
/// Manipulate configuration
114+
#[clap(subcommand)]
115+
Config(crate::config::ConfigOpts),
112116
/// Install to the target block device
113117
#[cfg(feature = "install")]
114118
Install(crate::install::InstallOpts),
@@ -208,24 +212,16 @@ async fn pull(
208212

209213
/// Stage (queue deployment of) a fetched container image.
210214
#[context("Staging")]
211-
async fn stage(
215+
pub(crate) async fn stage(
212216
sysroot: &SysrootLock,
213217
stateroot: &str,
214218
imgref: &ostree_container::OstreeImageReference,
215219
image: Box<LayeredImageState>,
216220
origin: &glib::KeyFile,
217221
) -> Result<()> {
218-
let cancellable = gio::Cancellable::NONE;
219-
let stateroot = Some(stateroot);
220-
let merge_deployment = sysroot.merge_deployment(stateroot);
221-
let _new_deployment = sysroot.stage_tree_with_options(
222-
stateroot,
223-
image.merge_commit.as_str(),
224-
Some(origin),
225-
merge_deployment.as_ref(),
226-
&Default::default(),
227-
cancellable,
228-
)?;
222+
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
223+
crate::deploy::deploy(sysroot, merge_deployment.as_ref(), stateroot, image, origin).await?;
224+
crate::deploy::cleanup(sysroot).await?;
229225
println!("Queued for next boot: {imgref}");
230226
Ok(())
231227
}
@@ -244,7 +240,7 @@ pub(crate) fn require_root() -> Result<()> {
244240

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

256+
pub(crate) fn target_deployment(sysroot: &SysrootLock) -> Result<Deployment> {
257+
let booted_deployment = sysroot.require_booted_deployment()?;
258+
Ok(sysroot.staged_deployment().unwrap_or(booted_deployment))
259+
}
260+
260261
/// Implementation of the `bootc upgrade` CLI command.
261262
#[context("Upgrading")]
262263
async fn upgrade(opts: UpgradeOpts) -> Result<()> {
263264
prepare_for_write().await?;
264265
let sysroot = &get_locked_sysroot().await?;
265266
let repo = &sysroot.repo();
266-
let booted_deployment = &sysroot.require_booted_deployment()?;
267-
let status = crate::status::DeploymentStatus::from_deployment(booted_deployment, true)?;
268-
let osname = booted_deployment.osname();
269-
let origin = booted_deployment
267+
let merge_deployment = &target_deployment(sysroot)?;
268+
let status = crate::status::DeploymentStatus::from_deployment(merge_deployment, true)?;
269+
let osname = merge_deployment.osname();
270+
let origin = merge_deployment
270271
.origin()
271272
.ok_or_else(|| anyhow::anyhow!("Deployment is missing an origin"))?;
272273
let imgref = status
@@ -278,7 +279,7 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
278279
"Booted deployment contains local rpm-ostree modifications; cannot upgrade via bootc"
279280
));
280281
}
281-
let commit = booted_deployment.csum();
282+
let commit = merge_deployment.csum();
282283
let state = ostree_container::store::query_image_commit(repo, &commit)?;
283284
let digest = state.manifest_digest.as_str();
284285
let fetched = pull(repo, &imgref, opts.quiet).await?;
@@ -303,11 +304,11 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
303304
prepare_for_write().await?;
304305

305306
let cancellable = gio::Cancellable::NONE;
306-
let sysroot = get_locked_sysroot().await?;
307-
let booted_deployment = &sysroot.require_booted_deployment()?;
308-
let (origin, booted_image) = crate::utils::get_image_origin(booted_deployment)?;
307+
let sysroot = &get_locked_sysroot().await?;
308+
let merge_deployment = &target_deployment(sysroot)?;
309+
let (origin, booted_image) = crate::utils::get_image_origin(merge_deployment)?;
309310
let booted_refspec = origin.optional_string("origin", "refspec")?;
310-
let osname = booted_deployment.osname();
311+
let osname = merge_deployment.osname();
311312
let repo = &sysroot.repo();
312313

313314
let transport = ostree_container::Transport::try_from(opts.transport.as_str())?;
@@ -373,6 +374,8 @@ where
373374
Opt::Upgrade(opts) => upgrade(opts).await,
374375
Opt::Switch(opts) => switch(opts).await,
375376
Opt::UsrOverlay => usroverlay().await,
377+
#[cfg(feature = "k8s-base")]
378+
Opt::Config(opts) => crate::config::run(opts).await,
376379
#[cfg(feature = "install")]
377380
Opt::Install(opts) => crate::install::install(opts).await,
378381
#[cfg(feature = "install")]

0 commit comments

Comments
 (0)