@@ -3,7 +3,6 @@ package lib
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "strings"
7
6
"time"
8
7
9
8
api "k8s.io/api/core/v1"
@@ -242,7 +241,10 @@ func executeTests(c *kubernetes.Clientset, testParams TestParams, primaryNode, s
242
241
}
243
242
fmt .Println ("Waiting for netperf pods to start up" )
244
243
245
- orchestratorPodName := getOrchestratorPodName (c , testParams .TestNamespace )
244
+ orchestratorPodName , err := getOrchestratorPodName (c , testParams .TestNamespace , 3 * time .Minute )
245
+ if err != nil {
246
+ return nil , fmt .Errorf ("failed to get orchestrator pod name: %v" , err )
247
+ }
246
248
fmt .Println ("Orchestrator Pod is" , orchestratorPodName )
247
249
248
250
var jsonFilePath string
@@ -290,19 +292,45 @@ func executeTests(c *kubernetes.Clientset, testParams TestParams, primaryNode, s
290
292
return results , nil
291
293
}
292
294
293
- func getOrchestratorPodName (c * kubernetes.Clientset , testNamespace string ) string {
295
+ func getOrchestratorPodName (c * kubernetes.Clientset , testNamespace string , timeout time.Duration ) (string , error ) {
296
+ timeoutCh := time .After (timeout )
297
+ ticker := time .NewTicker (5 * time .Second )
298
+ defer ticker .Stop ()
299
+
294
300
for {
295
- fmt .Println ("Waiting for orchestrator pod creation" )
296
- time .Sleep (60 * time .Second )
297
- pods , err := c .CoreV1 ().Pods (testNamespace ).List (context .Background (), everythingSelector )
298
- if err != nil {
299
- fmt .Println ("Failed to fetch pods - waiting for pod creation" , err )
300
- continue
301
- }
302
- for _ , pod := range pods .Items {
303
- if strings .Contains (pod .GetName (), "netperf-orch-" ) {
304
- return pod .GetName ()
301
+ select {
302
+ case <- ticker .C :
303
+ fmt .Println ("Waiting for orchestrator pod creation" )
304
+ pods , err := c .CoreV1 ().Pods (testNamespace ).List (context .Background (), metav1.ListOptions {
305
+ LabelSelector : "app=netperf-orch" ,
306
+ })
307
+ if err != nil {
308
+ fmt .Println ("Failed to fetch pods - waiting for pod creation" , err )
309
+ continue
310
+ }
311
+ if len (pods .Items ) == 0 {
312
+ fmt .Println ("No orchestrator pods found yet" )
313
+ continue
314
+ }
315
+
316
+ pod := pods .Items [0 ]
317
+ podStatus := pod .Status
318
+
319
+ if podStatus .Phase == api .PodRunning {
320
+ return pod .GetName (), nil
321
+ }
322
+
323
+ for _ , containerStatus := range podStatus .ContainerStatuses {
324
+ if waiting := containerStatus .State .Waiting ; waiting != nil {
325
+ switch waiting .Reason {
326
+ case "ErrImagePull" , "CrashLoopBackOff" , "ImagePullBackOff" :
327
+ return "" , fmt .Errorf ("orchestrator pod error: %s - %v" , waiting .Reason , waiting .Message )
328
+ }
329
+ }
305
330
}
331
+ fmt .Println ("Orchestrator pod is not running yet" )
332
+ case <- timeoutCh :
333
+ return "" , fmt .Errorf ("timed out waiting for orchestrator pod to be created" )
306
334
}
307
335
}
308
336
}
0 commit comments