Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): preserve API egress policy during watch faults
Alfredo Lopez6c2cd8ddc6e3
diff --git a/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh b/scripts/e2e/_lib/hcc-watch-recovery-fixture.shindex a02098b28..ecb97cbdc 100755--- a/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh+++ b/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh@@ -338,10 +338,10 @@ delete_hcc_proxy_fixture() {}restore_hcc_after_fault_injection() {- local host_override port_override host_aliases desired ready+ local host_override port_override api_cidrs_override host_aliases desired readykctl set env deployment/"$HCC_DEPLOY" -n "$HCC_NS" \- KUBERNETES_SERVICE_HOST- KUBERNETES_SERVICE_PORT- >/dev/null || return 1+ KUBERNETES_SERVICE_HOST- KUBERNETES_SERVICE_PORT- CONTEXT_MAPPER_K8S_API_CIDRS- >/dev/null || return 1kctl patch deployment "$HCC_DEPLOY" -n "$HCC_NS" --type=merge \-p '{"spec":{"template":{"spec":{"hostAliases":null}}}}' >/dev/null || return 1kctl rollout status deployment "$HCC_DEPLOY" -n "$HCC_NS" --timeout=180s >/dev/null || return 1@@ -350,10 +350,12 @@ restore_hcc_after_fault_injection() {-o jsonpath='{.spec.template.spec.containers[?(@.name=="host-context-controller")].env[?(@.name=="KUBERNETES_SERVICE_HOST")].name}')"port_override="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" \-o jsonpath='{.spec.template.spec.containers[?(@.name=="host-context-controller")].env[?(@.name=="KUBERNETES_SERVICE_PORT")].name}')"+ api_cidrs_override="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" \+ -o jsonpath='{.spec.template.spec.containers[?(@.name=="host-context-controller")].env[?(@.name=="CONTEXT_MAPPER_K8S_API_CIDRS")].name}')"host_aliases="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" -o jsonpath='{.spec.template.spec.hostAliases}')"desired="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" -o jsonpath='{.spec.replicas}')"ready="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" -o jsonpath='{.status.readyReplicas}')"- [ -z "$host_override$port_override$host_aliases" ] && [ "$desired" = "$ready" ]+ [ -z "$host_override$port_override$api_cidrs_override$host_aliases" ] && [ "$desired" = "$ready" ]}print_hcc_repair_instructions() {@@ -362,7 +364,7 @@ HCC restoration failed. Proxy resources were retained for repair.Context: ${E2E_KUBECONTEXT}Proxy: ${HCC_NS}/${PROXY_NAME}Repair commands:- kubectl --context=${E2E_KUBECONTEXT} -n ${HCC_NS} set env deployment/${HCC_DEPLOY} KUBERNETES_SERVICE_HOST- KUBERNETES_SERVICE_PORT-+ kubectl --context=${E2E_KUBECONTEXT} -n ${HCC_NS} set env deployment/${HCC_DEPLOY} KUBERNETES_SERVICE_HOST- KUBERNETES_SERVICE_PORT- CONTEXT_MAPPER_K8S_API_CIDRS-kubectl --context=${E2E_KUBECONTEXT} -n ${HCC_NS} patch deployment/${HCC_DEPLOY} --type=merge -p '{"spec":{"template":{"spec":{"hostAliases":null}}}}'kubectl --context=${E2E_KUBECONTEXT} -n ${HCC_NS} rollout status deployment/${HCC_DEPLOY} --timeout=180sAfter HCC is healthy, delete ${PROXY_NAME}, ${PROXY_EGRESS_NP}, ${HCC_PROXY_NP}, and ${PROBE_EGRESS_NP} in ${HCC_NS}.diff --git a/scripts/e2e/e2e-hcc-communicationchannel-watch-recovery.sh b/scripts/e2e/e2e-hcc-communicationchannel-watch-recovery.shindex cef9d1680..530b0223a 100755--- a/scripts/e2e/e2e-hcc-communicationchannel-watch-recovery.sh+++ b/scripts/e2e/e2e-hcc-communicationchannel-watch-recovery.sh@@ -42,6 +42,7 @@ kctl get nodes -o json | jq -e \HCC_NS="${HCC_NS:-control-plane}"HCC_DEPLOY="${HCC_DEPLOY:-host-context-controller}"+MCP_NS="${MCP_NS:-mcp-server}"SOURCE_HOST="${E2E_SOURCE_HOST_REF:-chatllm-stateless}"HOST_NS="${MCP_HOST_NS:-mcp-host}"CHANNEL_NS="${CHANNELS_NS:-channels}"@@ -87,7 +88,7 @@ print_hcc_proxy_rollout_diagnostics() {jq -r '.items[] |.status.containerStatuses[]? |- "pod=\(.metadata.name) phase=\(.status.phase // \"unknown\") ready=\(.ready) restarts=\(.restartCount) waiting=\(.state.waiting.reason // \"none\") terminated=\(.state.terminated.reason // \"none\") exitCode=\(.state.terminated.exitCode // \"none\") lastTerminated=\(.lastState.terminated.reason // \"none\") lastExitCode=\(.lastState.terminated.exitCode // \"none\")"+ "pod=\(.metadata.name) phase=\(.status.phase // "unknown") ready=\(.ready) restarts=\(.restartCount) waiting=\(.state.waiting.reason // "none") terminated=\(.state.terminated.reason // "none") exitCode=\(.state.terminated.exitCode // "none") lastTerminated=\(.lastState.terminated.reason // "none") lastExitCode=\(.lastState.terminated.exitCode // "none")"' >&2 || truewhile IFS= read -r pod; do@@ -176,13 +177,24 @@ host_override="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" \-o jsonpath='{.spec.template.spec.containers[?(@.name=="host-context-controller")].env[?(@.name=="KUBERNETES_SERVICE_HOST")].name}')"port_override="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" \-o jsonpath='{.spec.template.spec.containers[?(@.name=="host-context-controller")].env[?(@.name=="KUBERNETES_SERVICE_PORT")].name}')"-[ -z "$host_override$port_override" ] || die "HCC already has an explicit Kubernetes service override"+api_cidrs_override="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" \+ -o jsonpath='{.spec.template.spec.containers[?(@.name=="host-context-controller")].env[?(@.name=="CONTEXT_MAPPER_K8S_API_CIDRS")].name}')"+[ -z "$host_override$port_override$api_cidrs_override" ] ||+ die "HCC already has an explicit Kubernetes service or API CIDR override"[ -z "$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" -o jsonpath='{.spec.template.spec.hostAliases}')" ] ||die "HCC already has hostAliases; refusing a non-restorable fault injection"HCC_IMAGE="$(kctl get deployment "$HCC_DEPLOY" -n "$HCC_NS" \-o jsonpath='{.spec.template.spec.containers[?(@.name=="host-context-controller")].image}')"[ -n "$HCC_IMAGE" ] || die "could not resolve the running HCC image"+K8S_API_SERVICE_HOST="$(kctl exec deployment/"$HCC_DEPLOY" -n "$HCC_NS" \+ -c host-context-controller -- printenv KUBERNETES_SERVICE_HOST)" ||+ die "could not read the Kubernetes-injected API service IP"+kctl exec deployment/"$HCC_DEPLOY" -n "$HCC_NS" -c host-context-controller -- \+ node -e 'const { isIP } = require("node:net"); process.exit(isIP(process.argv[1]) === 4 ? 0 : 1)' \+ "$K8S_API_SERVICE_HOST" >/dev/null ||+ die "Kubernetes-injected API service host is not an IPv4 address"+K8S_API_CIDR="${K8S_API_SERVICE_HOST}/32"log "Creating an isolated TCP proxy for the Kubernetes API"create_hcc_api_proxy@@ -191,11 +203,12 @@ verify_hcc_proxy_network_policyPROXY_IP="$(kctl get service "$PROXY_NAME" -n "$HCC_NS" -o jsonpath='{.spec.clusterIP}')"[ -n "$PROXY_IP" ] || die "proxy Service has no ClusterIP"HCC_PATCHED=1-hcc_proxy_patch="$(jq -cn --arg ip "$PROXY_IP" '{spec:{template:{spec:{+hcc_proxy_patch="$(jq -cn --arg ip "$PROXY_IP" --arg api_cidr "$K8S_API_CIDR" '{spec:{template:{spec:{hostAliases:[{ip:$ip,hostnames:["kubernetes.default.svc"]}],containers:[{name:"host-context-controller",env:[{name:"KUBERNETES_SERVICE_HOST",value:"kubernetes.default.svc"},- {name:"KUBERNETES_SERVICE_PORT",value:"443"}+ {name:"KUBERNETES_SERVICE_PORT",value:"443"},+ {name:"CONTEXT_MAPPER_K8S_API_CIDRS",value:$api_cidr}]}]}}}}')"kctl patch deployment "$HCC_DEPLOY" -n "$HCC_NS" --type=strategic -p "$hcc_proxy_patch" >/dev/null@@ -206,6 +219,11 @@ fiinitial_hcc_identity="$(wait_for_hcc_identity 30)" || die "could not capture HCC pod identity"read -r HCC_UID HCC_RESTARTS <<<"$initial_hcc_identity"[ -n "$HCC_UID" ] && [ "$HCC_UID" != invalid ] || die "could not capture HCC pod identity"+proxy_policy_cidrs="$(kctl get networkpolicy "allow-k8s-api-egress-${MCP_NS}" -n "$MCP_NS" -o json |+ jq -r '[.spec.egress[0].to[]?.ipBlock.cidr] | join(",")')" ||+ die "could not read the proxy-run API egress policy"+[ "$proxy_policy_cidrs" = "$K8S_API_CIDR" ] ||+ die "proxy-run API egress policy did not retain the injected Kubernetes API CIDR"ok "HCC is healthy through the proxy (pod=${HCC_UID}, restarts=${HCC_RESTARTS})"log "Creating one stateful control and two stateless Host fixtures"diff --git a/scripts/tests/test-hcc-watch-recovery-gate.sh b/scripts/tests/test-hcc-watch-recovery-gate.shindex 543455cee..300defab1 100755--- a/scripts/tests/test-hcc-watch-recovery-gate.sh+++ b/scripts/tests/test-hcc-watch-recovery-gate.sh@@ -46,6 +46,8 @@ proxy_rollout_function="$(if [[ "$proxy_rollout_function" == *'kctl get pods'* ]] &&[[ "$proxy_rollout_function" == *'--previous --tail=120'* ]] &&[[ "$proxy_rollout_function" == *'status.containerStatuses'* ]] &&+ [[ "$proxy_rollout_function" == *'// "unknown"'* ]] &&+ [[ "$proxy_rollout_function" != *'\\"unknown\\"'* ]] &&grep -Fq 'if ! kctl rollout status deployment "$HCC_DEPLOY"' "$WATCH_GATE" &&[ "$(grep -Fc 'print_hcc_proxy_rollout_diagnostics' "$WATCH_GATE")" = 2 ]; thenpass "proxy rollout failure emits bounded HCC pod and previous-container diagnostics"@@ -53,6 +55,22 @@ elsefail "proxy rollout failure can discard the distinguishing HCC startup evidence"fi+# The proxy changes only the HCC client's target hostname. The HCC's+# allow-k8s-api-egress policies must retain the Kubernetes-injected API IP,+# which is the explicit fail-closed configuration seam for CIDR policy data.+# shellcheck disable=SC2016+if grep -Fq 'K8S_API_SERVICE_HOST="$(kctl exec deployment/"$HCC_DEPLOY"' "$WATCH_GATE" &&+ grep -Fq 'K8S_API_CIDR="${K8S_API_SERVICE_HOST}/32"' "$WATCH_GATE" &&+ grep -Fq -- '--arg api_cidr "$K8S_API_CIDR"' "$WATCH_GATE" &&+ grep -Fq 'CONTEXT_MAPPER_K8S_API_CIDRS",value:$api_cidr' "$WATCH_GATE" &&+ grep -Fq 'allow-k8s-api-egress-${MCP_NS}' "$WATCH_GATE" &&+ grep -Fq '[ "$proxy_policy_cidrs" = "$K8S_API_CIDR" ]' "$WATCH_GATE" &&+ grep -Fq 'CONTEXT_MAPPER_K8S_API_CIDRS-' "$FIXTURE_HELPER"; then+ pass "proxy fault injection preserves an explicit valid API egress CIDR and restores it"+else+ fail "proxy fault injection can turn a DNS hostname into an invalid API egress CIDR"+fi+if grep -Fq 'source "${SCRIPT_DIR}/_lib/hcc-watch-recovery-fixture.sh"' "$READINESS_GATE" &&[ "$(grep -Fc 'require_branch_owned_hcc_gate "$HCC_NS"' "$READINESS_GATE")" = 1 ] &&! grep -Fq 'HCC_BRANCH_GATE_SYNC_MARKER' "$READINESS_GATE" &&