Skip to content

Commit 21c7b3c

Browse files
committed
status: Change transport display
Registry is the assumed default; let's be quieter (less output) in this default/expected case. If we're using something else (e.g. `oci`) then put it inline with the image name as that's something one can pass to e.g. `skopeo`. Signed-off-by: Colin Walters <[email protected]>
1 parent 85b2ca5 commit 21c7b3c

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: org.containers.bootc/v1alpha1
2+
kind: BootcHost
3+
metadata:
4+
name: host
5+
spec:
6+
image:
7+
image: /var/mnt/osupdate:latest
8+
transport: oci
9+
bootOrder: default
10+
status:
11+
staged: null
12+
booted:
13+
image:
14+
image:
15+
image: /var/mnt/osupdate
16+
transport: oci
17+
version: stream9.20240807.0
18+
timestamp: null
19+
imageDigest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b38
20+
cachedUpdate: null
21+
incompatible: false
22+
pinned: false
23+
ostree:
24+
checksum: 439f6bd2e2361bee292c1f31840d798c5ac5ba76483b8021dc9f7b0164ac0f48
25+
deploySerial: 0
26+
rollback: null
27+
rollbackQueued: false
28+
type: bootcHost

lib/src/status.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::collections::VecDeque;
23
use std::io::IsTerminal;
34
use std::io::Write;
@@ -332,11 +333,16 @@ fn human_readable_output(mut out: impl Write, host: &Host) -> Result<()> {
332333
] {
333334
if let Some(host_status) = status {
334335
if let Some(image) = &host_status.image {
335-
writeln!(
336-
out,
337-
"Current {} image: {}",
338-
status_string, image.image.image
339-
)?;
336+
let transport = &image.image.transport;
337+
let imagename = &image.image.image;
338+
// Registry is the default, so don't show that
339+
let imageref = if transport == "registry" {
340+
Cow::Borrowed(imagename)
341+
} else {
342+
// But for non-registry we include the transport
343+
Cow::Owned(format!("{transport}:{imagename}"))
344+
};
345+
writeln!(out, "Current {status_string} image: {imageref}")?;
340346

341347
let version = image
342348
.version
@@ -347,11 +353,9 @@ fn human_readable_output(mut out: impl Write, host: &Host) -> Result<()> {
347353
.as_ref()
348354
.map(|t| t.to_string())
349355
.unwrap_or_else(|| "No timestamp present".to_owned());
350-
let transport = &image.image.transport;
351356
let digest = &image.image_digest;
352357

353358
writeln!(out, " Image version: {version} ({timestamp})")?;
354-
writeln!(out, " Image transport: {transport}")?;
355359
writeln!(out, " Image digest: {digest}")?;
356360
} else {
357361
writeln!(out, "Current {status_string} state is native ostree")?;
@@ -383,11 +387,9 @@ mod tests {
383387
let expected = indoc::indoc! { r"
384388
Current staged image: quay.io/example/someimage:latest
385389
Image version: nightly (2023-10-14 19:22:15 UTC)
386-
Image transport: registry
387390
Image digest: sha256:16dc2b6256b4ff0d2ec18d2dbfb06d117904010c8cf9732cdb022818cf7a7566
388391
Current booted image: quay.io/example/someimage:latest
389392
Image version: nightly (2023-09-30 19:22:16 UTC)
390-
Image transport: registry
391393
Image digest: sha256:736b359467c9437c1ac915acaae952aad854e07eb4a16a94999a48af08c83c34
392394
No rollback image present
393395
"};
@@ -417,7 +419,6 @@ mod tests {
417419
let expected = indoc::indoc! { r"
418420
Current staged image: quay.io/centos-bootc/centos-bootc:stream9
419421
Image version: stream9.20240807.0 (No timestamp present)
420-
Image transport: registry
421422
Image digest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b38
422423
Current booted state is native ostree
423424
No rollback image present
@@ -434,7 +435,6 @@ mod tests {
434435
No staged image present
435436
Current booted image: quay.io/centos-bootc/centos-bootc:stream9
436437
Image version: stream9.20240807.0 (No timestamp present)
437-
Image transport: registry
438438
Image digest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b38
439439
No rollback image present
440440
"};
@@ -449,17 +449,29 @@ mod tests {
449449
let expected = indoc::indoc! { r"
450450
Current staged image: quay.io/example/someimage:latest
451451
Image version: nightly (2023-10-14 19:22:15 UTC)
452-
Image transport: registry
453452
Image digest: sha256:16dc2b6256b4ff0d2ec18d2dbfb06d117904010c8cf9732cdb022818cf7a7566
454453
No booted image present
455454
Current rollback image: quay.io/example/someimage:latest
456455
Image version: nightly (2023-09-30 19:22:16 UTC)
457-
Image transport: registry
458456
Image digest: sha256:736b359467c9437c1ac915acaae952aad854e07eb4a16a94999a48af08c83c34
459457
"};
460458
similar_asserts::assert_eq!(w, expected);
461459
}
462460

461+
#[test]
462+
fn test_via_oci() {
463+
let w = human_status_from_spec_fixture(include_str!("fixtures/spec-via-local-oci.yaml"))
464+
.unwrap();
465+
let expected = indoc::indoc! { r"
466+
No staged image present
467+
Current booted image: oci:/var/mnt/osupdate
468+
Image version: stream9.20240807.0 (No timestamp present)
469+
Image digest: sha256:47e5ed613a970b6574bfa954ab25bb6e85656552899aa518b5961d9645102b38
470+
No rollback image present
471+
"};
472+
similar_asserts::assert_eq!(w, expected);
473+
}
474+
463475
#[test]
464476
fn test_convert_signatures() {
465477
use std::str::FromStr;

0 commit comments

Comments
 (0)