Skip to content

Commit

Permalink
Temporary code to dump extract job logs upon timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Zvi Cahana <[email protected]>
  • Loading branch information
zcahana committed Jun 30, 2021
1 parent 446a8cc commit 35a8c4b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/e2e/bundle_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ var _ = Describe("Launch bundle", func() {
}
case <-time.After(120 * time.Second):
Logf("Timeout waiting for job to complete")
dumpJobDebugInfo(kubeclient, job)
done <- struct{}{}
}
}
Expand Down Expand Up @@ -223,6 +224,45 @@ var _ = Describe("Launch bundle", func() {
})
})

func dumpJobDebugInfo(kubeclient kubernetes.Interface, job *batchv1.Job) {

podSelector := fmt.Sprintf("job-name=%s", job.Name)
pods, err := kubeclient.CoreV1().Pods(job.Namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: podSelector})
if err != nil {
Logf("Failed listing pods with job selector %s: %v", podSelector, err)
return
}
if len(pods.Items) == 0 {
Logf("No job pods found using selector %s", podSelector)
return
}

Logf("Found %d pods matching job selector %s", len(pods.Items), podSelector)

for _, pod := range pods.Items {
Logf("Fetching pod logs for %s", pod.Name)
req := kubeclient.CoreV1().Pods(job.Namespace).GetLogs(pod.Name, &corev1.PodLogOptions{
Container: "bundle-image",
})

res := req.Do(context.TODO())
if res.Error() != nil {
Logf("Error fetching pod logs for %s: %v", pod.Name, err)
continue
}

logBytes, err := res.Raw()
if err != nil {
Logf("Error fetching pod logs for %s: %v", pod.Name, err)
continue
}

fmt.Println("##################################################################################")
fmt.Println(string(logBytes))
fmt.Println("##################################################################################")
}
}

var kindControlPlaneNodeNameRegex = regexp.MustCompile("^kind-.*-control-plane$|^kind-control-plane$")

func isKindCluster(client *kubernetes.Clientset) (bool, string, error) {
Expand Down

0 comments on commit 35a8c4b

Please sign in to comment.