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/.gitignoreindex 0dfbe5d61..359099275 100644--- a/.gitignore+++ b/.gitignore@@ -131,3 +131,7 @@ v8-compile-cache-*/playwright_chromiumdev_profile-*/.codexdist-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.yamldiff --git a/deploy/overlays/minikube/kustomization.yaml b/deploy/overlays/minikube/kustomization.yamlindex 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.yamlpatches:diff --git a/deploy/overlays/minikube/patches/k8s-api-ip.yaml b/deploy/overlays/minikube/patches/k8s-api-ip.yaml.templatesimilarity index 82%rename from deploy/overlays/minikube/patches/k8s-api-ip.yamlrename to deploy/overlays/minikube/patches/k8s-api-ip.yaml.templateindex 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__/32ports:- port: 443protocol: TCP@@ -52,7 +58,7 @@ spec:egress:- to:- ipBlock:- cidr: 172.17.0.4/32+ cidr: __K8S_API_IP__/32ports:- port: 443protocol: TCP@@ -80,7 +86,7 @@ spec:egress:- to:- ipBlock:- cidr: 172.17.0.4/32+ cidr: __K8S_API_IP__/32ports:- port: 443protocol: TCPdiff --git a/deploy/scripts/minikube-detect-k8s-api-ip.sh b/deploy/scripts/minikube-detect-k8s-api-ip.shindex 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 pipefailOVERLAY_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 0fi@@ -36,11 +41,14 @@ fiecho "[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"