feat(maintenance): a run spreads swarm services back out after its last host, moving only what the emptier node can start (#6398)
Each weekly run drains Docker02 then Docker03, and the swarm never moves a task back by itself, so every run ended with nearly every service on one node. On 2026-10-25 the operator had that spread out by hand. - Agent 1.26.0 reports each swarm service's pinned digest, and every repo@sha256 its host holds (from /system/df, every 10 min). - Once a run's last host is back in service, Steward picks services on the fullest node to move to the emptiest until they are within one task. It takes services with several replicas on one node first. A service moves only when the emptier node already holds its exact image. One the plan keeps in place, one below its replicas, and one with no pinned digest stay put, and the run says why. - A swarm manager's helper carries it out through a new action, rebalance, with the service names (validated, at most 48). It force-updates each in turn with the spec unchanged and no registry lookup, skips any a constraint places, and gives each 5 min to settle. - The run ends done with what moved, or failed if a move didn't settle or the manager didn't answer in 60 min. A docker-scoped window covers the restarts, and the step goes on the timeline. - Plans gain "Spread swarm services back out" (on by default) and "Keep in place", on the create form and in an "After the run" form on each plan. list_maintenance_plans shows both and the latest run's spread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -134,7 +134,9 @@ class HostMaintenancePlan(Base):
|
||||
`at_time` in `time_zone`, its hosts are updated one at a time, each
|
||||
rebooting per `reboot_policy`. No host is started after `window_minutes`
|
||||
from the run's start. last_slot_at is the last scheduled slot that fired;
|
||||
Run now leaves it alone, so the schedule keeps its time."""
|
||||
Run now leaves it alone, so the schedule keeps its time. With `spread`, a
|
||||
run that drained swarm nodes ends by spreading services back out, leaving
|
||||
the services named in `keep_in_place` (comma-separated) where they are."""
|
||||
__tablename__ = "host_maintenance_plans"
|
||||
|
||||
id = Column(String(36), primary_key=True, default=_uuid)
|
||||
@@ -147,6 +149,8 @@ class HostMaintenancePlan(Base):
|
||||
window_minutes = Column(Integer, nullable=False, default=240)
|
||||
reboot_policy = Column(String(16), nullable=False, default="if_required")
|
||||
enabled = Column(Boolean, nullable=False, default=True)
|
||||
spread = Column(Boolean, nullable=False, default=True)
|
||||
keep_in_place = Column(Text, nullable=False, default="")
|
||||
last_slot_at = Column(DateTime(timezone=True), nullable=True)
|
||||
created_by = Column(String(36), ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, default=_utcnow)
|
||||
@@ -158,7 +162,10 @@ class HostMaintenanceRun(Base):
|
||||
host_ids is the order fixed at the start (JSON list); position is the host
|
||||
being worked on; skipped is [{"host_id", "reason"}] for hosts the run
|
||||
passed over. settle_since is when the current host's job finished and the
|
||||
run began waiting for the host to be back in service."""
|
||||
run began waiting for the host to be back in service. rebalance is the
|
||||
spreading of swarm services back out once the last host is back
|
||||
(rebalance.py): its state, the manager carrying it out, what it moved and
|
||||
what it left and why; None while not reached or not wanted."""
|
||||
__tablename__ = "host_maintenance_runs"
|
||||
|
||||
id = Column(String(36), primary_key=True, default=_uuid)
|
||||
@@ -171,5 +178,6 @@ class HostMaintenanceRun(Base):
|
||||
settle_since = Column(DateTime(timezone=True), nullable=True)
|
||||
detail = Column(Text, nullable=True)
|
||||
manual = Column(Boolean, nullable=False, default=False)
|
||||
rebalance = Column(JSON, nullable=True)
|
||||
started_at = Column(DateTime(timezone=True), nullable=False, default=_utcnow)
|
||||
finished_at = Column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user