Skip to content

Commit

Permalink
Added reasons to logs for unscheduled pods
Browse files Browse the repository at this point in the history
  • Loading branch information
jwalantmodi05 committed Sep 27, 2024
1 parent 8dea2dc commit 5034747
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/utils/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func CheckPodFailed(pod *corev1.Pod) error {
}

if pod.Status.Phase == corev1.PodPending {
if isPodUnschedulable, err := IsPodReasonUnschedulable(pod); isPodUnschedulable {
return fmt.Errorf("pod %s is in unschedulable state and reason is %v", pod.Name, err)
if isPodUnschedulable, reason := IsPodReasonUnschedulable(pod); isPodUnschedulable {
return fmt.Errorf("pod %s is in unschedulable state and reason is %s", pod.Name, reason)
}
}

Expand Down Expand Up @@ -202,13 +202,13 @@ func isPodError(reason string) bool {
return strings.HasSuffix(reason, "Error")
}

func IsPodReasonUnschedulable(pod *corev1.Pod) (bool, error) {
func IsPodReasonUnschedulable(pod *corev1.Pod) (isPodUnschedulable bool, reason string) {
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.PodScheduled && (condition.Reason == corev1.PodReasonUnschedulable ||
condition.Reason == corev1.PodReasonSchedulerError) {
return true, fmt.Errorf("%s", condition.Message)
return true, condition.Message
}
}

return false, nil
return false, ""
}

0 comments on commit 5034747

Please sign in to comment.