From 1418f0b98d254dcb596acd991fecbb00a7fe1e02 Mon Sep 17 00:00:00 2001 From: Robert Sturla Date: Tue, 18 Mar 2025 15:32:49 +0000 Subject: [PATCH] fix(status): enable --booted option to only show the current deployment The existing code didn't take into account the --booted options, so always showed the staged, current and rollback deployments. This correctly wires through the --booted option to only show that deployment. Stubs have been left in the code should we wish to enable options to show only the rollback or staged options (--rollback / --staged). No docs changes were required since the flag is already present. Closes #465 Signed-off-by: Robert Sturla --- lib/src/spec.rs | 20 +++++++++++++++++++- lib/src/status.rs | 10 ++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/src/spec.rs b/lib/src/spec.rs index ab2ca907..c712916a 100644 --- a/lib/src/spec.rs +++ b/lib/src/spec.rs @@ -7,7 +7,7 @@ use ostree_ext::oci_spec::image::Digest; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use crate::k8sapitypes; +use crate::{k8sapitypes, status::Slot}; const API_VERSION: &str = "org.containers.bootc/v1"; const KIND: &str = "BootcHost"; @@ -178,6 +178,24 @@ impl Host { status: Default::default(), } } + + /// Filter out the requested slot + pub fn filter_to_slot(&mut self, slot: Slot) { + match slot { + Slot::Staged => { + self.status.booted = None; + self.status.rollback = None; + } + Slot::Booted => { + self.status.staged = None; + self.status.rollback = None; + } + Slot::Rollback => { + self.status.staged = None; + self.status.booted = None; + } + } + } } impl Default for Host { diff --git a/lib/src/status.rs b/lib/src/status.rs index 02a4ac80..a3e9786b 100644 --- a/lib/src/status.rs +++ b/lib/src/status.rs @@ -293,7 +293,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> { 0 | 1 => {} o => anyhow::bail!("Unsupported format version: {o}"), }; - let host = if !ostree_booted()? { + let mut host = if !ostree_booted()? { Default::default() } else { let sysroot = super::cli::get_storage().await?; @@ -302,6 +302,12 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> { host }; + // We could support querying the staged or rollback deployments + // here too, but it's not a common use case at the moment. + if opts.booted { + host.filter_to_slot(Slot::Booted); + } + // If we're in JSON mode, then convert the ostree data into Rust-native // structures that can be serialized. // Filter to just the serializable status structures. @@ -326,7 +332,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> { } #[derive(Debug)] -enum Slot { +pub enum Slot { Staged, Booted, Rollback,