From 94cf6af643936ad2a1abf6a31be52e7d5c221cf7 Mon Sep 17 00:00:00 2001 From: Andrey Velichkevich Date: Mon, 19 Jun 2023 23:03:33 +0100 Subject: [PATCH] Return error when Pod is in the Pending state --- pkg/new-ui/v1beta1/backend.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/new-ui/v1beta1/backend.go b/pkg/new-ui/v1beta1/backend.go index 3b6cd4c4db2..90412b657e8 100644 --- a/pkg/new-ui/v1beta1/backend.go +++ b/pkg/new-ui/v1beta1/backend.go @@ -742,7 +742,14 @@ func fetchMasterPodName(clientset *kubernetes.Clientset, trial *trialsv1beta1.Tr } // Otherwise, return the first Failed Pod. - return podList.Items[0].Name, nil + for _, pod := range podList.Items { + if pod.Status.Phase == corev1.PodFailed { + return pod.Name, nil + } + } + + // Otherwise, return error since Pod is in the Pending state. + return "", errors.New("Failed to get logs for this Trial. Pod is in the Pending or Unknown state.") } // fetchPodLogs returns logs of a pod for the given job name and namespace