Skip to content

Commit abc1f8f

Browse files
committed
feat: Adds e2e test script
Signed-off-by: Daneyon Hansen <[email protected]>
1 parent 056adfd commit abc1f8f

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

hack/test-e2e.sh

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Determine the directory of this script and build an absolute path to client.yaml.
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
CLIENT_YAML="$SCRIPT_DIR/../test/testdata/client.yaml"
7+
8+
# TIME is the amount of time, in seconds, to run the test.
9+
TIME=${TIME:-1}
10+
# Optionally use a client curl pod for executing the curl command.
11+
CURL_POD=${CURL_POD:-false}
12+
13+
check_resource_exists() {
14+
local type=$1
15+
local name=$2
16+
local namespace=$3
17+
18+
if kubectl get "$type" "$name" -n "$namespace" &>/dev/null; then
19+
return 0
20+
else
21+
return 1
22+
fi
23+
}
24+
25+
check_pod_ready() {
26+
local pod_name=$1
27+
local namespace=$2
28+
# Check the Ready condition using jsonpath. Default to False if not found.
29+
local ready_status
30+
ready_status=$(kubectl get pod "$pod_name" -n "$namespace" -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' 2>/dev/null || echo "False")
31+
if [[ "$ready_status" == "True" ]]; then
32+
return 0
33+
else
34+
return 1
35+
fi
36+
}
37+
38+
# Try to get the Gateway's IP and the port from the listener named "llm-gw" if it exists.
39+
if check_resource_exists "gateway" "inference-gateway" "default"; then
40+
GATEWAY_IP=$(kubectl get gateway inference-gateway -n default -o jsonpath='{.status.addresses[0].value}')
41+
# Use JSONPath to select the port from the listener with name "llm-gw"
42+
GATEWAY_PORT=$(kubectl get gateway inference-gateway -n default -o jsonpath='{.spec.listeners[?(@.name=="llm-gw")].port}')
43+
else
44+
GATEWAY_IP=""
45+
GATEWAY_PORT=""
46+
fi
47+
48+
if [[ -n "$GATEWAY_IP" && -n "$GATEWAY_PORT" ]]; then
49+
echo "Using Gateway inference-gateway IP and port from listener 'llm-gw'."
50+
IP=${IP:-$GATEWAY_IP}
51+
PORT=${PORT:-$GATEWAY_PORT}
52+
else
53+
echo "Gateway inference-gateway not found or missing IP/port. Falling back to Envoy service."
54+
# Ensure the Envoy service exists.
55+
if ! check_resource_exists "svc" "envoy" "default"; then
56+
echo "Error: Envoy service not found in namespace 'default'."
57+
exit 1
58+
fi
59+
IP=${IP:-$(kubectl get svc envoy -n default -o jsonpath='{.spec.clusterIP}')}
60+
PORT=${PORT:-$(kubectl get svc envoy -n default -o jsonpath='{.spec.ports[0].port}')}
61+
fi
62+
63+
# Optionally verify that the curl pod exists and is ready.
64+
if [[ "$CURL_POD" == "true" ]]; then
65+
if ! check_resource_exists "pod" "curl" "default"; then
66+
echo "Pod 'curl' not found in namespace 'default'. Applying client.yaml from $CLIENT_YAML..."
67+
kubectl apply -f "$CLIENT_YAML"
68+
fi
69+
echo "Waiting for pod 'curl' to be ready..."
70+
# Retry every 5 seconds for up to 30 seconds (6 attempts)
71+
for i in {1..6}; do
72+
if check_pod_ready "curl" "default"; then
73+
echo "Pod 'curl' is now ready."
74+
break
75+
fi
76+
echo "Retry attempt $i: Pod 'curl' not ready; waiting 5 seconds..."
77+
sleep 5
78+
done
79+
80+
if ! check_pod_ready "curl" "default"; then
81+
echo "Error: Pod 'curl' is still not ready in namespace 'default' after 30 seconds."
82+
exit 1
83+
fi
84+
fi
85+
86+
# Validate that we have a non-empty IP and PORT.
87+
if [[ -z "$IP" ]]; then
88+
echo "Error: Unable to determine a valid IP from either Gateway or Envoy service."
89+
exit 1
90+
fi
91+
92+
if [[ -z "$PORT" ]]; then
93+
echo "Error: Unable to determine a valid port from either Gateway or Envoy service."
94+
exit 1
95+
fi
96+
97+
echo "Using IP: $IP"
98+
echo "Using PORT: $PORT"
99+
100+
# Run the test for the specified duration.
101+
end=$((SECONDS + TIME))
102+
if [[ "$CURL_POD" == "true" ]]; then
103+
while [ $SECONDS -lt $end ]; do
104+
kubectl exec po/curl -- curl -i "$IP:$PORT/v1/completions" \
105+
-H 'Content-Type: application/json' \
106+
-d '{"model": "tweet-summary","prompt": "Write as if you were a critic: San Francisco","max_tokens": 100,"temperature": 0}'
107+
sleep 5
108+
done
109+
else
110+
while [ $SECONDS -lt $end ]; do
111+
curl -i "$IP:$PORT/v1/completions" \
112+
-H 'Content-Type: application/json' \
113+
-d '{"model": "tweet-summary","prompt": "Write as if you were a critic: San Francisco","max_tokens": 100,"temperature": 0}'
114+
sleep 5
115+
done
116+
fi

0 commit comments

Comments
 (0)