Skip to content

Commit

Permalink
switch: Be idempotent
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cgwalters committed Jan 19, 2024
1 parent ac52673 commit d2eebb9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
9 changes: 8 additions & 1 deletion tests/kolainst/basic
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d2eebb9

Please sign in to comment.