Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KO-322: Added reasons to logs for unscheduled pods #315

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/controller/cluster/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ func (r *SingleClusterReconciler) getIgnorablePods(racksToDelete []asdbv1.Rack,
pod := &podList.Items[podIdx]

if !utils.IsPodRunningAndReady(pod) {
if utils.IsPodReasonUnschedulable(pod) {
if isPodUnschedulable, _ := utils.IsPodReasonUnschedulable(pod); isPodUnschedulable {
pendingPod = append(pendingPod, pod.Name)
continue
}
Expand Down
18 changes: 11 additions & 7 deletions pkg/utils/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ func CheckPodFailed(pod *corev1.Pod) error {

// if the value of ".status.phase" is "Failed", the pod is trivially in a failure state
if pod.Status.Phase == corev1.PodFailed {
return fmt.Errorf("pod %s has failed status", pod.Name)
return fmt.Errorf("pod %s has failed status with reason: %s and message: %s",
pod.Name, pod.Status.Reason, pod.Status.Message)
}

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

// grab the status of every container in the pod (including its init containers)
Expand Down Expand Up @@ -73,7 +76,8 @@ func CheckPodImageFailed(pod *corev1.Pod) error {

// if the value of ".status.phase" is "Failed", the pod is trivially in a failure state
if pod.Status.Phase == corev1.PodFailed {
return fmt.Errorf("pod has failed status")
return fmt.Errorf("pod %s has failed status with reason: %s and message: %s",
pod.Name, pod.Status.Reason, pod.Status.Message)
}

// grab the status of every container in the pod (including its init containers)
Expand Down Expand Up @@ -198,13 +202,13 @@ func isPodError(reason string) bool {
return strings.HasSuffix(reason, "Error")
}

func IsPodReasonUnschedulable(pod *corev1.Pod) bool {
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
return true, condition.Message
}
}

return false
return false, ""
}
Loading