From d2eebb99561652f66535f41154fe49f1ab5132ff Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 19 Jan 2024 09:38:07 -0500 Subject: [PATCH] switch: Be idempotent Instead of erroring out if the spec is unchanged, just print a notice. This better matches Kubernetes default style. Signed-off-by: Colin Walters --- docs/usage.md | 4 ++-- lib/src/cli.rs | 3 ++- tests/kolainst/basic | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 123f3625..0ec7e736 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -22,8 +22,8 @@ on the target, use bootc switch --transport oci /var/mnt/usb/myos.oci ``` -The above command can only be invoked once currently; thereafter, use `bootc upgrade` -as normal to fetch updates from the USB device. +The above command is only necessary once, and thereafter will be idempotent. +Then, use `bootc upgrade --apply` to fetch and apply the update from the USB device. This process can all be automated by creating systemd units that look for a USB device with a specific label, mount (optionally with LUKS diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 258513ca..520c6d51 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -442,7 +442,8 @@ async fn switch(opts: SwitchOpts) -> Result<()> { }; if new_spec == host.spec { - anyhow::bail!("No changes in current host spec"); + println!("Image specification is unchanged."); + return Ok(()); } let new_spec = RequiredHostSpec::from_spec(&new_spec)?; diff --git a/tests/kolainst/basic b/tests/kolainst/basic index 612a3a1c..bef28c21 100755 --- a/tests/kolainst/basic +++ b/tests/kolainst/basic @@ -15,10 +15,17 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in bootc status > status.txt grep 'Version:' status.txt bootc status --json > status.json - image=$(jq -r '.status.booted.image.image' < status.json) + image=$(jq '.status.booted.image.image' < status.json) echo "booted into $image" echo "ok status test" + # Switch should be idempotent + # (also TODO, get rid of the crazy .image.image.image nesting) + name=$(echo "${image}" | jq -r '.image') + bootc switch $name + staged=$(bootc status --json | jq .status.staged) + test "$staged" = "null" + host_ty=$(jq -r '.status.type' < status.json) test "${host_ty}" = "bootcHost" # Now fake things out with an empty /run