Answer architecture round 1: 0 🔴, 3 🟡 (0 misread); keep the slot's share beside ROOM_SHARE in machine_load, move the rule's predicate into rule_hook, and have capped set both limits itself instead of leaning on docker taking the last option

This commit is contained in:
2026-10-24 11:24:21 +02:00
parent 4c1ab3f185
commit 52641079b7
7 changed files with 60 additions and 31 deletions
+10 -3
View File
@@ -14,9 +14,16 @@ class Capped(unittest.TestCase):
with self.subTest(given):
self.assertEqual(capped(given, "6144m"), expected)
def test_a_container_s_own_memory_limit_is_kept_and_caps_its_swap(self):
self.assertEqual(capped(["run", "-m", "10g", "img"], "6144m"), ["run", "--memory-swap", "10g", "-m", "10g", "img"])
self.assertEqual(capped(["run", "--memory=12g", "img"], "6144m"), ["run", "--memory-swap", "12g", "--memory=12g", "img"])
def test_a_container_s_own_limit_is_kept_and_sets_the_limit_it_lacks(self):
for given, expected in [
(["run", "-m", "10g", "img"], ["run", "--memory", "10g", "--memory-swap", "10g", "img"]),
(["run", "--memory=12g", "img"], ["run", "--memory", "12g", "--memory-swap", "12g", "img"]),
(["run", "--memory-swap", "2g", "img"], ["run", "--memory", "2g", "--memory-swap", "2g", "img"]),
(["run", "-m", "4g", "--memory-swap", "-1", "img"], ["run", "--memory", "4g", "--memory-swap", "4g", "img"]),
(["run", "-m4g", "--memory-swap=0", "img", "python", "-m", "pytest"], ["run", "--memory", "4g", "--memory-swap", "4g", "img", "python", "-m", "pytest"]),
]:
with self.subTest(given):
self.assertEqual(capped(given, "6144m"), expected)
def test_a_container_with_both_limits_or_another_docker_call_is_left_alone(self):
for given in [["run", "-m", "10g", "--memory-swap", "12g", "img"], ["ps"], ["build", "."], ["run", "--help"], ["compose", "run", "app"], ["exec", "box", "true"]]: