@@ -17,6 +17,7 @@ GATEWAY_SERVICE="nantian-gw-$GATEWAY_NAME"
1717SMOKE_CLIENT_POD=" smoke-client"
1818SMOKE_CLIENT_IMAGE=" ${SMOKE_CLIENT_IMAGE:- curlimages/ curl: 8.16.0} "
1919SMOKE_URL=" http://${GATEWAY_SERVICE} .${CONTROL_PLANE_NS} .svc.cluster.local/echo"
20+ BACKEND_DIRECT_URL=" http://echo.${TEST_NS} .svc.cluster.local/echo"
2021ECHO_PORT=8080
2122TIMEOUT=" ${TIMEOUT:- 180} "
2223KIND_CONFIG=" ${KIND_CONFIG:- $GATEWAY_ROOT / scripts/ ci/ kind-ci-config.yaml} "
@@ -50,6 +51,65 @@ trim_response_detail() {
5051 printf ' %.240s' " $value "
5152}
5253
54+ probe_from_smoke_client () {
55+ local url=" $1 "
56+ local request_timeout=" $2 "
57+ local mode=" ${3:- plain} "
58+
59+ kubectl exec -n " $TEST_NS " " $SMOKE_CLIENT_POD " -- \
60+ sh -c '
61+ body_file=/tmp/smoke-response-body.txt
62+ rm -f "$body_file"
63+
64+ curl_flags=""
65+ if [ "$3" = "insecure" ]; then
66+ curl_flags="-k"
67+ fi
68+
69+ if ! status="$(curl -sS ${curl_flags} --connect-timeout "$1" --max-time "$1" \
70+ -o "$body_file" -w "%{http_code}" "$2")"; then
71+ rc=$?
72+ printf "__CURL_EXIT__%s\n" "$rc"
73+ [ -f "$body_file" ] && cat "$body_file"
74+ exit "$rc"
75+ fi
76+
77+ printf "__STATUS__%s\n" "$status"
78+ cat "$body_file"
79+ ' sh " $request_timeout " " $url " " $mode " 2>&1
80+ }
81+
82+ probe_output_code () {
83+ printf ' %s\n' " $1 " | awk ' NR == 1 {sub(/^__STATUS__/, "", $0); print; exit}'
84+ }
85+
86+ probe_output_body () {
87+ printf ' %s\n' " $1 " | tail -n +2
88+ }
89+
90+ probe_and_capture () {
91+ local url=" $1 "
92+ local request_timeout=" $2 "
93+ local mode=" $3 "
94+ local -n code_ref=" $4 "
95+ local -n body_ref=" $5 "
96+ local -n error_ref=" $6 "
97+ local output=" "
98+
99+ code_ref=" "
100+ body_ref=" "
101+ error_ref=" "
102+
103+ if ! output=" $( probe_from_smoke_client " $url " " $request_timeout " " $mode " ) " ; then
104+ error_ref=" $output "
105+ return 1
106+ fi
107+
108+ code_ref=" $( probe_output_code " $output " ) "
109+ body_ref=" $( probe_output_body " $output " ) "
110+ return 0
111+ }
112+
53113fail () {
54114 red " FAIL: $* "
55115 FAILED=true
@@ -281,6 +341,14 @@ send_request() {
281341 local last_request_error=" "
282342 local last_response_code=" "
283343 local last_response_body=" "
344+ local https_fallback_url=" https://${GATEWAY_SERVICE} .${CONTROL_PLANE_NS} .svc.cluster.local/echo"
345+ local backend_direct_url=" $BACKEND_DIRECT_URL "
346+ local last_https_fallback_error=" "
347+ local last_https_fallback_code=" "
348+ local last_https_fallback_body=" "
349+ local last_backend_direct_error=" "
350+ local last_backend_direct_code=" "
351+ local last_backend_direct_body=" "
284352 local output=" "
285353 local response_code=" "
286354 local response_body=" "
@@ -325,6 +393,22 @@ send_request() {
325393 sleep 2
326394 done
327395
396+ probe_and_capture \
397+ " $https_fallback_url " \
398+ " $request_timeout " \
399+ insecure \
400+ last_https_fallback_code \
401+ last_https_fallback_body \
402+ last_https_fallback_error || true
403+
404+ probe_and_capture \
405+ " $backend_direct_url " \
406+ " $request_timeout " \
407+ plain \
408+ last_backend_direct_code \
409+ last_backend_direct_body \
410+ last_backend_direct_error || true
411+
328412 local detail=" "
329413 if [[ -n " $last_request_error " ]]; then
330414 detail=$' \n last request error: ' " $last_request_error "
@@ -335,6 +419,24 @@ send_request() {
335419 if [[ -n " $last_response_body " ]]; then
336420 detail+=$' \n last response body: ' " $( trim_response_detail " $last_response_body " ) "
337421 fi
422+ if [[ -n " $last_https_fallback_error " ]]; then
423+ detail+=$' \n last https fallback error: ' " $( trim_response_detail " $last_https_fallback_error " ) "
424+ fi
425+ if [[ -n " $last_https_fallback_code " ]]; then
426+ detail+=$' \n last https fallback code: ' " $last_https_fallback_code "
427+ fi
428+ if [[ -n " $last_https_fallback_body " ]]; then
429+ detail+=$' \n last https fallback body: ' " $( trim_response_detail " $last_https_fallback_body " ) "
430+ fi
431+ if [[ -n " $last_backend_direct_error " ]]; then
432+ detail+=$' \n last backend direct error: ' " $( trim_response_detail " $last_backend_direct_error " ) "
433+ fi
434+ if [[ -n " $last_backend_direct_code " ]]; then
435+ detail+=$' \n last backend direct code: ' " $last_backend_direct_code "
436+ fi
437+ if [[ -n " $last_backend_direct_body " ]]; then
438+ detail+=$' \n last backend direct body: ' " $( trim_response_detail " $last_backend_direct_body " ) "
439+ fi
338440
339441 fail " GET /echo via $GATEWAY_SERVICE did not succeed within ${TIMEOUT} s${detail} "
340442 return 1
0 commit comments