Skip to content

Commit 82f0a72

Browse files
committed
feat(status): display pinned deployments
Part of #904 Displays pinned deployments as part of "bootc status". Includes unit tests to ensure correct parsing of the pinned deployments, and that they are displayed in human readable formats correctly.
1 parent df879ed commit 82f0a72

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apiVersion: org.containers.bootc/v1alpha1
2+
kind: BootcHost
3+
metadata:
4+
name: host
5+
spec:
6+
image:
7+
image: quay.io/centos-bootc/centos-bootc:stream9
8+
transport: registry
9+
bootOrder: default
10+
status:
11+
staged: null
12+
booted:
13+
image:
14+
image:
15+
image: quay.io/centos-bootc/centos-bootc:stream9
16+
transport: registry
17+
architecture: arm64
18+
version: stream9.20240807.0
19+
timestamp: null
20+
imageDigest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b38
21+
cachedUpdate: null
22+
incompatible: false
23+
pinned: false
24+
ostree:
25+
checksum: 439f6bd2e2361bee292c1f31840d798c5ac5ba76483b8021dc9f7b0164ac0f48
26+
deploySerial: 0
27+
pinned:
28+
- image:
29+
image:
30+
image: quay.io/centos-bootc/centos-bootc:stream9
31+
transport: registry
32+
version: stream9.20240807.0
33+
timestamp: null
34+
imageDigest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b37
35+
architecture: arm64
36+
cachedUpdate: null
37+
incompatible: false
38+
pinned: true
39+
ostree:
40+
checksum: 99b2cc3b6edce9ebaef6a6076effa5ee3e1dcff3523016ffc94a1b27c6c67e12
41+
deploySerial: 0
42+
43+
rollback: null
44+
rollbackQueued: false
45+
type: bootcHost

lib/src/spec.rs

+7
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ pub struct HostStatus {
157157
/// Set to true if the rollback entry is queued for the next boot.
158158
#[serde(default)]
159159
pub rollback_queued: bool,
160+
/// All pinned images
161+
pub pinned: Option<Vec<BootEntry>>,
160162

161163
/// The detected type of system
162164
#[serde(rename = "type")]
@@ -196,6 +198,11 @@ impl Host {
196198
self.status.staged = None;
197199
self.status.booted = None;
198200
}
201+
Slot::Pinned => {
202+
self.status.staged = None;
203+
self.status.booted = None;
204+
self.status.rollback = None;
205+
}
199206
}
200207
}
201208
}

lib/src/status.rs

+46-3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@ pub(crate) fn get_status(
253253
.map(|d| boot_entry_from_deployment(sysroot, d))
254254
.transpose()
255255
.context("Rollback deployment")?;
256+
let pinned = deployments
257+
.other
258+
.iter()
259+
.filter_map(|d| {
260+
d.is_pinned()
261+
.then(|| boot_entry_from_deployment(sysroot, d).ok())
262+
})
263+
.collect::<Option<Vec<_>>>()
264+
.filter(|v| !v.is_empty());
256265
let spec = staged
257266
.as_ref()
258267
.or(booted.as_ref())
@@ -280,6 +289,7 @@ pub(crate) fn get_status(
280289
booted,
281290
rollback,
282291
rollback_queued,
292+
pinned,
283293
ty,
284294
};
285295
Ok((deployments, host))
@@ -336,6 +346,7 @@ pub enum Slot {
336346
Staged,
337347
Booted,
338348
Rollback,
349+
Pinned,
339350
}
340351

341352
impl std::fmt::Display for Slot {
@@ -344,6 +355,7 @@ impl std::fmt::Display for Slot {
344355
Slot::Staged => "staged",
345356
Slot::Booted => "booted",
346357
Slot::Rollback => "rollback",
358+
Slot::Pinned => "pinned",
347359
};
348360
f.write_str(s)
349361
}
@@ -377,6 +389,7 @@ fn human_render_imagestatus(
377389
Slot::Staged => " Staged image".into(),
378390
Slot::Booted => format!("{} Booted image", crate::glyph::Glyph::BlackCircle),
379391
Slot::Rollback => " Rollback image".into(),
392+
Slot::Pinned => " Pinned image".into(),
380393
};
381394
let prefix_len = prefix.chars().count();
382395
writeln!(out, "{prefix}: {imageref}")?;
@@ -416,6 +429,7 @@ fn human_render_ostree(mut out: impl Write, slot: Slot, ostree_commit: &str) ->
416429
Slot::Staged => " Staged ostree".into(),
417430
Slot::Booted => format!("{} Booted ostree", crate::glyph::Glyph::BlackCircle),
418431
Slot::Rollback => " Rollback ostree".into(),
432+
Slot::Pinned => " Pinned ostree".into(),
419433
};
420434
let prefix_len = prefix.len();
421435
writeln!(out, "{prefix}")?;
@@ -446,6 +460,18 @@ fn human_readable_output_booted(mut out: impl Write, host: &Host) -> Result<()>
446460
}
447461
}
448462
}
463+
464+
if let Some(pinned) = &host.status.pinned {
465+
writeln!(out)?;
466+
for entry in pinned {
467+
if let Some(image) = &entry.image {
468+
human_render_imagestatus(&mut out, Slot::Pinned, image)?;
469+
} else if let Some(ostree) = entry.ostree.as_ref() {
470+
human_render_ostree(&mut out, Slot::Pinned, &ostree.checksum)?;
471+
}
472+
}
473+
}
474+
449475
Ok(())
450476
}
451477

