fix(ci): mount the swarm loop data roots with discard

The ext4 loop image behind each swarm lab node's Docker data root was mounted without discard. Blocks freed inside it, mostly docker save staging under data-root/tmp, stayed allocated in the sparse image, so the runner disk shrank for good. In main run 44185755981 this aborted Matrix#1 below 6144M free and made WordPress#3 refuse its pre-flight. ext4 now mounts with discard; btrfs mounts with discard=async, its kernel default, now made explicit.

🎯 Fix: 85 %
💥 Break: 4 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 82
🚦 Gate: ⛔ fix 85 % < 90

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-11-18 17:21:13 +00:00
1 parent 88d2b6ad09
commit 33c0d9a444
2 files changed
+39 -7

No files matched your search

@@ -214,12 +214,17 @@ require_tool() {
require_tool losetup util-linux || decline "losetup is unavailable"
require_tool mountpoint util-linux || decline "mountpoint is unavailable"
# A block freed inside a loop filesystem stays allocated in its sparse image
# until the filesystem discards it, so without these options every image pull
# and docker save staged in the data root grows the host disk for good.
case "${FSTYPE}" in
ext4)
require_tool mkfs.ext4 e2fsprogs || decline "mkfs.ext4 is unavailable"
MOUNT_OPTIONS=discard
;;
btrfs)
require_tool mkfs.btrfs btrfs-progs || decline "btrfs-progs is unavailable"
MOUNT_OPTIONS=discard=async
;;
zfs)
require_tool zpool zfsutils-linux zfs zfs-utils ||
@@ -295,7 +300,7 @@ if [ "${FSTYPE}" = zfs ]; then
zfs create -o mountpoint="${MOUNT}/docker" "${POOL}/docker"
else
"mkfs.${FSTYPE}" -q "${LOOP}"
mount -t "${FSTYPE}" "${LOOP}" "${MOUNT}"
mount -t "${FSTYPE}" -o "${MOUNT_OPTIONS}" "${LOOP}" "${MOUNT}"
arm_autoclear "${LOOP}" "${MOUNT}"
if [ "${FSTYPE}" = btrfs ]; then
btrfs subvolume create "${MOUNT}/docker" >/dev/null
@@ -26,7 +26,8 @@ STUB = (
" id) echo 0 ;;\n"
" awk) echo 10 ;;\n"
" losetup) echo /dev/infinito-test-loop ;;\n"
" mountpoint) exit 1 ;;\n"
' mount) touch "${STUB_LOG}.mounted" ;;\n'
' mountpoint) [ "$2" = /mnt/docker-fs ] && [ -e "${STUB_LOG}.mounted" ] ;;\n'
' zpool) [ "$1" != list ] ;;\n'
' systemctl) [ "$1" != cat ] ;;\n'
" python3) cat >/dev/null ;;\n"
@@ -39,6 +40,10 @@ STUBBED = (
"mountpoint",
"zpool",
"zfs",
"mkfs.ext4",
"mkfs.btrfs",
"btrfs",
"mount",
"systemctl",
"python3",
"modprobe",
@@ -49,8 +54,10 @@ STUBBED = (
)
def apply_zfs() -> tuple[subprocess.CompletedProcess, list[list[str]]]:
"""Run the zfs path of docker_dataroot.sh against stubs of every host tool.
def apply(fstype: str) -> tuple[subprocess.CompletedProcess, list[list[str]]]:
"""
Args:
fstype: the filesystem the script is asked to put the data root on.
Returns:
The finished process and the argv of every stubbed call, tool first.
@@ -71,7 +78,7 @@ def apply_zfs() -> tuple[subprocess.CompletedProcess, list[list[str]]]:
}
env.update(PATH=f"{bin_dir}{os.pathsep}{os.environ['PATH']}", STUB_LOG=str(log))
done = subprocess.run(
["bash", str(SCRIPT), "zfs", "true", "30G", "unit-node"],
["bash", str(SCRIPT), fstype, "true", "30G", "unit-node"],
env=env,
capture_output=True,
text=True,
@@ -83,16 +90,36 @@ def apply_zfs() -> tuple[subprocess.CompletedProcess, list[list[str]]]:
class TestDockerDatarootZfs(unittest.TestCase):
def test_the_stubbed_zfs_path_applies(self) -> None:
done, _ = apply_zfs()
done, _ = apply("zfs")
self.assertEqual(done.returncode, 0, done.stdout + done.stderr)
self.assertIn("status=applied-pending-docker", done.stdout)
def test_the_pool_returns_freed_blocks_to_the_sparse_image(self) -> None:
_, calls = apply_zfs()
_, calls = apply("zfs")
creates = [argv for argv in calls if argv[:2] == ["zpool", "create"]]
self.assertEqual(len(creates), 1, calls)
self.assertIn(("-o", "autotrim=on"), list(pairwise(creates[0])))
class TestDockerDatarootLoopMount(unittest.TestCase):
DISCARD = {"ext4": "discard", "btrfs": "discard=async"}
def test_the_stubbed_mount_paths_apply(self) -> None:
for fstype in self.DISCARD:
with self.subTest(fstype=fstype):
done, _ = apply(fstype)
self.assertEqual(done.returncode, 0, done.stdout + done.stderr)
self.assertIn("status=applied-pending-docker", done.stdout)
def test_the_mount_returns_freed_blocks_to_the_sparse_image(self) -> None:
for fstype, option in self.DISCARD.items():
with self.subTest(fstype=fstype):
_, calls = apply(fstype)
mounts = [argv for argv in calls if argv[0] == "mount"]
self.assertEqual(len(mounts), 1, calls)
self.assertIn(("-t", fstype), list(pairwise(mounts[0])))
self.assertIn(("-o", option), list(pairwise(mounts[0])))
if __name__ == "__main__":
unittest.main()