refactor(macos): one infra container (control plane + gateway), fixes shared-DB races
Adopts the firecracker infra-VM pattern for macOS: the orchestrator control plane and the gateway data plane now run in a SINGLE Apple container instead of two. Apple Containers are lightweight VMs with separate kernels, so the prior two-container design had both guests writing one bot-bottle.db over virtiofs, where fcntl locks are not coherent across kernels — concurrent writes (the orchestrator's registry vs the gateway supervise daemon's queue) could corrupt it. One container = one kernel = coherent locking. The DB moves onto a container-only Apple volume (bot-bottle-mac-db), never bind-mounted from the host, so no host process opens the live file either. The host CLI already reaches registry + supervise state over the control-plane HTTP surface (cli/supervise.py uses OrchestratorClient), exactly as firecracker's VM-only DB requires. Two simplifications fall out of the single container: - No DNS dance: the control plane and gateway daemons reach each other over 127.0.0.1, so the orchestrator-before-gateway ordering (a workaround for Apple having no container DNS) is gone, along with the moved-IP recreate logic it needed. - Net -243 lines. Mechanics: the infra container runs from the gateway image with the control-plane source bind-mounted read-only (like the docker orchestrator, so a code change needs no rebuild) and a small sh -c init that starts both processes (mirrors firecracker's _infra_init). Also implements the macOS backend's ensure_orchestrator() and adds it to discover_orchestrator_url, so operator tools (supervise) can bring up / find the control plane on demand — previously the macOS backend died with "no orchestrator control plane". Verified end-to-end on real Apple Container 1.0.0: the single infra container comes up healthy (one address for control plane + gateway), both processes run, the DB is written on the container-only volume, host-side supervise works over HTTP, and a registered agent gets 200 for an allowed host / 403 for a denied one. 1824 unit tests pass with `container` absent (CI parity), pyright clean, pylint 9.89. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,30 +50,35 @@ def _client() -> Mock:
|
||||
|
||||
class TestEnsureGateway(unittest.TestCase):
|
||||
def _run(self, service: MagicMock) -> GatewayEndpoint:
|
||||
with patch(f"{_MOD}.MacosOrchestratorService", return_value=service):
|
||||
with patch(f"{_MOD}.MacosInfraService", return_value=service):
|
||||
return ensure_gateway()
|
||||
|
||||
def _service(self) -> MagicMock:
|
||||
from bot_bottle.backend.macos_container.infra import InfraEndpoint
|
||||
service = MagicMock()
|
||||
service.ensure_running.return_value = "http://192.168.128.2:8099"
|
||||
service.ensure_running.return_value = InfraEndpoint(
|
||||
control_plane_url="http://192.168.128.2:8099",
|
||||
gateway_ip="192.168.128.2",
|
||||
)
|
||||
service.network = "bot-bottle-mac-gateway"
|
||||
service.gateway.return_value.ip_on_shared_network.return_value = "192.168.128.3"
|
||||
service.gateway.return_value.ca_cert_pem.return_value = "PEM"
|
||||
service.ca_cert_pem.return_value = "PEM"
|
||||
return service
|
||||
|
||||
def test_reports_gateway_endpoint(self) -> None:
|
||||
endpoint = self._run(self._service())
|
||||
self.assertEqual("http://192.168.128.2:8099", endpoint.orchestrator_url)
|
||||
self.assertEqual("192.168.128.3", endpoint.gateway_ip)
|
||||
self.assertEqual("192.168.128.2", endpoint.gateway_ip)
|
||||
self.assertEqual("PEM", endpoint.gateway_ca_pem)
|
||||
self.assertEqual("bot-bottle-mac-gateway", endpoint.network)
|
||||
|
||||
def test_gateway_is_pointed_at_the_resolved_control_plane(self) -> None:
|
||||
"""Apple has no container DNS, so the gateway must be handed the
|
||||
control plane's *resolved URL* rather than a container name."""
|
||||
service = self._service()
|
||||
self._run(service)
|
||||
service.gateway.assert_called_with("http://192.168.128.2:8099")
|
||||
def test_control_plane_and_gateway_share_one_address(self) -> None:
|
||||
"""One infra container hosts both, so the gateway IP and the
|
||||
control-plane host are the same."""
|
||||
endpoint = self._run(self._service())
|
||||
self.assertEqual(
|
||||
endpoint.gateway_ip,
|
||||
endpoint.orchestrator_url.split("://")[1].split(":")[0],
|
||||
)
|
||||
|
||||
|
||||
class TestRegisterAgent(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user