Atlas and Metal upgrade ops: metald rollout plan
This is the plan for frappe/atlas#262. It is a proposal that waits for approval. Nothing in it is implemented yet.
Last updated 13 October 2026
1. Situation
metald is the daemon on each Metal host. It runs the Firecracker VMs, their network, and their consoles. Atlas builds it from the monorepo and gives it to the hosts. These are the problems with that process today:
- The binary changes without notice. Each Atlas deploy that changes
metal/builds a newmetaldand links it in Atlas Settings. A new host install then gets that binary at once. - No version on a host. Atlas does not know which
metaldruns on which host. - No phased rollout. The bulk "Upgrade Metald" action in the Metal Server list upgrades all selected hosts at the same time. It has no batches, no wait time and no stop on failure.
- A weak health check.
upgrade-metald.shrolls back only when systemd reports the unit inactive in the first 5 seconds. A crash one minute later stays in place. - Refused connections during a restart. A restart closes the API listeners. Atlas calls fail with "connection refused" until the new process listens again.
- No wg-mesh upgrade. Only the install path delivers
atlas-wg-mesh. After that, nothing updates it.
2. Scope
| In this change set | Later, as separate work |
|---|---|
|
|
tableflip is not needed. Section 7 explains why.
3. Build version
There is no release system yet. So the version is optional input to the build:
pilot --site atlas.localhost build-metald --version 1.4.0 # metald 1.4.0 pilot --site atlas.localhost build-metald # metald dev-20261013T101500Z pilot --site atlas.localhost build-wg-mesh --version 1.4.0 # same rule for wg-mesh
- Atlas runs
make build VERSION=<version>. Without--version, the version isdev-followed by the UTC build time. - The default in
metal/Makefileandservices/wg-mesh/Makefilechanges fromgit describeto the same development timestamp. This keeps one rule for each build path. - The
after_migratebuild uses the development timestamp. It still builds only when the source digest changes. - A
--versionthat is different from the stored version builds again, even when the source is unchanged. - New fields in the Atlas Settings "Metal Daemon" section:
metald_versionandwg_mesh_version(read only), next to the existing file and hash fields.
4. Version on each host
POST /v1/syncalready runs every 10 seconds for each host. Its response gets two optional fields:metald_versionandwg_mesh_version.metaldreads thewg-meshversion once at startup.- Host sync writes the values to the Metal Server only when they change. This is the same pattern as
private_network_mac_address. - An old
metalddoes not send the fields. The Metal Server then shows no version. - The Metal Server list shows a "Metald Version" column, so an operator can filter the hosts that are not on a version.
5. Metald Update doctype
An operator uses one Metald Update record to move a set of hosts to one pinned build. The record upgrades the hosts in batches. After each batch it waits, checks the health of the hosts, and then continues. On any failure it pauses.
Structure
Fields
Metald Update (module Operations, name METALD-UPDATE-.#####)
| Field | Type | Owner and rule |
|---|---|---|
status | Select: Draft, Running, Paused, Completed, Cancelled | Changed by the rollout job and the Desk actions |
version | Data, read only | Copied from Atlas Settings when the record is created |
metald_binary_file, metald_binary_hash | Link File, Data, read only | Copied when the record is created |
wg_mesh_binary_file, wg_mesh_binary_hash | Link File, Data, read only | Copied when the record is created |
canary_size | Int, default 1 | Number of hosts in the first batch. Edit only in Draft. |
batch_size | Int, default 5 | Number of hosts in each later batch. Edit in Draft or Paused. |
wait_minutes | Int, default 10 | Time to watch a batch before the health gate. Edit in Draft or Paused. |
current_batch | Int, read only | Set by the rollout job |
wait_until | Datetime, read only | The end of the watch time for the current batch |
failure_message | Small Text, read only | Why the update paused |
servers | Table: Metald Update Server | Rows can be added, removed and reordered only in Draft |
Metald Update Server (child table)
| Field | Type | Owner and rule |
|---|---|---|
server | Link Metal Server | Unique in the table |
batch | Int, read only | Set on Start from the row order |
status | Select: Pending, Upgrading, Upgraded, Failed, Skipped | The rollout job sets Upgrading. The host job sets Upgraded or Failed. |
previous_version | Data, read only | The version that the host reported before its upgrade |
ssh_task | Link SSH Task, read only | The script output |
failure_message | Small Text, read only | Why this host failed |
The update does not store counts, because the rows give them. The Metal Server gets two read-only fields: metald_version and wg_mesh_version. They go next to metald_tls_expires_on.
Form mockup
Build
▸ Binaries (Metald Binary, Metald Binary SHA-256, WG Mesh Binary, WG Mesh Binary SHA-256)
Rollout
Servers
| Server | Batch | Status | Previous Version | SSH Task |
|---|---|---|---|---|
| metal-waw-1 | 1 | Upgraded | dev-20261002T0814Z | SSH-TASK-0412 |
| metal-waw-2 | 2 | Upgraded | dev-20261002T0814Z | SSH-TASK-0418 |
| metal-waw-3 | 2 | Upgrading | dev-20261002T0814Z | |
| metal-waw-4 | 3 | Pending |
The buttons depend on the status. Draft shows Start. Running shows Pause and Cancel. Paused shows Resume and Cancel. Cancel asks for confirmation.
States
Rollout example
Twelve hosts, with a canary size of 1, a batch size of 5 and a wait of 10 minutes:
How it works
- Create. The record copies the version, the files and the hashes from Atlas Settings. It adds each Running Metal Server whose
metald_versionis different. The operator can remove or reorder rows. The Metal Server list action "Upgrade Metald" changes to "Create Metald Update", which uses the selected servers. - Start. This assigns batch numbers from the row order. It fails when another update is Running or Paused, or when a server is in another open update.
- Rollout job. It runs every minute with one job ID, so only one copy runs. For the current batch, it locks the record and sets each Pending row to Upgrading. It commits, and then it queues one host job for each row. A server that is not Running gets the Skipped status, which does not count as a failure.
- Host job. It uses the Metal Server
metald_job_id, so it never runs next to anothermetaldoperation on that host. It runsupgrade-metald.shwith the pinned URLs and hashes. Then it writes only its own row: Upgraded or Failed, the SSH Task, and the message. - Watch. When all rows in the batch are done, any Failed row pauses the update. If no row failed, the job sets
wait_untilto now pluswait_minutes. - Health gate. After the wait, each upgraded host must meet two conditions. It must report the target version, and its last sync must be less than 2 minutes old. If a host fails the gate, its row becomes Failed and the update pauses.
- Next batch or, when no rows are left, Completed.
- Pause stops new batches. Host jobs that are running finish. Resume sets Failed rows back to Pending and continues. Cancel is final.
- Stale row. If a row is Upgrading for longer than the script timeout plus 5 minutes, and its job is gone, the row becomes Failed with the message "upgrade job stopped".
- Roll back the fleet. Duplicate an older Metald Update. A duplicate keeps its pinned files. The cleanup of unlinked files, which runs every 15 minutes, keeps every file that a Metald Update links.
The "Upgrade Metald" button on a single Metal Server form stays. It is the quick path for one host, and it uses the latest build.
6. Upgrade on one host
These steps are added to upgrade-metald.sh. The download, the hash check, the version smoke test and the backup already exist.
- Both binaries. The script installs
metaldandatlas-wg-mesh, and keeps a.previouscopy of each.metaldrunsEnsureHoston each start, so the restart applies the new BPF release (section 8). - Readiness. When startup is complete (mesh set up, consoles and listeners adopted, servers serving),
metaldsendsSTATUS=ready <version>to systemd. The script waits up to 60 seconds untilsystemctl show -p StatusTextshows that value. - VM check. The script compares the number of active
metal-vm@units before and after the restart. If the number drops, the host fails. The rollout stops before the next host. - Self-rollback after the script ends. The script installs a drop-in,
metal.service.d/rollback.conf, withOnFailure=metal-rollback.service. It also writes/var/lib/metal/upgrade.json, which records an expiry time of 30 minutes. Assume that the newmetaldcrash-loops until systemd stops it, inside that window. The rollback unit then restores the.previousbinaries and startsmetal.serviceagain. After the window, the marker has no effect.
Why STATUS and not Type=notify: with Type=notify, a rollback to an old binary that never sends READY=1 would hang until the start timeout, and then fail. STATUS works with the current unit, which already has NotifyAccess=main. If a very old unit does not have that setting, the script checks only is-active and prints a warning.
7. Restart without refused connections
metaldstores its three listening sockets in the systemd file descriptor store. The sockets are the API (9000), coordination (9001) and migration transfer (9002) listeners. The PTY masters of the VM consoles already use this store.- At startup,
metaldtakes the stored socket that has the configured address. If there is none, it listens and stores the new socket. If the address changed, it removes the old socket from the store. - During a restart, the kernel keeps the socket open. New connections wait in the accept queue. Atlas sees a slower response, not "connection refused". The Atlas Metal client allows 5 seconds to connect and 30 to 60 seconds to read, so a restart of a few seconds fits in that time. We will measure the restart time on the development hosts.
- The current graceful shutdown already lets requests in progress finish, with a limit of 30 seconds.
- Open console WebSockets and running migration streams still close. Migrations continue from their resume token, as today. Console reconnect is later work.
- The first upgrade from an old
metaldstill refuses connections for a short time, because the old process did not store its sockets. Later upgrades do not.
Why not tableflip
tableflip runs the old and new processes at the same time and passes the listeners from one to the other. metald owns resources that only one process can own at a time: PTY readers, VM units through D-Bus, BPF attachments, reconcilers and migration records. The old process must release all of them before the new one starts. So the overlap gives nothing that the descriptor store does not already give. tableflip would also add a dependency. The descriptor store is already in use.
8. BPF maps
A BPF map is kernel memory that a BPF program reads and writes. A map is "pinned" when a file under /sys/fs/bpf keeps it alive after the process that made it exits. Two components use BPF, and they follow different rules.
metald traffic monitor (not pinned)
track_traffic.ocounts packets on each VM TAP device. Its maps and links belong to themetaldprocess.- When
metaldexits, the kernel removes the links and the maps. The new process loads new maps and attaches them in its first reconcile pass. - The counters start again at 0. The idle baseline is the time of attachment, which is the current contract.
- While
metaldis down, no packet events arrive. A sleeping VM wakes on the next client retry after the restart. - No state goes from one version to the next, so no compatibility rule is needed. This stays as it is.
wg-mesh datapath (pinned)
The mesh programs stay attached when no process runs. So packets continue to flow during a metald restart. An upgrade replaces the programs in this sequence (this logic already exists in services/wg-mesh/cli):
- The new
atlas-wg-meshopens each pinned map that has a name in its object file. It checks the type, key size, value size, maximum entries and flags withMapSpec.Compatible. - It reuses the compatible maps, creates the new maps, and pins its programs under
releases/<build hash>. - It fills new maps from the VM interfaces on the host.
tc filter replaceswaps each hook atomically. If a step fails, the hooks go back to the old release.- It writes
build_hash, and removes the old release and the maps that no program uses.
If a map layout changed, step 1 fails with "reset is required". EnsureHost fails, so metald does not start. The script restores both old binaries. The old programs stay attached the whole time, so packets do not stop. The rollout pauses at the canary.
Rules
- Do not change the type, key, value or maximum entries of an existing pinned map. Add a map with a new name. Old programs ignore it.
- The content of each pinned map must be possible to rebuild from
metaldsync (peers, VMs and host config). A downgrade removes maps that the old object does not know. - New CI job: build the BPF object at the merge base and at the pull request head. Then compare all maps that have the same name with
Compatible. A layout change fails the pull request and names the map. No.ofile goes into Git.
9. Compatibility
| Surface | Effect |
|---|---|
POST /v1/sync | Two optional response fields. An old Atlas ignores them, and an old metald does not send them. |
| Metal Server, Atlas Settings | New read-only fields. They are empty until the next build or sync. No patch is needed. |
| Metal Server list action | The bulk "Upgrade Metald" changes to "Create Metald Update". This is a Desk change only, with no API change. |
| systemd unit | A drop-in only. The base unit does not change. Without a descriptor store, metald listens as it does today. |
| BPF | No map change. |
| Files | Files that a Metald Update links stay. Other unlinked files are deleted as today. |
10. Failure cases
| Case | Behavior |
|---|---|
| The rollout job runs twice | Its job ID prevents a second copy. A Pending row becomes Upgrading only under the record lock. |
| A worker is killed during a host job | The script on the host finishes or rolls back by itself. The row becomes stale, then Failed, and the update pauses. |
| Atlas is down during a rollout | Host scripts finish. The rollout job continues on the next tick, and the health gate uses the sync time. |
| A bad binary passes the canary and crashes later | Self-rollback inside 30 minutes. Sync shows the old version, so the gate fails and the update pauses. |
The metald restart stops VMs | The VM count check fails on the canary, and the rollout stops. |
| BPF map layout changed | metald does not start. The script rolls back, and the datapath has no gap. CI catches this before merge. |
| 200 hosts | The batch size limits how many hosts upgrade at once. Each host job is one SSH job on the long queue. |
| Who writes what | The rollout job owns the update status, the batch fields, and the change from Pending to Upgrading. A host job owns its row result. Desk actions change the status under the record lock. The rollout job reads the status again under that lock before each change. |
| Operator view | The status, current batch, wait end time, row status, SSH Task and failure message, without SQL. |
11. Verification
- Go: tests for listener reuse (matched by name and address) and for the readiness status. Run
go test -raceon the changed packages. - wg-mesh CI check: a change to a map layout must make the check fail.
- Atlas, on
test.local: tests for batch assignment, the health gate, stale rows, and pause and resume, with real doctypes. - Live, on
atlas.localhostwith the waw Scaleway development hosts:- Canary of 1 host. During the upgrade, a loop calls
GET /v1/vmsevery 100 ms. Expect 0 connection errors, all VMs still running, and consoles that open after the restart. - A bad build that exits after 30 seconds. Expect the self-rollback to restore the previous binaries and the update to pause.
- A full rollout over all development hosts, with a batch size of 1 and a wait of 2 minutes.
- A ping between VMs on two hosts during the
wg-meshupgrade. Expect no packet loss.
- Canary of 1 host. During the upgrade, a loop calls
12. Commits
build(metal): Default the build version to a development timestamp: the Makefiles,--version, and the Atlas Settings version fields.feat(metal): Report the metald and wg-mesh versions in host sync: the sync response, and the Metal Server fields and list column.feat(metal): Keep the listening sockets across a metald restart: listeners in the descriptor store, and the readiness status.feat(atlas): Check readiness and roll back a failed metald upgrade: the script, the rollback drop-in, and thewg-meshinstall.feat(atlas): Add the Metald Update rollout: the Operations module, the doctypes, the rollout job, and the list action.build(wg-mesh): Check BPF map compatibility in CIdocs(atlas): Document the metald rollout: the operator runbook and theSPEC.mdupdates.
13. Decisions needed
- Is the doctype structure and form layout above good?
- Are the defaults good: a canary of 1, a batch size of 5, and a wait of 10 minutes?
- Does
wg-meshship in the same Metald Update asmetald? I recommend yes. - Is a self-rollback window of 30 minutes good?
- Do we replace the bulk "Upgrade Metald" list action with "Create Metald Update"? I recommend yes, so there is only one way to roll out to the fleet.