From 2a4c71ecdf3c3465c7c50827cf7715c0a436bd6d Mon Sep 17 00:00:00 2001 From: JesseStutler Date: Wed, 13 Nov 2024 17:05:09 +0800 Subject: [PATCH] feature: add event logging related with abnormal pod to help debug ci --- test/e2e/util/job.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/e2e/util/job.go b/test/e2e/util/job.go index 4fbabca000..acd8b1e366 100644 --- a/test/e2e/util/job.go +++ b/test/e2e/util/job.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/onsi/ginkgo/v2" "strconv" "strings" "time" @@ -289,6 +290,16 @@ func WaitTaskPhase(ctx *TestContext, job *batchv1alpha1.Job, phase []v1.PodPhase if pod.Status.Phase == p { readyTaskNum++ break + } else { + fmt.Fprintf(ginkgo.GinkgoWriter, "The pod <%s/%s> is not in %s phase", pod.Namespace, pod.Name, p) + fieldSelector := fmt.Sprintf("involvedObject.kind=Pod,involvedObject.name=%s,reason=Failed", pod.Name) + events, err := ctx.Kubeclient.CoreV1().Events(pod.Namespace).List(context.TODO(), metav1.ListOptions{ + FieldSelector: fieldSelector, + }) + Expect(err).NotTo(HaveOccurred(), "failed to get events related with pod %s in namespace %s", pod.Name, pod.Namespace) + for _, event := range events.Items { + fmt.Fprintf(ginkgo.GinkgoWriter, "Event related with pod <%s/%s>: %s - %s\n", pod.Namespace, pod.Name, event.Reason, event.Message) + } } } }