Skip to content

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

TypeScript

fix(minikube): render k8s-api-ip patch instead of rewriting a tracked file

Jose Ramirezde0cd0a20b55
diff --git a/.gitignore b/.gitignore
index 0dfbe5d61..359099275 100644
--- a/.gitignore
+++ b/.gitignore
@@ -131,3 +131,7 @@ v8-compile-cache-*/
playwright_chromiumdev_profile-*/
.codex
dist-public/
+
+# Rendered from patches/k8s-api-ip.yaml.template at setup time — the IP is
+# machine-specific, so the rendered file must never be tracked.
+deploy/overlays/minikube/patches/k8s-api-ip.yaml
diff --git a/deploy/overlays/minikube/kustomization.yaml b/deploy/overlays/minikube/kustomization.yaml
index aa75610c0..b66ed9880 100644
--- a/deploy/overlays/minikube/kustomization.yaml
+++ b/deploy/overlays/minikube/kustomization.yaml
@@ -90,9 +90,11 @@ patchesStrategicMerge:
# "unable to parse SM or JSON patch from [...]".
- patches/storage-class.yaml
# CIDR-based egress to kube-apiserver — required under Calico CNI.
- # The `cidr:` values are auto-patched by
- # `deploy/scripts/minikube-detect-k8s-api-ip.sh` on every
- # `make minikube-deploy-all` / `make minikube-setup`.
+ # RENDERED FILE (gitignored): generated from patches/k8s-api-ip.yaml.template
+ # by deploy/scripts/minikube-detect-k8s-api-ip.sh on every
+ # `make minikube-deploy-all` / `make minikube-setup`. A bare
+ # `kubectl apply -k` without that script will fail on the missing file —
+ # run the script (or make target) first.
- patches/k8s-api-ip.yaml
patches:
diff --git a/deploy/overlays/minikube/patches/k8s-api-ip.yaml b/deploy/overlays/minikube/patches/k8s-api-ip.yaml.template
similarity index 82%
rename from deploy/overlays/minikube/patches/k8s-api-ip.yaml
rename to deploy/overlays/minikube/patches/k8s-api-ip.yaml.template
index da2695d8d..9f4258ced 100644
--- a/deploy/overlays/minikube/patches/k8s-api-ip.yaml
+++ b/deploy/overlays/minikube/patches/k8s-api-ip.yaml.template
@@ -1,10 +1,16 @@
+# TEMPLATE — do not edit the rendered patches/k8s-api-ip.yaml (gitignored).
+# deploy/scripts/minikube-detect-k8s-api-ip.sh renders this file, replacing
+# __K8S_API_IP__ with the live kube-apiserver endpoint IP. Committing a real
+# IP here would dirty every contributor's tree on the first setup run.
+#
# Patch K8s API server IP for minikube cluster (clerum-test profile).
#
-# AUTO-MANAGED: The `cidr:` values below are overwritten on every
+# AUTO-MANAGED: The `cidr:` values below are rendered on every
# `make minikube-deploy-all` (and `make minikube-setup`) by
# `deploy/scripts/minikube-detect-k8s-api-ip.sh`, which reads the current
-# `kubernetes` endpoint IP. Do not rely on the committed value — it reflects
-# whatever node IP minikube had the last time someone ran the detector.
+# `kubernetes` endpoint IP into the sentinel `__K8S_API_IP__` above. The
+# rendered `patches/k8s-api-ip.yaml` is gitignored; only this template is
+# tracked.
#
# Why not `namespaceSelector`/`podSelector` instead of `ipBlock`?
# Stock K8s NetworkPolicy cannot reference Services or their endpoints; the
@@ -36,7 +42,7 @@ spec:
egress:
- to:
- ipBlock:
- cidr: 172.17.0.4/32
+ cidr: __K8S_API_IP__/32
ports:
- port: 443
protocol: TCP
@@ -52,7 +58,7 @@ spec:
egress:
- to:
- ipBlock:
- cidr: 172.17.0.4/32
+ cidr: __K8S_API_IP__/32
ports:
- port: 443
protocol: TCP
@@ -80,7 +86,7 @@ spec:
egress:
- to:
- ipBlock:
- cidr: 172.17.0.4/32
+ cidr: __K8S_API_IP__/32
ports:
- port: 443
protocol: TCP
diff --git a/deploy/scripts/minikube-detect-k8s-api-ip.sh b/deploy/scripts/minikube-detect-k8s-api-ip.sh
index 7e1cd2ad0..db2ce3130 100755
--- a/deploy/scripts/minikube-detect-k8s-api-ip.sh
+++ b/deploy/scripts/minikube-detect-k8s-api-ip.sh
@@ -18,9 +18,14 @@ set -euo pipefail
OVERLAY_DIR="${OVERLAY_DIR:-deploy/overlays/minikube}"
CONTEXT="${CONTEXT:-clerum-test}"
PATCH_FILE="$OVERLAY_DIR/patches/k8s-api-ip.yaml"
+TEMPLATE_FILE="$PATCH_FILE.template"
-if [ ! -f "$PATCH_FILE" ]; then
- echo "[detect-k8s-api-ip] $PATCH_FILE not present; skipping."
+# Render from the template when present (minikube overlay). Fall back to
+# in-place rewrite when only a plain patch file exists, so callers that
+# construct their own overlay dir (scripts/tests/test-gcp-scripts.sh) keep
+# working unchanged.
+if [ ! -f "$TEMPLATE_FILE" ] && [ ! -f "$PATCH_FILE" ]; then
+ echo "[detect-k8s-api-ip] no $PATCH_FILE or $TEMPLATE_FILE; skipping."
exit 0
fi
@@ -36,11 +41,14 @@ fi
echo "[detect-k8s-api-ip] context=$CONTEXT endpoint=$IP"
# Rewrite every `cidr: <ip>/32` line in the patch (BSD + GNU sed compatible).
+SOURCE_FILE="$PATCH_FILE"
+[ -f "$TEMPLATE_FILE" ] && SOURCE_FILE="$TEMPLATE_FILE"
+
tmp="$(mktemp)"
awk -v ip="$IP" '
/^[[:space:]]+cidr:/ { sub(/cidr:[[:space:]]*.*/, "cidr: " ip "/32"); }
{ print }
-' "$PATCH_FILE" > "$tmp"
+' "$SOURCE_FILE" > "$tmp"
mv "$tmp" "$PATCH_FILE"
echo "[detect-k8s-api-ip] patched: $PATCH_FILE"