Skip to content

Commit 1418f0b

Browse files
committed
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 <[email protected]>
1 parent 1958fe8 commit 1418f0b

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/src/spec.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ostree_ext::oci_spec::image::Digest;
77
use schemars::JsonSchema;
88
use serde::{Deserialize, Serialize};
99

10-
use crate::k8sapitypes;
10+
use crate::{k8sapitypes, status::Slot};
1111

1212
const API_VERSION: &str = "org.containers.bootc/v1";
1313
const KIND: &str = "BootcHost";
@@ -178,6 +178,24 @@ impl Host {
178178
status: Default::default(),
179179
}
180180
}
181+
182+
/// Filter out the requested slot
183+
pub fn filter_to_slot(&mut self, slot: Slot) {
184+
match slot {
185+
Slot::Staged => {
186+
self.status.booted = None;
187+
self.status.rollback = None;
188+
}
189+
Slot::Booted => {
190+
self.status.staged = None;
191+
self.status.rollback = None;
192+
}
193+
Slot::Rollback => {
194+
self.status.staged = None;
195+
self.status.booted = None;
196+
}
197+
}
198+
}
181199
}
182200

183201
impl Default for Host {

lib/src/status.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
293293
0 | 1 => {}
294294
o => anyhow::bail!("Unsupported format version: {o}"),
295295
};
296-
let host = if !ostree_booted()? {
296+
let mut host = if !ostree_booted()? {
297297
Default::default()
298298
} else {
299299
let sysroot = super::cli::get_storage().await?;
@@ -302,6 +302,12 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
302302
host
303303
};
304304

305+
// We could support querying the staged or rollback deployments
306+
// here too, but it's not a common use case at the moment.
307+
if opts.booted {
308+
host.filter_to_slot(Slot::Booted);
309+
}
310+
305311
// If we're in JSON mode, then convert the ostree data into Rust-native
306312
// structures that can be serialized.
307313
// Filter to just the serializable status structures.
@@ -326,7 +332,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
326332
}
327333

328334
#[derive(Debug)]
329-
enum Slot {
335+
pub enum Slot {
330336
Staged,
331337
Booted,
332338
Rollback,

0 commit comments

Comments
 (0)