Skip to content

Commit cb49444

Browse files
committed
Add support for configmaps
This is part of #22
1 parent a0f1035 commit cb49444

File tree

9 files changed

+628
-13
lines changed

9 files changed

+628
-13
lines changed

lib/Cargo.toml

Lines changed: 6 additions & 1 deletion
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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ostree_ext::container as ostree_container;
1515
use ostree_ext::container::SignatureSource;
1616
use ostree_ext::keyfileext::KeyFileExt;
1717
use ostree_ext::ostree;
18+
use ostree_ext::ostree::Deployment;
1819
use ostree_ext::sysroot::SysrootLock;
1920
use std::ffi::OsString;
2021
use std::os::unix::process::CommandExt;
@@ -110,6 +111,9 @@ pub(crate) enum Opt {
110111
/// Add a transient writable overlayfs on `/usr` that will be discarded on reboot.
111112
#[clap(alias = "usroverlay")]
112113
UsrOverlay,
114+
/// Manipulate configuration
115+
#[clap(subcommand)]
116+
Config(crate::config::ConfigOpts),
113117
/// Install to the target block device
114118
#[cfg(feature = "install")]
115119
Install(crate::install::InstallOpts),
@@ -209,7 +213,7 @@ async fn pull(
209213

210214
/// Stage (queue deployment of) a fetched container image.
211215
#[context("Staging")]
212-
async fn stage(
216+
pub(crate) async fn stage(
213217
sysroot: &SysrootLock,
214218
stateroot: &str,
215219
imgref: &ostree_container::OstreeImageReference,
@@ -245,7 +249,7 @@ pub(crate) fn require_root() -> Result<()> {
245249

246250
/// A few process changes that need to be made for writing.
247251
#[context("Preparing for write")]
248-
async fn prepare_for_write() -> Result<()> {
252+
pub(crate) async fn prepare_for_write() -> Result<()> {
249253
if ostree_ext::container_utils::is_ostree_container()? {
250254
anyhow::bail!(
251255
"Detected container (ostree base); this command requires a booted host system."
@@ -258,16 +262,21 @@ async fn prepare_for_write() -> Result<()> {
258262
Ok(())
259263
}
260264

265+
pub(crate) fn target_deployment(sysroot: &SysrootLock) -> Result<Deployment> {
266+
let booted_deployment = sysroot.require_booted_deployment()?;
267+
Ok(sysroot.staged_deployment().unwrap_or(booted_deployment))
268+
}
269+
261270
/// Implementation of the `bootc upgrade` CLI command.
262271
#[context("Upgrading")]
263272
async fn upgrade(opts: UpgradeOpts) -> Result<()> {
264273
prepare_for_write().await?;
265274
let sysroot = &get_locked_sysroot().await?;
266275
let repo = &sysroot.repo().unwrap();
267-
let booted_deployment = &sysroot.require_booted_deployment()?;
268-
let status = crate::status::DeploymentStatus::from_deployment(booted_deployment, true)?;
269-
let osname = booted_deployment.osname().unwrap();
270-
let origin = booted_deployment
276+
let merge_deployment = &target_deployment(sysroot)?;
277+
let status = crate::status::DeploymentStatus::from_deployment(merge_deployment, true)?;
278+
let osname = merge_deployment.osname().unwrap();
279+
let origin = merge_deployment
271280
.origin()
272281
.ok_or_else(|| anyhow::anyhow!("Deployment is missing an origin"))?;
273282
let imgref = status
@@ -279,7 +288,7 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
279288
"Booted deployment contains local rpm-ostree modifications; cannot upgrade via bootc"
280289
));
281290
}
282-
let commit = booted_deployment.csum().unwrap();
291+
let commit = merge_deployment.csum().unwrap();
283292
let state = ostree_container::store::query_image_commit(repo, &commit)?;
284293
let digest = state.manifest_digest.as_str();
285294
let fetched = pull(repo, &imgref, opts.quiet).await?;
@@ -304,11 +313,11 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
304313
prepare_for_write().await?;
305314

306315
let cancellable = gio::Cancellable::NONE;
307-
let sysroot = get_locked_sysroot().await?;
308-
let booted_deployment = &sysroot.require_booted_deployment()?;
309-
let (origin, booted_image) = crate::utils::get_image_origin(booted_deployment)?;
316+
let sysroot = &get_locked_sysroot().await?;
317+
let merge_deployment = &target_deployment(sysroot)?;
318+
let (origin, booted_image) = crate::utils::get_image_origin(merge_deployment)?;
310319
let booted_refspec = origin.optional_string("origin", "refspec")?;
311-
let osname = booted_deployment.osname().unwrap();
320+
let osname = merge_deployment.osname().unwrap();
312321
let repo = &sysroot.repo().unwrap();
313322

314323
let transport = ostree_container::Transport::try_from(opts.transport.as_str())?;
@@ -374,6 +383,8 @@ where
374383
Opt::Upgrade(opts) => upgrade(opts).await,
375384
Opt::Switch(opts) => switch(opts).await,
376385
Opt::UsrOverlay => usroverlay().await,
386+
#[cfg(feature = "k8s-base")]
387+
Opt::Config(opts) => crate::config::run(opts).await,
377388
#[cfg(feature = "install")]
378389
Opt::Install(opts) => crate::install::install(opts).await,
379390
#[cfg(feature = "install")]

0 commit comments

Comments
 (0)