Skip to content

Commit f988b69

Browse files
twangboydwoz
authored andcommitted
Ignore Docker's auto-assigned network Gateway when comparing IPAM pools
Some Docker engine versions auto-fill a pool's Gateway even when only a Subnet was explicitly requested, while Salt's locally-built "desired" IPAM config never includes a Gateway unless the user set one. compare_networks() matched IPAM Config entries by strict dict equality, so this asymmetry was reported as a real config change, making docker_network.present() think the network needed recreating on every run (seen in test_docker_network.py::test_bridge_dupname_update on Ubuntu 26.04's newer Docker). Pair pools by Subnet and drop a Gateway key that's present on only one side before comparing, while still catching genuinely different explicit Gateway values.
1 parent fed4c65 commit f988b69

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎salt/modules/dockermod.py‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,31 @@ def strip_empty(pool):
13511351
[strip_empty(p) for p in val2.get("Config", [])],
13521352
key=kvsort,
13531353
)
1354-
if config1 != config2:
1354+
1355+
def config_changed(pools1, pools2):
1356+
by_subnet1 = {p.get("Subnet"): p for p in pools1}
1357+
by_subnet2 = {p.get("Subnet"): p for p in pools2}
1358+
if set(by_subnet1) != set(by_subnet2):
1359+
return True
1360+
for subnet_key, pool1 in by_subnet1.items():
1361+
pool2 = by_subnet2[subnet_key]
1362+
# Some Docker engine versions auto-assign a
1363+
# Gateway for a pool where none was explicitly
1364+
# requested (e.g. when only a Subnet was given).
1365+
# Don't treat that as a real difference.
1366+
if "Gateway" in pool1 and "Gateway" not in pool2:
1367+
pool1 = {
1368+
k: v for k, v in pool1.items() if k != "Gateway"
1369+
}
1370+
elif "Gateway" in pool2 and "Gateway" not in pool1:
1371+
pool2 = {
1372+
k: v for k, v in pool2.items() if k != "Gateway"
1373+
}
1374+
if pool1 != pool2:
1375+
return True
1376+
return False
1377+
1378+
if config_changed(config1, config2):
13551379
ret.setdefault("IPAM", {})["Config"] = {
13561380
"old": config1,
13571381
"new": config2,

0 commit comments

Comments
 (0)