Skip to content

Commit 1424a7a

Browse files
committed
Add support for configmaps
This is part of #22
1 parent e851fbb commit 1424a7a

File tree

8 files changed

+941
-3
lines changed

8 files changed

+941
-3
lines changed

lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ tempfile = "3.3.0"
4040
toml = "0.7.2"
4141
xshell = { version = "0.2", optional = true }
4242
uuid = { version = "1.2.2", features = ["v4"] }
43+
reqwest = { version = "0.11.14", features = ["json"] }
4344

4445
[features]
4546
default = ["install"]

lib/src/cli.rs

Lines changed: 49 additions & 2 deletions
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;
@@ -116,6 +117,9 @@ pub(crate) enum Opt {
116117
/// Add a transient writable overlayfs on `/usr` that will be discarded on reboot.
117118
#[clap(alias = "usroverlay")]
118119
UsrOverlay,
120+
/// Manipulate configuration
121+
#[clap(subcommand)]
122+
Config(crate::config::ConfigOpts),
119123
/// Install to the target block device
120124
#[cfg(feature = "install")]
121125
Install(crate::install::InstallOpts),
@@ -216,12 +220,13 @@ async fn pull(
216220

217221
/// Stage (queue deployment of) a fetched container image.
218222
#[context("Staging")]
219-
async fn stage(
223+
pub(crate) async fn stage(
220224
sysroot: &SysrootLock,
221225
stateroot: &str,
222226
image: Box<LayeredImageState>,
223227
spec: &HostSpec,
224228
) -> Result<()> {
229+
<<<<<<< HEAD
225230
let cancellable = gio::Cancellable::NONE;
226231
let stateroot = Some(stateroot);
227232
let merge_deployment = sysroot.merge_deployment(stateroot);
@@ -248,6 +253,12 @@ async fn stage(
248253
if let Some(imgref) = ostree_imgref.as_ref() {
249254
println!("Queued for next boot: {imgref}");
250255
}
256+
=======
257+
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
258+
crate::deploy::deploy(sysroot, merge_deployment.as_ref(), stateroot, image, origin).await?;
259+
crate::deploy::cleanup(sysroot).await?;
260+
println!("Queued for next boot: {imgref}");
261+
>>>>>>> 6b0a900 (Add support for configmaps)
251262
Ok(())
252263
}
253264

@@ -265,7 +276,7 @@ pub(crate) fn require_root() -> Result<()> {
265276

266277
/// A few process changes that need to be made for writing.
267278
#[context("Preparing for write")]
268-
async fn prepare_for_write() -> Result<()> {
279+
pub(crate) async fn prepare_for_write() -> Result<()> {
269280
if ostree_ext::container_utils::is_ostree_container()? {
270281
anyhow::bail!(
271282
"Detected container (ostree base); this command requires a booted host system."
@@ -278,22 +289,43 @@ async fn prepare_for_write() -> Result<()> {
278289
Ok(())
279290
}
280291

292+
pub(crate) fn target_deployment(sysroot: &SysrootLock) -> Result<Deployment> {
293+
let booted_deployment = sysroot.require_booted_deployment()?;
294+
Ok(sysroot.staged_deployment().unwrap_or(booted_deployment))
295+
}
296+
281297
/// Implementation of the `bootc upgrade` CLI command.
282298
#[context("Upgrading")]
283299
async fn upgrade(opts: UpgradeOpts) -> Result<()> {
284300
prepare_for_write().await?;
285301
let sysroot = &get_locked_sysroot().await?;
302+
<<<<<<< HEAD
286303
let booted_deployment = &sysroot.require_booted_deployment()?;
287304
let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?;
288305
// SAFETY: There must be a status if we have a booted deployment
289306
let status = host.status.unwrap();
290307
let imgref = host.spec.image.as_ref();
291308
// If there's no specified image, let's be nice and check if the booted system is using rpm-ostree
292309
if imgref.is_none() && status.booted.map_or(false, |b| b.incompatible) {
310+
=======
311+
let repo = &sysroot.repo();
312+
let merge_deployment = &target_deployment(sysroot)?;
313+
let status = crate::status::DeploymentStatus::from_deployment(merge_deployment, true)?;
314+
let osname = merge_deployment.osname();
315+
let origin = merge_deployment
316+
.origin()
317+
.ok_or_else(|| anyhow::anyhow!("Deployment is missing an origin"))?;
318+
let imgref = status
319+
.image
320+
.ok_or_else(|| anyhow::anyhow!("Booted deployment is not container image based"))?;
321+
let imgref: OstreeImageReference = imgref.into();
322+
if !status.supported {
323+
>>>>>>> 6b0a900 (Add support for configmaps)
293324
return Err(anyhow::anyhow!(
294325
"Booted deployment contains local rpm-ostree modifications; cannot upgrade via bootc"
295326
));
296327
}
328+
<<<<<<< HEAD
297329
let imgref = imgref.ok_or_else(|| anyhow::anyhow!("No image source specified"))?;
298330
// Find the currently queued digest, if any before we pull
299331
let queued_digest = status
@@ -332,6 +364,12 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
332364
return Ok(());
333365
}
334366
}
367+
=======
368+
let commit = merge_deployment.csum();
369+
let state = ostree_container::store::query_image_commit(repo, &commit)?;
370+
let digest = state.manifest_digest.as_str();
371+
let fetched = pull(repo, &imgref, opts.quiet).await?;
372+
>>>>>>> 6b0a900 (Add support for configmaps)
335373

336374
let osname = booted_deployment.osname();
337375
stage(sysroot, &osname, fetched, &host.spec).await?;
@@ -348,8 +386,16 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
348386
async fn switch(opts: SwitchOpts) -> Result<()> {
349387
prepare_for_write().await?;
350388
let cancellable = gio::Cancellable::NONE;
389+
<<<<<<< HEAD
351390

352391
let sysroot = &get_locked_sysroot().await?;
392+
=======
393+
let sysroot = &get_locked_sysroot().await?;
394+
let merge_deployment = &target_deployment(sysroot)?;
395+
let (origin, booted_image) = crate::utils::get_image_origin(merge_deployment)?;
396+
let booted_refspec = origin.optional_string("origin", "refspec")?;
397+
let osname = merge_deployment.osname();
398+
>>>>>>> 6b0a900 (Add support for configmaps)
353399
let repo = &sysroot.repo();
354400
let booted_deployment = &sysroot.require_booted_deployment()?;
355401
let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?;
@@ -427,6 +473,7 @@ where
427473
Opt::Upgrade(opts) => upgrade(opts).await,
428474
Opt::Switch(opts) => switch(opts).await,
429475
Opt::UsrOverlay => usroverlay().await,
476+
Opt::Config(opts) => crate::config::run(opts).await,
430477
#[cfg(feature = "install")]
431478
Opt::Install(opts) => crate::install::install(opts).await,
432479
#[cfg(feature = "install")]

0 commit comments

Comments
 (0)