Skip to content

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 ​

TypeResponsibility
ServiceApplies desired host state, then reports the sync result.
DesiredStateThe 3 controller-owned sets, each complete.
SyncResultWhat one sync returns: capacity and VM states.
CapacityHost capacity for placement.
PrivilegedMesh, WireGuardManager, ImagePolicyStore, VirtualMachineSource, StorageCapacitySourceInjected services.
  • Service holds no state. Each injected service owns the state it applies.
  • The mesh service is nil when Atlas WG Mesh is disabled.
  • Dependencies.Compatibility holds the immutable facts that metald captures at startup. Each SyncResult returns 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:

  1. Apply the privileged VM addresses.
  2. Apply the WireGuard peers.
  3. Set the image policies.
  4. Set the WireGuard gateway return routes. vm.Manager stores them and adds them to each VM with is_accessible_via_wireguard_gateway. A VM route with the same destination wins.
  5. Wake the reconcilers.
  6. List the VM state once.
  7. Return the SyncResult.

Wake must follow the writes, so reconcilers act on the new policies at once.

Capacity ​

ResourceSource
CPU totalHost CPU count × 1000 millicores.
CPU availableTotal minus VM cpu_millicores, floored at zero.
MemoryMemAvailable from /proc/meminfo.
StorageStorageCapacitySource.
  • CPU is for visibility only. No admission check uses it.
  • VirtualMachineSource skips 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.

AGPL-3.0