Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): resolve WRC workload instances
Alfredo Lopezffe210408995
diff --git a/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh b/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.shindex 35a61e913..f72cbca00 100755--- a/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh+++ b/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh@@ -18,6 +18,8 @@ BACKEND_ID="${E2E_BACKEND_ID:-be-${RUN_ID}}"DENIED_POD="${E2E_DENIED_POD:-deny-${RUN_ID}}"BACKEND_PORT="${E2E_BACKEND_PORT:-8080}"CONNECT_TIMEOUT="${E2E_CONNECT_TIMEOUT:-6}"+SOURCE_DEPLOYMENT="$SOURCE_ID"+BACKEND_DEPLOYMENT="$BACKEND_ID"CREATED=0cleanup() {@@ -28,9 +30,9 @@ cleanup() {--ignore-not-found --wait=false >/dev/null 2>&1 || status=1wait_for_workflowrecipe_deleted "$WORKFLOW_RECIPE_NS" "$RECIPE_NAME" "$TIMEOUT_DELETE" \>/dev/null 2>&1 || status=1- kctl delete deployment "$SOURCE_ID" "$BACKEND_ID" -n "$SANDBOX_NS" \+ kctl delete deployment "$SOURCE_DEPLOYMENT" "$BACKEND_DEPLOYMENT" -n "$SANDBOX_NS" \--ignore-not-found --wait=false >/dev/null 2>&1 || status=1- kctl delete service "$SOURCE_ID" "$BACKEND_ID" -n "$SANDBOX_NS" \+ kctl delete service "$SOURCE_DEPLOYMENT" "$BACKEND_DEPLOYMENT" -n "$SANDBOX_NS" \--ignore-not-found >/dev/null 2>&1 || status=1kctl delete networkpolicy -n "$SANDBOX_NS" \-l "clerum.io/managed-by=workflow-recipes,clerum.io/policy-type=internal-dependency,clerum.io/recipe=${RECIPE_NAME}" \@@ -85,6 +87,21 @@ wait_internal_ready() {return 1}+wait_for_workload_instance() {+ local workload_id=$1 timeout=${2:-$TIMEOUT_POD} elapsed=0 instance+ while [ "$elapsed" -lt "$timeout" ]; do+ instance="$(kctl get workflowrecipe "$RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" \+ -o "jsonpath={.status.workloadInstances.${workload_id}}" 2>/dev/null || true)"+ if [ -n "$instance" ]; then+ printf '%s\n' "$instance"+ return 0+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ return 1+}+policy_refs() {kctl get networkpolicy -A -l "$1" \-o go-template='{{range .items}}{{.metadata.namespace}}/{{.metadata.name}}{{"\n"}}{{end}}' \@@ -214,18 +231,26 @@ fiok "Fixture has no egressBindings shortcut"header "Phase 2 - WRC reconciliation"-wait_for_deployment "$SANDBOX_NS" "$SOURCE_ID" "$TIMEOUT_POD" && ok "Source deployment ready" || {+SOURCE_DEPLOYMENT="$(wait_for_workload_instance "$SOURCE_ID" "$TIMEOUT_POD")" || {+ fail "Source workload instance was not assigned"+ exit 1+}+BACKEND_DEPLOYMENT="$(wait_for_workload_instance "$BACKEND_ID" "$TIMEOUT_POD")" || {+ fail "Backend workload instance was not assigned"+ exit 1+}+wait_for_deployment "$SANDBOX_NS" "$SOURCE_DEPLOYMENT" "$TIMEOUT_POD" && ok "Source deployment ready" || {fail "Source deployment not ready"exit 1}-wait_for_deployment "$SANDBOX_NS" "$BACKEND_ID" "$TIMEOUT_POD" && ok "Backend deployment ready" || {+wait_for_deployment "$SANDBOX_NS" "$BACKEND_DEPLOYMENT" "$TIMEOUT_POD" && ok "Backend deployment ready" || {fail "Backend deployment not ready"exit 1}wait_internal_ready "$TIMEOUT_POD"-resolved_target="$(kctl exec "deploy/${SOURCE_ID}" -n "$SANDBOX_NS" -- printenv TARGET_URL 2>/dev/null || true)"-expected_target="http://${BACKEND_ID}.${SANDBOX_NS}.svc.cluster.local:${BACKEND_PORT}/"+resolved_target="$(kctl exec "deploy/${SOURCE_DEPLOYMENT}" -n "$SANDBOX_NS" -- printenv TARGET_URL 2>/dev/null || true)"+expected_target="http://${BACKEND_DEPLOYMENT}.${SANDBOX_NS}.svc.cluster.local:${BACKEND_PORT}/"[ "$resolved_target" = "$expected_target" ] && ok "TARGET_URL resolved to ${resolved_target}" || {fail "TARGET_URL resolved to '${resolved_target}', expected '${expected_target}'"exit 1@@ -240,7 +265,7 @@ assert_policy "$egress_ref" "egress" "$SOURCE_ID" "$BACKEND_ID"assert_policy "$ingress_ref" "ingress" "$BACKEND_ID" "$SOURCE_ID"header "Phase 4 - Positive packet flow"-positive_output="$(kctl exec "deploy/${SOURCE_ID}" -n "$SANDBOX_NS" -- \+positive_output="$(kctl exec "deploy/${SOURCE_DEPLOYMENT}" -n "$SANDBOX_NS" -- \sh -c 'wget -qO- --timeout='"$CONNECT_TIMEOUT"' --tries=1 "$TARGET_URL"' 2>/dev/null || true)"printf "%s" "$positive_output" | grep -Fq "issue485-ok" && \ok "WRC source reached backend through inferred internal dependency" || {@@ -282,7 +307,7 @@ wait_for_pod "$SANDBOX_NS" "run=${DENIED_POD}" 60 && ok "Unlabeled negative pod}if kctl exec "$DENIED_POD" -n "$SANDBOX_NS" -- wget -qO- \--timeout="$CONNECT_TIMEOUT" --tries=1 \- "http://${BACKEND_ID}.${SANDBOX_NS}.svc.cluster.local:${BACKEND_PORT}/" >/dev/null 2>&1; then+ "http://${BACKEND_DEPLOYMENT}.${SANDBOX_NS}.svc.cluster.local:${BACKEND_PORT}/" >/dev/null 2>&1; thenfail "Unlabeled pod reached backend; policy is too broad or NetworkPolicy is not enforced"exit 1fidiff --git a/scripts/tests/test-wrc-internal-dependency-networkpolicy-gate.sh b/scripts/tests/test-wrc-internal-dependency-networkpolicy-gate.shnew file mode 100755index 000000000..98f9a9177--- /dev/null+++ b/scripts/tests/test-wrc-internal-dependency-networkpolicy-gate.sh@@ -0,0 +1,33 @@+#!/usr/bin/env bash+set -u++ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"+GATE="${ROOT}/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh"+FAIL=0++pass() { echo "PASS: $1"; }+fail() { echo "FAIL: $1"; FAIL=1; }++if bash -n "$GATE"; then+ pass "WRC internal-dependency gate has valid bash syntax"+else+ fail "WRC internal-dependency gate has invalid bash syntax"+fi++# WRC persists its generated workload resource names in status before+# materializing workloads. The gate must use that public CRD contract rather+# than assuming a workload ID is also a Deployment or Service name.+# shellcheck disable=SC2016+if grep -Fq 'wait_for_workload_instance() {' "$GATE" &&+ grep -Fq 'SOURCE_DEPLOYMENT="$(wait_for_workload_instance "$SOURCE_ID"' "$GATE" &&+ grep -Fq 'BACKEND_DEPLOYMENT="$(wait_for_workload_instance "$BACKEND_ID"' "$GATE" &&+ ! grep -Fq 'wait_for_deployment "$SANDBOX_NS" "$SOURCE_ID"' "$GATE" &&+ ! grep -Fq 'wait_for_deployment "$SANDBOX_NS" "$BACKEND_ID"' "$GATE" &&+ grep -Fq 'deploy/${SOURCE_DEPLOYMENT}' "$GATE" &&+ grep -Fq '${BACKEND_DEPLOYMENT}.${SANDBOX_NS}.svc.cluster.local' "$GATE"; then+ pass "WRC gate resolves persisted workload instances before runtime assertions"+else+ fail "WRC gate assumes raw workload IDs are runtime resource names"+fi++exit "$FAIL"