hives report an agent being updated: its status shows updating from the update's stop until the container is back up
A hive marks an agent updating when StopForUpdate stops its running container and clears it when the tail Reconcile or Start settles it, success or failure. The flag rides in the agent status snapshot (absent when false, so older readers and documents are unchanged), the status publisher sends a change at once instead of at the next sweep, and the swarm UI card shows an updating badge.
This commit is contained in:
parent
ca1e25b21e
commit
748ef2da08
2 changed files with 227 additions and 12 deletions
|
|
@ -841,7 +841,13 @@ async fn run_reconcile(
|
|||
) -> Result<Option<NodeKind>> {
|
||||
let running = host.is_running(name).await;
|
||||
let wanted = coord.power.get_or_seed(name, running);
|
||||
Ok(match reconcile_action(wanted, running) {
|
||||
let action = reconcile_action(wanted, running);
|
||||
// The update ends here unless this plans the start that brings the agent
|
||||
// back; `run_start` ends it then, once the container is up or has failed.
|
||||
if !matches!(action, ReconcileAction::Start) {
|
||||
coord.set_updating(name, false);
|
||||
}
|
||||
Ok(match action {
|
||||
ReconcileAction::Start => Some(NodeKind::Start {
|
||||
agent: name.to_owned(),
|
||||
}),
|
||||
|
|
@ -870,7 +876,12 @@ async fn run_start(host: &impl Host, coord: &Arc<Coordinator>, name: &str) -> Re
|
|||
let agent_dir = crate::paths::agent_runtime_dir(name);
|
||||
let hive = coord.hive_env();
|
||||
let paths = Coordinator::agent_paths(name, agent_dir)?;
|
||||
host.start(name, &hive, &paths).await?;
|
||||
// Whatever the outcome, the update this start belongs to is over: the
|
||||
// container is back up, or the node fails and the agent is as stopped as
|
||||
// it looks.
|
||||
let started = host.start(name, &hive, &paths).await;
|
||||
coord.set_updating(name, false);
|
||||
started?;
|
||||
// Bind the MCP listener immediately after starting the container.
|
||||
// The preamble created the runtime dir; the container is now coming
|
||||
// up and will connect to this socket on its first turn. Event-driven
|
||||
|
|
@ -906,6 +917,11 @@ async fn run_stop_for_update(host: &impl Host, coord: &Arc<Coordinator>, name: &
|
|||
// stopped state and would otherwise seed a running-but-unknown
|
||||
// agent as `Offline`, stranding it down after its own rebuild.
|
||||
coord.power.get_or_seed(name, true);
|
||||
// The agent is down for the update from here until the tail
|
||||
// `Reconcile` / `Start` settles it. Set before the kill so the status
|
||||
// never reads as plain stopped, and so a failed kill still gets cleared
|
||||
// by that tail.
|
||||
coord.set_updating(name, true);
|
||||
host.kill(name).await?;
|
||||
coord.rescan_containers_and_emit().await;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -609,8 +609,68 @@ async fn stop_for_update_failure_fails_the_node_after_seeding() {
|
|||
assert_eq!(coord.power.get("alice"), Some(Wanted::Up));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_update_is_marked_from_the_stop_until_the_agent_is_settled() {
|
||||
let (_dir, coord) = coordinator();
|
||||
// A stopped container is no update: nothing was taken down.
|
||||
run_stop_for_update(&FakeHost::down(), &coord, "alice")
|
||||
.await
|
||||
.expect("noop");
|
||||
assert!(!coord.is_updating("alice"));
|
||||
// Marked by the stop, and still marked when the kill fails: the tail
|
||||
// Reconcile is what ends it.
|
||||
run_stop_for_update(&FakeHost::up().failing("kill"), &coord, "alice")
|
||||
.await
|
||||
.expect_err("kill fails");
|
||||
assert!(coord.is_updating("alice"));
|
||||
coord.set_updating("alice", false);
|
||||
run_stop_for_update(&FakeHost::up(), &coord, "alice")
|
||||
.await
|
||||
.expect("stop ok");
|
||||
assert!(coord.is_updating("alice"));
|
||||
assert!(!coord.is_updating("bob"), "per agent");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_change_of_the_updating_set_wakes_the_status_publisher_once() {
|
||||
let (_dir, coord) = coordinator();
|
||||
coord.set_updating("alice", true);
|
||||
tokio::time::timeout(std::time::Duration::from_secs(1), coord.updating_changed())
|
||||
.await
|
||||
.expect("woken by the change");
|
||||
// The same state again is no change, so there is nothing to wake for.
|
||||
coord.set_updating("alice", true);
|
||||
assert!(
|
||||
tokio::time::timeout(
|
||||
std::time::Duration::from_millis(50),
|
||||
coord.updating_changed()
|
||||
)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
// --- Reconcile --------------------------------------------------------------
|
||||
|
||||
#[tokio::test]
|
||||
async fn reconcile_ends_the_update_unless_it_plans_the_start_that_does() {
|
||||
let (_dir, coord) = coordinator();
|
||||
// Wanted up and down: the start node ends the update, not this.
|
||||
coord.power.set("alice", Wanted::Up);
|
||||
coord.set_updating("alice", true);
|
||||
run_reconcile(&FakeHost::down(), &coord, "alice")
|
||||
.await
|
||||
.expect("ok");
|
||||
assert!(coord.is_updating("alice"));
|
||||
// Wanted offline (a deliberately stopped agent's rebuild): nothing comes
|
||||
// back, so the update is over.
|
||||
coord.power.set("alice", Wanted::Offline);
|
||||
run_reconcile(&FakeHost::down(), &coord, "alice")
|
||||
.await
|
||||
.expect("ok");
|
||||
assert!(!coord.is_updating("alice"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reconcile_fans_out_start_for_wanted_up_and_down() {
|
||||
let (_dir, coord) = coordinator();
|
||||
|
|
@ -934,6 +994,21 @@ async fn start_starts_then_registers_the_listener() {
|
|||
assert_eq!(host.calls(), ["start alice", "register_agent alice"]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_start_ends_the_update_whether_it_works_or_not() {
|
||||
let (_dir, coord) = coordinator();
|
||||
coord.set_updating("alice", true);
|
||||
run_start(&FakeHost::down(), &coord, "alice")
|
||||
.await
|
||||
.expect("ok");
|
||||
assert!(!coord.is_updating("alice"));
|
||||
coord.set_updating("alice", true);
|
||||
run_start(&FakeHost::down().failing("start"), &coord, "alice")
|
||||
.await
|
||||
.expect_err("start");
|
||||
assert!(!coord.is_updating("alice"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_failed_start_registers_no_listener() {
|
||||
let (_dir, coord) = coordinator();
|
||||
|
|
|
|||
Loading…
Reference in a new issue