@@ -480,7 +506,7 @@ mod tests {
480506
Staged image: quay.io/example/someimage:latest
481507
Digest: sha256:16dc2b6256b4ff0d2ec18d2dbfb06d117904010c8cf9732cdb022818cf7a7566 (arm64)
482508
Version: nightly (2023-10-14T19:22:15Z)
483-
509+
484510
● Booted image: quay.io/example/someimage:latest
485511
Digest: sha256:736b359467c9437c1ac915acaae952aad854e07eb4a16a94999a48af08c83c34 (arm64)
486512
Version: nightly (2023-09-30T19:22:16Z)
@@ -498,7 +524,7 @@ mod tests {
498524
let expected = indoc::indoc! { r"
499525
Staged ostree
500526
Commit: 1c24260fdd1be20f72a4a97a75c582834ee3431fbb0fa8e4f482bb219d633a45
501-
527+
502528
● Booted ostree
503529
Commit: f9fa3a553ceaaaf30cf85bfe7eed46a822f7b8fd7e14c1e3389cbc3f6d27f791
504530
"};
@@ -514,7 +540,7 @@ mod tests {
514540
Staged image: quay.io/centos-bootc/centos-bootc:stream9
515541
Digest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b38 (s390x)
516542
Version: stream9.20240807.0
517-
543+
518544
● Booted ostree
519545
Commit: f9fa3a553ceaaaf30cf85bfe7eed46a822f7b8fd7e14c1e3389cbc3f6d27f791
520546
"};
@@ -534,6 +560,23 @@ mod tests {
534560
similar_asserts::assert_eq!(w, expected);
535561
}
536562

563+
#[test]
564+
fn test_human_readable_booted_pinned_spec() {
565+
// booted image, no staged/rollback
566+
let w = human_status_from_spec_fixture(include_str!("fixtures/spec-booted-pinned.yaml"))
567+
.expect("No spec found");
568+
let expected = indoc::indoc! { r"
569+
● Booted image: quay.io/centos-bootc/centos-bootc:stream9
570+
Digest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b38 (arm64)
571+
Version: stream9.20240807.0
572+
573+
Pinned image: quay.io/centos-bootc/centos-bootc:stream9
574+
Digest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b37 (arm64)
575+
Version: stream9.20240807.0
576+
"};
577+
similar_asserts::assert_eq!(w, expected);
578+
}
579+
537580
#[test]
538581
fn test_human_readable_staged_rollback_spec() {
539582
// staged/rollback image, no booted

0 commit comments

Comments
 (0)