Skip to content

Commit d2eebb9

Browse files
committed
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 <[email protected]>
1 parent ac52673 commit d2eebb9

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

docs/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ on the target, use
2222
bootc switch --transport oci /var/mnt/usb/myos.oci
2323
```
2424

25-
The above command can only be invoked once currently; thereafter, use `bootc upgrade`
26-
as normal to fetch updates from the USB device.
25+
The above command is only necessary once, and thereafter will be idempotent.
26+
Then, use `bootc upgrade --apply` to fetch and apply the update from the USB device.
2727

2828
This process can all be automated by creating systemd
2929
units that look for a USB device with a specific label, mount (optionally with LUKS

lib/src/cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
442442
};
443443

444444
if new_spec == host.spec {
445-
anyhow::bail!("No changes in current host spec");
445+
println!("Image specification is unchanged.");
446+
return Ok(());
446447
}
447448
let new_spec = RequiredHostSpec::from_spec(&new_spec)?;
448449

tests/kolainst/basic

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in
1515
bootc status > status.txt
1616
grep 'Version:' status.txt
1717
bootc status --json > status.json
18-
image=$(jq -r '.status.booted.image.image' < status.json)
18+
image=$(jq '.status.booted.image.image' < status.json)
1919
echo "booted into $image"
2020
echo "ok status test"
2121

22+
# Switch should be idempotent
23+
# (also TODO, get rid of the crazy .image.image.image nesting)
24+
name=$(echo "${image}" | jq -r '.image')
25+
bootc switch $name
26+
staged=$(bootc status --json | jq .status.staged)
27+
test "$staged" = "null"
28+
2229
host_ty=$(jq -r '.status.type' < status.json)
2330
test "${host_ty}" = "bootcHost"
2431
# Now fake things out with an empty /run

0 commit comments

Comments
 (0)