Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(minikube): generate k8s-api-ip.yaml where the render actually happens

Jose Ramirez7e1e1d256eac
diff --git a/scripts/minikube/full-setup.sh b/scripts/minikube/full-setup.sh
index 71196709a..a21c205b2 100755
--- a/scripts/minikube/full-setup.sh
+++ b/scripts/minikube/full-setup.sh
@@ -842,6 +842,22 @@ fi
# 6b. Deploy via kustomize
log "Refreshing minikube K8s API endpoint CIDRs..."
CONTEXT="${PROFILE}" OVERLAY_DIR="${ACTIVE_MINIKUBE_KUSTOMIZE_DIR}" "${PROJECT_DIR}/deploy/scripts/minikube-detect-k8s-api-ip.sh"
+# patches/k8s-api-ip.yaml is GENERATED and gitignored -- overlays/minikube
+# commits only the .template -- and overlays/minikube-ghcr renders ../minikube,
+# which patches with it.
+#
+# With MINIKUBE_IMAGE_TAG set, ACTIVE_MINIKUBE_KUSTOMIZE_DIR is the mktemp COPY
+# (apply_image_tag_override), so the line above writes the patch THERE and the
+# working tree never gets one. Every later consumer renders from the working
+# tree, or from image-mode.sh's own fresh copy of it: the next
+# `make minikube-pre-gate-sync` renders the control-api migration overlay
+# BEFORE `make minikube-deploy-all` regenerates the patch, and kustomize dies
+# with an evalsymlink error naming a file nothing ever wrote. Generate it in the
+# working tree too whenever the active dir is not the working tree.
+PROJECT_MINIKUBE_KUSTOMIZE_DIR="${PROJECT_DIR}/deploy/overlays/minikube"
+if [ "$ACTIVE_MINIKUBE_KUSTOMIZE_DIR" != "$PROJECT_MINIKUBE_KUSTOMIZE_DIR" ]; then
+ CONTEXT="${PROFILE}" OVERLAY_DIR="${PROJECT_MINIKUBE_KUSTOMIZE_DIR}" "${PROJECT_DIR}/deploy/scripts/minikube-detect-k8s-api-ip.sh"
+fi
ok "Minikube K8s API CIDRs refreshed"
# Upgrade path: stage the additive reader credential before the full overlay
diff --git a/scripts/minikube/image-mode.sh b/scripts/minikube/image-mode.sh
index 28bd1aadd..860c492d7 100755
--- a/scripts/minikube/image-mode.sh
+++ b/scripts/minikube/image-mode.sh
@@ -187,7 +187,7 @@ image_mode_images_generated_at() {
# project dir and the tag so repeated runs reuse one location instead of
# leaking a new mktemp -d every time.
image_mode_override_render_dir() {
- local project_dir="$1" tag="$2" key root component rewritten
+ local project_dir="$1" tag="$2" key root component rewritten patch
key="$(printf '%s' "$project_dir" | shasum | awk '{print $1}')"
root="${TMPDIR:-/tmp}/clerum-image-tag-override/${key}-${tag}"
rm -rf "$root"
@@ -201,6 +201,21 @@ image_mode_override_render_dir() {
printf 'image-mode: ghcr component missing from the deploy copy at %s\n' "$component" >&2
return 1
fi
+ # overlays/minikube-ghcr renders `resources: ../minikube`, which patches with
+ # patches/k8s-api-ip.yaml -- a GENERATED, gitignored file (the overlay commits
+ # only the .template). Copying a tree that has never had one produces a render
+ # dir that fails inside kustomize with
+ # evalsymlink failure on '<temp dir>/.../patches/k8s-api-ip.yaml'
+ # which names a path in a temp directory and tells the operator nothing about
+ # what to do. Fail here instead, naming the file in THEIR tree and the command
+ # that writes it.
+ patch="${root}/deploy/overlays/minikube/patches/k8s-api-ip.yaml"
+ if [ ! -f "$patch" ]; then
+ printf 'image-mode: %s/deploy/overlays/minikube/patches/k8s-api-ip.yaml has not been generated, so the MINIKUBE_IMAGE_TAG=%s render copy would not render.\n' \
+ "$project_dir" "$tag" >&2
+ printf 'image-mode: generate it with: CONTEXT=<minikube-profile> deploy/scripts/minikube-detect-k8s-api-ip.sh (make minikube-setup and make minikube-deploy-all both do this)\n' >&2
+ return 1
+ fi
# -i.bak plus rm keeps this portable across BSD and GNU sed; `sed -i ''` is a
# BSD-only spelling GNU sed rejects.
sed -i.bak "s|^\([[:space:]]*newTag:[[:space:]]*\).*$|\1${tag}|" "$component"
diff --git a/scripts/tests/test-minikube-full-setup.sh b/scripts/tests/test-minikube-full-setup.sh
index 430bd61da..ff625d1b6 100755
--- a/scripts/tests/test-minikube-full-setup.sh
+++ b/scripts/tests/test-minikube-full-setup.sh
@@ -611,6 +611,120 @@ assert_the_tag_origin_distinguishes_pin_from_override() {
fi
}
+# ---------------------------------------------------------------------------
+# The GENERATED k8s-api-ip.yaml under a tag override
+# ---------------------------------------------------------------------------
+#
+# patches/k8s-api-ip.yaml is generated and gitignored; overlays/minikube commits
+# only the .template, and overlays/minikube-ghcr renders `../minikube`, which
+# patches with it. With MINIKUBE_IMAGE_TAG set, ACTIVE_MINIKUBE_KUSTOMIZE_DIR is
+# the mktemp copy, so Step 6b used to write the patch ONLY there and the working
+# tree never got one. The next `make minikube-pre-gate-sync` renders a FRESH
+# copy of ${PROJECT_DIR}/deploy (image-mode.sh) for the control-api migration,
+# BEFORE `make minikube-deploy-all` regenerates the patch, and kustomize dies on
+# `evalsymlink failure on .../patches/k8s-api-ip.yaml`.
+#
+# These cases run the REAL Step 6b block and the REAL
+# deploy/scripts/minikube-detect-k8s-api-ip.sh against a stubbed kubectl, then
+# assert on the FILES that appear on disk and on how many times the detector
+# ran. Inverting the condition (or wrapping it in `if false && ...`) changes
+# both, so neither assertion survives a semantic mutation.
+extract_full_setup_k8s_api_ip_block() {
+ awk '
+ /Refreshing minikube K8s API endpoint CIDRs/ { cap = 1 }
+ cap { print }
+ cap && /Minikube K8s API CIDRs refreshed/ { exit }
+ ' "$1"
+}
+
+# A throwaway PROJECT_DIR carrying the real detector and the real patch
+# template, plus a kubectl stub that answers the one endpoint read the detector
+# makes and logs every call so invocations can be counted.
+prepare_k8s_api_ip_repo() {
+ local d=$1
+ mkdir -p "$d/bin" "$d/project/deploy/scripts" "$d/project/deploy/overlays/minikube/patches"
+ cp "$REPO_ROOT/deploy/scripts/minikube-detect-k8s-api-ip.sh" "$d/project/deploy/scripts/"
+ cp "$REPO_ROOT/deploy/overlays/minikube/patches/k8s-api-ip.yaml.template" \
+ "$d/project/deploy/overlays/minikube/patches/"
+ cat > "$d/bin/kubectl" <<'STUB'
+#!/usr/bin/env bash
+printf 'kubectl %s\n' "$*" >>"${TEST_LOG_FILE:?}"
+case "$*" in
+ *"get endpoints kubernetes"*) echo "10.11.12.13"; exit 0 ;;
+esac
+exit 0
+STUB
+ chmod +x "$d/bin/kubectl"
+}
+
+# The mktemp copy apply_image_tag_override would have produced.
+prepare_k8s_api_ip_override_copy() {
+ local d=$1
+ mkdir -p "$d/override/deploy/overlays/minikube/patches"
+ cp "$REPO_ROOT/deploy/overlays/minikube/patches/k8s-api-ip.yaml.template" \
+ "$d/override/deploy/overlays/minikube/patches/"
+}
+
+run_k8s_api_ip_block() {
+ local d=$1 active=$2 script
+ script="$d/step6b.sh"
+ {
+ printf 'set -euo pipefail\n'
+ printf 'log() { printf "LOG:%%s\\n" "$*"; }\n'
+ printf 'ok() { printf "OK:%%s\\n" "$*"; }\n'
+ printf 'PROFILE="clerum-test"\n'
+ printf 'PROJECT_DIR=%q\n' "$d/project"
+ printf 'ACTIVE_MINIKUBE_KUSTOMIZE_DIR=%q\n' "$active"
+ extract_full_setup_k8s_api_ip_block "$REPO_ROOT/scripts/minikube/full-setup.sh"
+ } > "$script"
+ PATH="$d/bin:$PATH" TEST_LOG_FILE="$d/ops.log" bash "$script" 2>&1
+}
+
+assert_the_tag_override_also_generates_the_api_ip_patch_in_the_working_tree() {
+ local d out rc calls problems=""
+ d="$(mktemp -d)"
+ prepare_k8s_api_ip_repo "$d"
+ prepare_k8s_api_ip_override_copy "$d"
+ out="$(run_k8s_api_ip_block "$d" "$d/override/deploy/overlays/minikube")"
+ rc=$?
+ calls="$(grep -c 'get endpoints kubernetes' "$d/ops.log")"
+ [ "$rc" -eq 0 ] || problems+="step 6b block exited $rc; "
+ grep -q '10.11.12.13/32' "$d/override/deploy/overlays/minikube/patches/k8s-api-ip.yaml" \
+ || problems+="the render copy did not get the generated patch; "
+ # The whole point: the working tree gets one too, so image-mode.sh's copy and
+ # the pre-gate migration render both find it.
+ grep -q '10.11.12.13/32' "$d/project/deploy/overlays/minikube/patches/k8s-api-ip.yaml" \
+ || problems+="the working tree did not get the generated patch; "
+ [ "$calls" = "2" ] || problems+="detector ran ${calls} time(s), expected 2; "
+ if [ -z "$problems" ]; then
+ pass "a tag override generates k8s-api-ip.yaml in the render copy AND in the working tree"
+ else
+ fail "$problems out=$out"
+ fi
+ rm -rf "$d"
+}
+
+# The complement, so the fix cannot be "always run it twice": with no override
+# the active kustomize dir IS the working tree, and one generation is enough.
+assert_the_unoverridden_path_generates_the_api_ip_patch_once() {
+ local d out rc calls problems=""
+ d="$(mktemp -d)"
+ prepare_k8s_api_ip_repo "$d"
+ out="$(run_k8s_api_ip_block "$d" "$d/project/deploy/overlays/minikube")"
+ rc=$?
+ calls="$(grep -c 'get endpoints kubernetes' "$d/ops.log")"
+ [ "$rc" -eq 0 ] || problems+="step 6b block exited $rc; "
+ grep -q '10.11.12.13/32' "$d/project/deploy/overlays/minikube/patches/k8s-api-ip.yaml" \
+ || problems+="the working tree did not get the generated patch; "
+ [ "$calls" = "1" ] || problems+="detector ran ${calls} time(s), expected 1; "
+ if [ -z "$problems" ]; then
+ pass "the unoverridden path generates k8s-api-ip.yaml exactly once, in the working tree"
+ else
+ fail "$problems out=$out"
+ fi
+ rm -rf "$d"
+}
+
# The guard that keeps this file honest: a case defined but never added to the
# call block below reports nothing at all, which reads as a green run.
assert_every_defined_case_is_invoked() {
@@ -649,6 +763,8 @@ assert_the_tag_override_copy_is_a_whole_deploy_tree_with_the_new_tag
assert_the_skip_build_staleness_advice_is_mode_aware
assert_the_banner_prints_the_image_source_tag_and_origin
assert_the_tag_origin_distinguishes_pin_from_override
+assert_the_tag_override_also_generates_the_api_ip_patch_in_the_working_tree
+assert_the_unoverridden_path_generates_the_api_ip_patch_once
assert_every_defined_case_is_invoked
exit $FAIL
diff --git a/scripts/tests/test-minikube-pre-gate-shadow.sh b/scripts/tests/test-minikube-pre-gate-shadow.sh
index 34be12752..3858c5faa 100755
--- a/scripts/tests/test-minikube-pre-gate-shadow.sh
+++ b/scripts/tests/test-minikube-pre-gate-shadow.sh
@@ -115,6 +115,14 @@ prepare_repo() {
cp -R "$REPO_ROOT/deploy" "$d/repo/deploy"
cp -R "$REPO_ROOT/scripts" "$d/repo/scripts"
rm -rf "$d/repo/deploy/minikube"
+ # patches/k8s-api-ip.yaml is GENERATED and gitignored (the overlay commits
+ # only the .template), so whether the developer's tree has one is incidental.
+ # Materialise it deterministically: by the time anything renders, `make
+ # minikube-setup` / `make minikube-deploy-all` have written it. Its absence is
+ # its own case (assert_a_render_copy_without_the_generated_patch_...), which
+ # deletes this file again.
+ cp "$d/repo/deploy/overlays/minikube/patches/k8s-api-ip.yaml.template" \
+ "$d/repo/deploy/overlays/minikube/patches/k8s-api-ip.yaml"
cat > "$d/repo/scripts/minikube/build-images.sh" <<'STUB'
#!/usr/bin/env bash
printf 'build-images %s\n' "$*" >>"${TEST_LOG_FILE:?}"
@@ -812,6 +820,71 @@ assert_an_overridden_tag_renders_from_a_copy_carrying_that_tag() {
rm -rf "$d"
}
+# The copy has to carry the GENERATED patch, not just the committed files.
+# overlays/minikube-ghcr renders `resources: ../minikube`, which patches with
+# patches/k8s-api-ip.yaml -- gitignored, written by minikube-detect-k8s-api-ip.sh.
+assert_a_render_copy_carries_the_generated_api_ip_patch() {
+ local d out rc
+ d="$(mktemp -d)"
+ prepare_repo "$d"
+ write_manifest "$d" '{"generated":"g1","imageSource":"ghcr","imageTag":"latest","images":{}}'
+ out="$(bash "$d/repo/scripts/minikube/image-mode.sh" --render-dir 2>&1)"
+ rc=$?
+ if [ "$rc" -eq 0 ] \
+ && [ -d "$out" ] \
+ && [ -f "${out}/../minikube/patches/k8s-api-ip.yaml" ]; then
+ pass "the tag-override render copy carries the generated k8s-api-ip.yaml"
+ else
+ fail "expected the copy to carry patches/k8s-api-ip.yaml; rc=$rc out=$out"
+ fi
+ rm -rf "$d"
+}
+
+# Reproduced before the fix: a fresh clone plus
+# `MINIKUBE_IMAGE_TAG=latest make minikube-setup` generated the patch only into
+# the setup's own mktemp copy, so the next pre-gate rendered a copy without one
+# and kustomize failed with `evalsymlink failure on <temp>/patches/
+# k8s-api-ip.yaml: no such file or directory` -- a path inside a temp dir, and
+# no remedy. Fail before the copy is handed out, naming the file in the
+# developer's tree and the command that writes it.
+assert_a_render_copy_without_the_generated_api_ip_patch_fails_with_a_remedy() {
+ local d out rc
+ d="$(mktemp -d)"
+ prepare_repo "$d"
+ write_manifest "$d" '{"generated":"g1","imageSource":"ghcr","imageTag":"latest","images":{}}'
+ rm -f "$d/repo/deploy/overlays/minikube/patches/k8s-api-ip.yaml"
+ out="$(bash "$d/repo/scripts/minikube/image-mode.sh" --render-dir 2>&1)"
+ rc=$?
+ if [ "$rc" -ne 0 ] \
+ && grep -Fq "$d/repo/deploy/overlays/minikube/patches/k8s-api-ip.yaml" <<< "$out" \
+ && grep -Fq 'deploy/scripts/minikube-detect-k8s-api-ip.sh' <<< "$out" \
+ && ! grep -q 'evalsymlink' <<< "$out"; then
+ pass "a copy missing the generated patch fails naming the file and how to regenerate it"
+ else
+ fail "expected a named, actionable failure; rc=$rc out=$out"
+ fi
+ rm -rf "$d"
+}
+
+# The pinned path renders the committed overlay in place, so it must NOT be
+# gated on the generated patch: kustomize is what reports a missing patch there,
+# and only the copy can be silently built without one.
+assert_the_pinned_render_dir_is_not_gated_on_the_generated_patch() {
+ local d out rc
+ d="$(mktemp -d)"
+ prepare_repo "$d"
+ write_manifest "$d" '{"generated":"g1","imageSource":"ghcr","imageTag":"'"$PIN_TAG"'","images":{}}'
+ rm -f "$d/repo/deploy/overlays/minikube/patches/k8s-api-ip.yaml"
+ out="$(bash "$d/repo/scripts/minikube/image-mode.sh" --render-dir 2>&1)"
+ rc=$?
+ if [ "$rc" -eq 0 ] && [ "$out" = "$d/repo/deploy/overlays/minikube-ghcr" ]; then
+ pass "the pinned render dir resolves without the generated patch"
+ else
+ fail "expected the committed ghcr overlay; rc=$rc out=$out"
+ fi
+ rm -rf "$d"
+}
+
# A mode that is neither ghcr nor local is a typo, and guessing one silently
# picks a cluster shape.
assert_an_unknown_image_source_is_rejected() {
@@ -914,6 +987,9 @@ assert_a_re_acquisition_forces_a_full_resync
assert_make_deploy_all_renders_the_mode_aware_overlay
assert_the_render_dir_resolver_follows_the_recorded_mode
assert_an_overridden_tag_renders_from_a_copy_carrying_that_tag
+assert_a_render_copy_carries_the_generated_api_ip_patch
+assert_a_render_copy_without_the_generated_api_ip_patch_fails_with_a_remedy
+assert_the_pinned_render_dir_is_not_gated_on_the_generated_patch
assert_an_unknown_image_source_is_rejected
assert_a_targeted_build_carries_the_recorded_coordinate_forward
assert_the_touched_scripts_parse