mirror of
https://github.com/containers/bootc.git
synced 2026-02-05 15:45:53 +01:00
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 <robertsturla@outlook.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user