Skip to content

Commit

Permalink
wip-rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Mar 9, 2024
1 parent db93ac8 commit 74261c2
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
//!
//! Command line tool to manage bootable ostree-based containers.

use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};
use camino::Utf8PathBuf;
use cap_std_ext::cap_std;
use clap::Parser;
use fn_error_context::context;
use ostree::gio;
use ostree_container::store::PrepareResult;
use ostree_ext::container as ostree_container;
use ostree_ext::container::store::query_image;
use ostree_ext::keyfileext::KeyFileExt;
use ostree_ext::ostree;
use std::ffi::OsString;
Expand Down Expand Up @@ -86,6 +87,16 @@ pub(crate) struct SwitchOpts {
pub(crate) target: String,
}

/// Options controlling rollback
#[derive(Debug, Parser)]
pub(crate) struct RollbackOpts {
/// Do not change the pull specification to pin to digest; be aware
/// that an upgrade agent (unless it is itself aware of the system state)
/// may reapply the change.
#[clap(long, short = 'p')]
pub(crate) no_pin: bool,
}

/// Perform an edit operation
#[derive(Debug, Parser)]
pub(crate) struct EditOpts {
Expand Down Expand Up @@ -186,6 +197,15 @@ pub(crate) enum Opt {
/// This operates in a very similar fashion to `upgrade`, but changes the container image reference
/// instead.
Switch(SwitchOpts),
/// Swap the order of bootloader entries; the entry under `rollback` will be queued for the next boot,
/// and the current will become rollback. If there is a `staged` entry (an unapplied, queued upgrade)
/// then it will be discarded.
///
/// Additionally by default, the pull specification for upgrades will change to the digested pull
/// spec of the previously pulled image. This will suppress any active agent
/// (such as the default `bootc-fetch-apply-updates.timer` and associated `.service`) which would
/// otherwise re-apply the target change.
Rollback(RollbackOpts),
/// Apply full changes to the host specification.
///
/// This command operates very similarly to `kubectl apply`; if invoked interactively,
Expand Down Expand Up @@ -470,6 +490,25 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
Ok(())
}

/// Implementation of the `bootc rollback` CLI command.
#[context("Rollback")]
async fn rollback(opts: RollbackOpts) -> Result<()> {
prepare_for_write().await?;
let sysroot = &get_locked_sysroot().await?;
let repo = &sysroot.repo();
let (booted_deployment, _deployments, host) =
crate::status::get_status_require_booted(sysroot)?;
let imgref = host.spec.image.as_ref();
let spec = RequiredHostSpec::from_spec(&host.spec)?;
let rollback_status = host
.status
.rollback
.ok_or_else(|| anyhow!("No rollback image available"))?;
let rollback_image = query_image(repo, &rollback_status)?;

todo!()
}

/// Implementation of the `bootc edit` CLI command.
#[context("Editing spec")]
async fn edit(opts: EditOpts) -> Result<()> {
Expand Down Expand Up @@ -528,6 +567,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
match opt {
Opt::Upgrade(opts) => upgrade(opts).await,
Opt::Switch(opts) => switch(opts).await,
Opt::Rollback(opts) => rollback(opts).await,
Opt::Edit(opts) => edit(opts).await,
Opt::UsrOverlay => usroverlay().await,
#[cfg(feature = "install")]
Expand Down

0 comments on commit 74261c2

Please sign in to comment.