#!/usr/bin/env bash # T81: externalTrafficPolicy Cluster (SNAT cross-node allowed) vs Local (blackhole cross-node) set -euo pipefail NS=istio-vt-t81 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cleanup() { kubectl delete namespace "$NS" --wait=false --ignore-not-found } trap cleanup EXIT kubectl create namespace "$NS" --dry-run=client -o yaml | \ kubectl label -f - istio-injection=enabled --local -o yaml | \ kubectl apply -f - kubectl apply -f "$SCRIPT_DIR/manifest.yaml" kubectl -n "$NS" wait --for=condition=available deploy/snat-echo --timeout=60s kubectl -n "$NS" wait --for=condition=Ready pod/client --timeout=120s SNAT_NODE=$(kubectl -n "$NS" get pod -l app=snat-echo -o jsonpath="{.items[0].spec.nodeName}") TARGET_NODE_IP=$(kubectl get nodes -o jsonpath='{.items[?(@.metadata.name!="'"$SNAT_NODE"'")].status.addresses[?(@.type=="InternalIP")].address}' | awk '{print $1}') echo "target_node_without_endpoint=$TARGET_NODE_IP" curl -s -o /dev/null -w 'cluster_policy_cross_node=%{http_code}\n' --max-time 4 "http://$TARGET_NODE_IP:30880/" kubectl -n "$NS" patch svc snat-echo -p '{"spec":{"externalTrafficPolicy":"Local"}}' sleep 3 set +e curl -s -o /dev/null -w 'local_policy_cross_node=%{http_code}\n' --max-time 4 "http://$TARGET_NODE_IP:30880/" echo "exit=$?" set -e