host: controller synchronization and capacity
For Go code, follow the repository Go anti-pattern rules.
Metal specification · Behavior: host sync
Purpose
The host package applies the controller-owned sets: WireGuard peers, image policies, privileged VM addresses, and WireGuard gateway return routes. Each complete set replaces the previous one.
Types
| Type | Responsibility |
|---|---|
Service | Applies desired host state, then reports the sync result. |
DesiredState | The 3 controller-owned sets, each complete. |
SyncResult | What one sync returns: capacity and VM states. |
Capacity | Host capacity for placement. |
PrivilegedMesh, WireGuardManager, ImagePolicyStore, VirtualMachineSource, StorageCapacitySource | Injected services. |
Serviceholds no state. Each injected service owns the state it applies.- The mesh service is nil when Atlas WG Mesh is disabled.
Dependencies.Compatibilityholds the immutable facts that metald captures at startup. EachSyncResultreturns the same optional report. Atlas owns compatibility decisions. See host sync.
Synchronize
POST /v1/sync runs these steps in order and stops at the first error:
- Apply the privileged VM addresses.
- Apply the WireGuard peers.
- Set the image policies.
- Set the WireGuard gateway return routes.
vm.Managerstores them and adds them to each VM withis_accessible_via_wireguard_gateway. A VM route with the same destination wins. - Wake the reconcilers.
- List the VM state once.
- Return the
SyncResult.
Wake must follow the writes, so reconcilers act on the new policies at once.
Capacity
| Resource | Source |
|---|---|
| CPU total | Host CPU count × 1000 millicores. |
| CPU available | Total minus the reserve and the cpu_millicores of each VM that runs, pauses or boots, floored at zero. A burstable VM counts its baseline_cpu_millicores. A sleeping VM holds no CPU. |
| Memory available | The smaller of MemAvailable from /proc/meminfo and total memory minus the reserve and the memory_mib of each VM that runs, pauses or boots. A sleeping VM holds no memory. |
| Storage available | The smaller of real ZFS free space and the pool size × StorageOvercommitFactor minus the size of every VM disk. Incoming migration reservations and the reserved percent of the pool are then subtracted. |
| Storage used | Real ZFS used of the pool. Thin VM disks count only the data that they hold. |
The
[capacity]section ofmetald.tomlsets theReserve. Each missing key is 0.install-metald.shwrites 18432 MiB of memory (the ZFS ARC maximum and the host system), 2000 millicores and 10% of the pool. On the host that runs the Atlas VM, it adds the memory and CPU of that VM.The controller sends
storage_overcommit_factoron each sync. The service keeps the last value in memory. It is 1 until the first sync after a start, so a restarted host overcommits nothing until then.CPU is for visibility only. No admission check uses it.
VirtualMachineSourceskips a VM that has only one of its two records.
Virtual machine states
SyncResult.VirtualMachineStates maps each VM ID to its last observed state. It reuses the capacity List call, which reads stored records, not the runtime.
Related
- internal/api/SPEC.md owns the sync request and response shapes.
- internal/network/SPEC.md owns WireGuard peers and the privileged mesh.
- internal/storage/SPEC.md owns image policies and pool capacity.