Probe managed ingress across Docker namespaces

This commit is contained in:
2026-08-03 19:41:04 +02:00
parent 909862afdb
commit 2f28f22fd1
4 changed files with 177 additions and 36 deletions
+44 -2
View File
@@ -2,6 +2,7 @@ from __future__ import annotations
import importlib.util
from pathlib import Path
import json
import subprocess
import sys
import unittest
@@ -68,7 +69,13 @@ class ManagedIngressDrillTests(unittest.TestCase):
completed = subprocess.CompletedProcess(
[],
0,
"127.0.0.1:49152\n",
json.dumps(
{
"8443/tcp": [
{"HostIp": "127.0.0.1", "HostPort": "49152"}
]
}
),
"",
)
with patch.object(INGRESS, "_run", return_value=completed) as run:
@@ -76,10 +83,45 @@ class ManagedIngressDrillTests(unittest.TestCase):
self.assertEqual(49152, port)
self.assertEqual(
["docker", "port", "ingress", "8443/tcp"],
[
"docker",
"inspect",
"--format",
"{{json .HostConfig.PortBindings}}",
"ingress",
],
run.call_args.args[0],
)
def test_published_port_rejects_non_loopback_binding(self) -> None:
completed = subprocess.CompletedProcess(
[],
0,
'{"8443/tcp":[{"HostIp":"0.0.0.0","HostPort":"49152"}]}',
"",
)
with patch.object(INGRESS, "_run", return_value=completed):
with self.assertRaisesRegex(RuntimeError, "loopback binding"):
INGRESS._published_port("ingress", 8443)
def test_probe_runs_as_a_network_sibling_from_a_digest_image(self) -> None:
completed = subprocess.CompletedProcess([], 0, "", "")
image = "registry.example/runtime-api@sha256:" + "1" * 64
with patch.object(INGRESS, "_run", return_value=completed) as run:
INGRESS._probe_ingress(
image=image,
network="deployment-network",
container="ingress",
)
argv = run.call_args.args[0]
self.assertEqual("docker", argv[0])
self.assertIn("deployment-network", argv)
self.assertIn(image, argv)
self.assertIn('(\"ingress\", port)', argv[-1])
self.assertIn("server_hostname=\"localhost\"", argv[-1])
self.assertNotIn("localhost:49152", argv[-1])
if __name__ == "__main__":
unittest.main()