Skip to content

Commit

Permalink
[UI] Fix Trial Logs when Kubernetes Job Fails (#2164)
Browse files Browse the repository at this point in the history
* [UI] Fix Trial Logs when Kubernetes Job Fails

* Return error when Pod is in the Pending state
  • Loading branch information
andreyvelich committed Jun 20, 2023
1 parent 37b237f commit ede6e74
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/new-ui/v1beta1/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,23 @@ func fetchMasterPodName(clientset *kubernetes.Clientset, trial *trialsv1beta1.Tr
field to "true" in the Experiment definition. If this error persists then the Pod's logs are not currently
persisted in the cluster.`)
}
if len(podList.Items) > 1 {
return "", errors.New("More than one master replica found")

// If Pod is Running or Succeeded Pod, return it.
for _, pod := range podList.Items {
if pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodRunning {
return pod.Name, nil
}
}

// Otherwise, return the first Failed Pod.
for _, pod := range podList.Items {
if pod.Status.Phase == corev1.PodFailed {
return pod.Name, nil
}
}

return podList.Items[0].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
Expand Down

0 comments on commit ede6e74

Please sign in to comment.