Skip to content

Commit 405f24e

Browse files
committed
fix(health): accept null IPAM for built-in networks
1 parent 0f1ff53 commit 405f24e

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎scripts/health.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ def _docker_network_headroom(run: Runner, values: dict[str, str], *, docker_ok:
384384
saw_ipv6 = False
385385
for entry in payload:
386386
configs = entry.get("IPAM", {}).get("Config", []) if isinstance(entry, dict) else []
387+
if configs is None and name in {"host", "none"}:
388+
configs = []
387389
if not isinstance(configs, list):
388390
return unavailable
389391
for config in configs:

‎scripts/test_health.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,43 @@ def run(args):
179179
result = health._docker_network_headroom(run, network_policy_values(), docker_ok=True)
180180
self.assertEqual(result["legacy"], 1)
181181

182+
def test_builtin_null_ipam_keeps_transactional_health_below_failure(self) -> None:
183+
networks = {
184+
"bridge": [{"IPAM": {"Config": [{"Subnet": "198.51.100.0/28"}]}}],
185+
"ci-fleet_default": [{"IPAM": {"Config": [{"Subnet": "172.18.0.0/16"}]}}],
186+
"host": [{"IPAM": {"Config": None}}],
187+
"none": [{"IPAM": {"Config": None}}],
188+
}
189+
190+
def run(args):
191+
if args[:3] == ["docker", "network", "ls"]:
192+
return health.subprocess.CompletedProcess(args, 0, "bridge\nci-fleet_default\nhost\nnone\n", "")
193+
return health.subprocess.CompletedProcess(args, 0, json.dumps(networks[args[-1]]), "")
194+
195+
network = health._docker_network_headroom(run, network_policy_values(), docker_ok=True)
196+
self.assertEqual(
197+
network,
198+
{"configured": 16, "used": 1, "free": 15, "reserve": 1, "legacy": 1, "state": "warning"},
199+
)
200+
report = health.evaluate({**healthy_snapshot(), "docker_network_headroom": network}, health.Thresholds())
201+
self.assertEqual((report["status"], report["exit_code"]), ("warning", 1))
202+
self.assertNotIn("docker_network_inspection", {check["id"] for check in report["checks"]})
203+
204+
def test_custom_null_ipam_still_fails_closed(self) -> None:
205+
def run(args):
206+
if args[:3] == ["docker", "network", "ls"]:
207+
return health.subprocess.CompletedProcess(args, 0, "custom\n", "")
208+
return health.subprocess.CompletedProcess(
209+
args,
210+
0,
211+
json.dumps([{"IPAM": {"Config": None}}]),
212+
"",
213+
)
214+
215+
self.assert_unavailable_network(
216+
health._docker_network_headroom(run, network_policy_values(), docker_ok=True)
217+
)
218+
182219
def test_overlapping_builtin_bridge_consumes_allocation_without_legacy_warning(self) -> None:
183220
def run(args):
184221
if args[:3] == ["docker", "network", "ls"]:

0 commit comments

Comments
 (0)