Skip to content

Commit ae870ea

Browse files
astefanuttiopenshift-merge-robot
authored andcommitted
test: Add defered troubleshooting logs
1 parent 0c4e2ae commit ae870ea

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

test/e2e/mnist_pytorch_mcad_job_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,17 @@ torchvision==0.12.0
182182
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutMedium).
183183
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive)))
184184

185+
defer troubleshooting(test, job)
186+
185187
test.T().Logf("Waiting for Job %s/%s to complete successfully", job.Namespace, job.Name)
186-
test.Eventually(Job(test, namespace, job.Name), TestTimeoutLong).
188+
test.Eventually(Job(test, job.Namespace, job.Name), TestTimeoutLong).
187189
Should(WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)))
188190

189191
// Refresh the job to get the generated pod selector
190-
job = GetJob(test, namespace, job.Name)
192+
job = GetJob(test, job.Namespace, job.Name)
191193

192194
// Get the job Pod
193-
pods := GetPods(test, namespace, metav1.ListOptions{
195+
pods := GetPods(test, job.Namespace, metav1.ListOptions{
194196
LabelSelector: labels.FormatLabels(job.Spec.Selector.MatchLabels)},
195197
)
196198
test.Expect(pods).To(HaveLen(1))
@@ -199,3 +201,25 @@ torchvision==0.12.0
199201
test.T().Logf("Printing Job %s/%s logs", job.Namespace, job.Name)
200202
test.T().Log(GetPodLogs(test, &pods[0], corev1.PodLogOptions{}))
201203
}
204+
205+
func troubleshooting(test Test, job *batchv1.Job) {
206+
if !test.T().Failed() {
207+
return
208+
}
209+
job = GetJob(test, job.Namespace, job.Name)
210+
211+
test.T().Errorf("Job %s/%s hasn't completed in time: %s", job.Namespace, job.Name, job)
212+
213+
pods := GetPods(test, job.Namespace, metav1.ListOptions{
214+
LabelSelector: labels.FormatLabels(job.Spec.Selector.MatchLabels)},
215+
)
216+
217+
if len(pods) == 0 {
218+
test.T().Errorf("Job %s/%s has no pods scheduled", job.Namespace, job.Name)
219+
} else {
220+
for i, pod := range pods {
221+
test.T().Logf("Printing Pod %s/%s logs", pod.Namespace, pod.Name)
222+
test.T().Log(GetPodLogs(test, &pods[i], corev1.PodLogOptions{}))
223+
}
224+
}
225+
}

test/support/batch.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ import (
2020
"github.com/onsi/gomega"
2121

2222
batchv1 "k8s.io/api/batch/v1"
23-
corev1 "k8s.io/api/core/v1"
2423
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2524
)
2625

27-
func Job(t Test, namespace *corev1.Namespace, name string) func(g gomega.Gomega) *batchv1.Job {
26+
func Job(t Test, namespace, name string) func(g gomega.Gomega) *batchv1.Job {
2827
return func(g gomega.Gomega) *batchv1.Job {
29-
job, err := t.Client().Core().BatchV1().Jobs(namespace.Name).Get(t.Ctx(), name, metav1.GetOptions{})
28+
job, err := t.Client().Core().BatchV1().Jobs(namespace).Get(t.Ctx(), name, metav1.GetOptions{})
3029
g.Expect(err).NotTo(gomega.HaveOccurred())
3130
return job
3231
}
3332
}
3433

35-
func GetJob(t Test, namespace *corev1.Namespace, name string) *batchv1.Job {
34+
func GetJob(t Test, namespace, name string) *batchv1.Job {
3635
t.T().Helper()
3736
return Job(t, namespace, name)(t)
3837
}

test/support/core.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func Raw(t Test, obj runtime.Object) runtime.RawExtension {
3636
}
3737
}
3838

39-
func GetPods(t Test, namespace *corev1.Namespace, options metav1.ListOptions) []corev1.Pod {
39+
func GetPods(t Test, namespace string, options metav1.ListOptions) []corev1.Pod {
4040
t.T().Helper()
41-
pods, err := t.Client().Core().CoreV1().Pods(namespace.Name).List(t.Ctx(), options)
41+
pods, err := t.Client().Core().CoreV1().Pods(namespace).List(t.Ctx(), options)
4242
t.Expect(err).NotTo(gomega.HaveOccurred())
4343
return pods.Items
4444
}

0 commit comments

Comments
 (0)