Skip to content

Commit 57b86ba

Browse files
committed
Add function to write reboot-required file with context
This change adds a function that writes the /run/reboot-required file. This function is called from any deployment operation with the relevant context. Calling from rollback will ensure the rollback context along with the image digest is written to the file, while calling from upgrade or switch will write the deploy context for users to reference. This expands on the functionality requested in: #1574 Related to: #1583 Signed-off-by: Brendan Shephard <[email protected]>
1 parent 39b0a32 commit 57b86ba

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

crates/lib/src/deploy.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,16 @@ pub(crate) async fn stage(
794794

795795
// Unconditionally create or update /run/reboot-required to signal a reboot is needed.
796796
// This is monitored by kured (Kubernetes Reboot Daemon).
797-
let reboot_message = format!("bootc: Reboot required for image: {}", &spec.image.image);
797+
let bootc_action: String = String::from("deploy");
798+
write_reboot_required(&image.manifest_digest.as_ref(), bootc_action.as_str())?;
799+
800+
Ok(())
801+
}
802+
803+
/// Update the /run/reboot-required file with the action we're performing,
804+
/// and the image that will be active after the reboot.
805+
fn write_reboot_required(image: &str, action: &str) -> Result<()> {
806+
let reboot_message = format!("bootc {}: Reboot required for image: {}", action, image);
798807
let run_dir = Dir::open_ambient_dir("/run", cap_std::ambient_authority())?;
799808
run_dir
800809
.atomic_write("reboot-required", reboot_message.as_bytes())
@@ -870,6 +879,12 @@ pub(crate) async fn rollback(sysroot: &Storage) -> Result<()> {
870879
println!("Next boot: rollback deployment");
871880
}
872881

882+
let bootc_action: String = String::from("rollback");
883+
write_reboot_required(
884+
rollback_image.manifest_digest.as_ref(),
885+
bootc_action.as_str(),
886+
)?;
887+
873888
sysroot.update_mtime()?;
874889

875890
Ok(())

0 commit comments

Comments
 (0)