|
118 | 118 | # Cleanup: Delete the applied manifests |
119 | 119 | kubectl delete --ignore-not-found -f "$BATS_TEST_DIRNAME"/../examples/gateway_httproute_simple.yaml |
120 | 120 | } |
| 121 | + |
| 122 | + |
| 123 | +@test "Ingress to Gateway Migration and X-Forwarded-For Header" { |
| 124 | + # Apply the Gateway and HTTPRoute manifests |
| 125 | + kubectl apply -f "$BATS_TEST_DIRNAME"/../examples/ingress_foo_bar.yaml |
| 126 | + |
| 127 | + # Wait for the backend application pod to be ready |
| 128 | + kubectl wait --for=condition=ready pods -l app=foo --timeout=60s |
| 129 | + kubectl wait --for=condition=ready pods -l app=foo --timeout=60s |
| 130 | + |
| 131 | + # Give the controller time to reconcile |
| 132 | + echo "Waiting for reconciliation..." |
| 133 | + sleep 5 |
| 134 | + |
| 135 | + echo "Finding Ingress Loadbalancer IP ..." |
| 136 | + run kubectl get ingress example-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}' |
| 137 | + [ "$status" -eq 0 ] |
| 138 | + export INGRESS_SVC_IP="$output" |
| 139 | + echo "Ingress LoadBalancer IP: $INGRESS_SVC_IP" |
| 140 | + |
| 141 | + # Test /foo prefix |
| 142 | + echo "Testing /foo prefix (should match foo-app)..." |
| 143 | + run kubectl exec curl-pod -- curl -H "Host: foo.example.com" -s "http://$INGRESS_SVC_IP/hostname" |
| 144 | + [ "$status" -eq 0 ] |
| 145 | + [[ "$output" == "foo-app" ]] |
| 146 | + |
| 147 | + # Test /bar prefix |
| 148 | + echo "Testing /bar prefix (should match bar-app)..." |
| 149 | + run kubectl exec curl-pod -- curl -H "Host: bar.example.com" -s "http://$INGRESS_SVC_IP/hostname" |
| 150 | + [ "$status" -eq 0 ] |
| 151 | + [[ "$output" == "bar-app" ]] |
| 152 | + |
| 153 | + # Test X-Forwarded-For header |
| 154 | + echo "Testing X-Forwarded-For header..." |
| 155 | + run kubectl exec curl-pod -- curl -H "Host: foo.example.com" -s "http://$INGRESS_SVC_IP/header?key=X-Forwarded-For" |
| 156 | + [ "$status" -eq 0 ] |
| 157 | + echo "X-Forwarded-For header value: $output" |
| 158 | + [[ ! -z "$output" ]] |
| 159 | + |
| 160 | + # Cleanup: Delete the applied manifests |
| 161 | + kubectl delete --ignore-not-found -f "$BATS_TEST_DIRNAME"/../examples/ingress_foo_bar.yaml |
| 162 | +} |
0 commit comments