Skip to content

Commit

Permalink
feature: add event logging related with abnormal pod to help debug ci
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseStutler committed Nov 13, 2024
1 parent 8b2f918 commit 2a4c71e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/e2e/util/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/onsi/ginkgo/v2"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit 2a4c71e

Please sign in to comment.