Skip to content

Commit 1390195

Browse files
committed
update
Signed-off-by: bitliu <[email protected]>
1 parent 4396721 commit 1390195

File tree

1 file changed

+71
-3
lines changed

1 file changed

+71
-3
lines changed

e2e/profiles/ai-gateway/testcases.go

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,23 @@ func testChatCompletionsRequest(ctx context.Context, client *kubernetes.Clientse
7272
for {
7373
envoyService, err = getEnvoyServiceName(ctx, opts.Verbose)
7474
if err == nil {
75-
break
75+
// Verify that at least one pod is running for this service
76+
podErr := verifyServicePodsRunning(ctx, client, "envoy-gateway-system", envoyService, opts.Verbose)
77+
if podErr == nil {
78+
break
79+
}
80+
if opts.Verbose {
81+
fmt.Printf("[Test] Envoy service found but pods not ready: %v\n", podErr)
82+
}
83+
err = fmt.Errorf("service pods not ready: %w", podErr)
7684
}
7785

7886
if time.Since(startTime) >= retryTimeout {
79-
return fmt.Errorf("failed to get Envoy service name after %v: %w", retryTimeout, err)
87+
return fmt.Errorf("failed to get Envoy service with running pods after %v: %w", retryTimeout, err)
8088
}
8189

8290
if opts.Verbose {
83-
fmt.Printf("[Test] Envoy service not found, retrying in %v... (elapsed: %v)\n",
91+
fmt.Printf("[Test] Envoy service not ready, retrying in %v... (elapsed: %v)\n",
8492
retryInterval, time.Since(startTime).Round(time.Second))
8593
}
8694

@@ -188,6 +196,66 @@ func getEnvoyServiceName(ctx context.Context, verbose bool) (string, error) {
188196
return serviceName, nil
189197
}
190198

199+
func verifyServicePodsRunning(ctx context.Context, client *kubernetes.Clientset, namespace, serviceName string, verbose bool) error {
200+
// Get the service to find its selector
201+
svc, err := client.CoreV1().Services(namespace).Get(ctx, serviceName, metav1.GetOptions{})
202+
if err != nil {
203+
return fmt.Errorf("failed to get service: %w", err)
204+
}
205+
206+
if len(svc.Spec.Selector) == 0 {
207+
return fmt.Errorf("service has no selector")
208+
}
209+
210+
// Convert selector map to label selector string
211+
var selectorParts []string
212+
for key, value := range svc.Spec.Selector {
213+
selectorParts = append(selectorParts, fmt.Sprintf("%s=%s", key, value))
214+
}
215+
labelSelector := strings.Join(selectorParts, ",")
216+
217+
// List pods matching the service selector
218+
pods, err := client.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
219+
LabelSelector: labelSelector,
220+
})
221+
if err != nil {
222+
return fmt.Errorf("failed to list pods: %w", err)
223+
}
224+
225+
if len(pods.Items) == 0 {
226+
return fmt.Errorf("no pods found for service %s", serviceName)
227+
}
228+
229+
// Check if at least one pod is running
230+
runningCount := 0
231+
for _, pod := range pods.Items {
232+
if pod.Status.Phase == "Running" {
233+
// Also check if all containers are ready
234+
allReady := true
235+
for _, containerStatus := range pod.Status.ContainerStatuses {
236+
if !containerStatus.Ready {
237+
allReady = false
238+
break
239+
}
240+
}
241+
if allReady {
242+
runningCount++
243+
}
244+
}
245+
}
246+
247+
if runningCount == 0 {
248+
return fmt.Errorf("no running pods found for service %s (total pods: %d)", serviceName, len(pods.Items))
249+
}
250+
251+
if verbose {
252+
fmt.Printf("[Test] Service %s/%s has %d running pod(s) out of %d total\n",
253+
namespace, serviceName, runningCount, len(pods.Items))
254+
}
255+
256+
return nil
257+
}
258+
191259
func startPortForward(ctx context.Context, namespace, service, ports string, verbose bool) error {
192260
cmd := exec.CommandContext(ctx, "kubectl", "port-forward",
193261
"-n", namespace,

0 commit comments

Comments
 (0)