From 589c895d59b4c58da72bac34c1f911466ed2d680 Mon Sep 17 00:00:00 2001 From: Adham Kiwan Date: Thu, 19 Nov 2026 15:16:30 +0200 Subject: [PATCH] test(migrations): build each migration test image once per file Every test in the migration 54, 55, 57, 58, 59 and 61 bats files called prep(), and prep() ran `docker build -t` for one fixed tag. Tests in a file run concurrently under bats -j, so on a cold cache several builds of that tag ran at once. With the containerd image store a retag to a different image deletes the old one before creating the new one, and a sibling's `docker run` that resolved the tag in between found nothing locally and fell back to a pull of an image that does not exist. Build the image in setup_file, before any test of the file starts. prep() keeps a fallback build for a run without setup_file, taken only when the tag is missing. Closes: #5299 Assisted-by: LLM Signed-off-by: Adham Kiwan --- hack/migration-54-redis-adopt.bats | 28 +++++++++++++++----- hack/migration-55-fluxcd-orphan.bats | 28 +++++++++++++++----- hack/migration-57-seaweedfs-size-limit.bats | 26 +++++++++++++++--- hack/migration-58-http-cache-freeze.bats | 26 +++++++++++++++--- hack/migration-59-vmi-hotplug-volumes.bats | 26 +++++++++++++++--- hack/migration-61-strimzi-v1-conversion.bats | 26 +++++++++++++++--- 6 files changed, 132 insertions(+), 28 deletions(-) diff --git a/hack/migration-54-redis-adopt.bats b/hack/migration-54-redis-adopt.bats index 18fa8ce48..ec3281276 100644 --- a/hack/migration-54-redis-adopt.bats +++ b/hack/migration-54-redis-adopt.bats @@ -106,6 +106,25 @@ run_migration() { return "$_run_migration_rc" } +# build_test_image bakes the test's packages onto the pinned base. Its status +# is docker build's, so a failed build fails whoever called it. +build_test_image() { + docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || return 0 + build_test_image + return 0 +} + # prep resets env to a clean scenario. Tests set FAKE_* afterwards. prep() { # Fail here rather than at the first docker run, so the reason is legible. @@ -115,12 +134,9 @@ prep() { echo "busybox ash — the interpreter run-migrations.sh actually gives it." >&2 return 1 } - # Bake jq onto the pinned base. Cached after the first run, so this is a no-op - # on every subsequent test; only the first build touches the network. - docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || build_test_image chmod +x "$FAKEBIN/kubectl" WORK=$(mktemp -d) export FAKE_CMDLOG="$WORK/cmdlog" diff --git a/hack/migration-55-fluxcd-orphan.bats b/hack/migration-55-fluxcd-orphan.bats index 92dd8475c..c5c337250 100644 --- a/hack/migration-55-fluxcd-orphan.bats +++ b/hack/migration-55-fluxcd-orphan.bats @@ -103,6 +103,25 @@ run_migration() { return "$_run_migration_rc" } +# build_test_image bakes the test's packages onto the pinned base. Its status +# is docker build's, so a failed build fails whoever called it. +build_test_image() { + docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || return 0 + build_test_image + return 0 +} + # prep resets env to a clean scenario. Tests set FAKE_* afterwards. prep() { # Fail here rather than at the first docker run, so the reason is legible. @@ -112,12 +131,9 @@ prep() { echo "busybox ash — the interpreter run-migrations.sh actually gives it." >&2 return 1 } - # Bake jq onto the pinned base. Cached after the first run, so this is a no-op - # on every subsequent test; only the first build touches the network. - docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || build_test_image chmod +x "$FAKEBIN/kubectl" WORK=$(mktemp -d) export FAKE_CMDLOG="$WORK/cmdlog" diff --git a/hack/migration-57-seaweedfs-size-limit.bats b/hack/migration-57-seaweedfs-size-limit.bats index d2922def7..ccc1471b2 100644 --- a/hack/migration-57-seaweedfs-size-limit.bats +++ b/hack/migration-57-seaweedfs-size-limit.bats @@ -106,16 +106,34 @@ runbook_step() { return $? } +# build_test_image bakes the test's packages onto the pinned base. Its status +# is docker build's, so a failed build fails whoever called it. +build_test_image() { + docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || return 0 + build_test_image + return 0 +} + prep() { docker info >/dev/null 2>&1 || { echo "docker is required: these tests run migration 57 inside a jq-enabled" >&2 echo "build of $ALPINE, the migrations image's base." >&2 return 1 } - docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || build_test_image chmod +x "$FAKEBIN/kubectl" WORK=$(mktemp -d) export FAKE_CMDLOG="$WORK/cmdlog" diff --git a/hack/migration-58-http-cache-freeze.bats b/hack/migration-58-http-cache-freeze.bats index 6f07d3b83..905139282 100644 --- a/hack/migration-58-http-cache-freeze.bats +++ b/hack/migration-58-http-cache-freeze.bats @@ -58,16 +58,34 @@ run_migration() { return "$_run_migration_rc" } +# build_test_image bakes the test's packages onto the pinned base. Its status +# is docker build's, so a failed build fails whoever called it. +build_test_image() { + docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || return 0 + build_test_image + return 0 +} + prep() { docker info >/dev/null 2>&1 || { echo "docker is required: these tests run migration 58 inside a jq-enabled" >&2 echo "build of $ALPINE, the migrations image's base." >&2 return 1 } - docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || build_test_image chmod +x "$FAKEBIN/kubectl" mkdir -p "$WORKROOT" WORK=$(mktemp -d "$WORKROOT/XXXXXX") diff --git a/hack/migration-59-vmi-hotplug-volumes.bats b/hack/migration-59-vmi-hotplug-volumes.bats index 556061da2..d70cf4c97 100644 --- a/hack/migration-59-vmi-hotplug-volumes.bats +++ b/hack/migration-59-vmi-hotplug-volumes.bats @@ -48,16 +48,34 @@ run_migration() { return "$_run_migration_rc" } +# build_test_image bakes the test's packages onto the pinned base. Its status +# is docker build's, so a failed build fails whoever called it. +build_test_image() { + docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || return 0 + build_test_image + return 0 +} + prep() { docker info >/dev/null 2>&1 || { echo "docker is required: these tests run migration 59 inside a jq-enabled" >&2 echo "build of $ALPINE, the migrations image's base." >&2 return 1 } - docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || build_test_image chmod +x "$FIXTURES/kubectl" mkdir -p "$WORKROOT" WORK=$(mktemp -d "$WORKROOT/XXXXXX") diff --git a/hack/migration-61-strimzi-v1-conversion.bats b/hack/migration-61-strimzi-v1-conversion.bats index 6b82dd5c7..946d15765 100644 --- a/hack/migration-61-strimzi-v1-conversion.bats +++ b/hack/migration-61-strimzi-v1-conversion.bats @@ -78,16 +78,34 @@ run_migration() { return "$_run_migration_rc" } +# build_test_image bakes the test's packages onto the pinned base. Its status +# is docker build's, so a failed build fails whoever called it. +build_test_image() { + docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || return 0 + build_test_image + return 0 +} + prep() { docker info >/dev/null 2>&1 || { echo "docker is required: these tests run migration 61 inside a jq-enabled" >&2 echo "build of $ALPINE, the migrations image's base." >&2 return 1 } - docker build -q -t "$TESTIMG" - >/dev/null </dev/null 2>&1 || build_test_image chmod +x "$FIXTURES/kubectl" mkdir -p "$WORKROOT" WORK=$(mktemp -d "$WORKROOT/XXXXXX")