diff --git a/.changes/unreleased/fixed-20261028-174735.yaml b/.changes/unreleased/fixed-20261028-174735.yaml new file mode 100644 index 000000000..45393cfc6 --- /dev/null +++ b/.changes/unreleased/fixed-20261028-174735.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: |- + Scheduler patches a pending pod's PodScheduled condition only when it changes, not every cycle +custom: + Author: "sam-huang1223" + Issue: "2544" diff --git a/pkg/scheduler/cache/pod_transform.go b/pkg/scheduler/cache/pod_transform.go index 1bfdc5f35..2311edb98 100644 --- a/pkg/scheduler/cache/pod_transform.go +++ b/pkg/scheduler/cache/pod_transform.go @@ -75,13 +75,16 @@ func compactContainerStatuses(statuses []v1.ContainerStatus) []v1.ContainerStatu return compact } +// compactConditions keeps PodResizePending for resize accounting and PodScheduled, which the status +// updater compares against so it patches the condition only when it changes. func compactConditions(conditions []v1.PodCondition) []v1.PodCondition { + var compact []v1.PodCondition for _, c := range conditions { - if c.Type == v1.PodResizePending { - return []v1.PodCondition{c} + if c.Type == v1.PodResizePending || c.Type == v1.PodScheduled { + compact = append(compact, c) } } - return nil + return compact } func compactContainers(containers []v1.Container) []v1.Container { diff --git a/pkg/scheduler/cache/pod_transform_test.go b/pkg/scheduler/cache/pod_transform_test.go index c60b96768..18084bd6c 100644 --- a/pkg/scheduler/cache/pod_transform_test.go +++ b/pkg/scheduler/cache/pod_transform_test.go @@ -148,5 +148,25 @@ var _ = Describe("compactSchedulerPod", func() { Expect(compact.Annotations).To(HaveLen(2)) Expect(compact.ManagedFields).To(BeNil()) }) + + It("keeps PodScheduled, which the status updater compares before patching it", func() { + pod := succeededPod() + pod.Status.Phase = v1.PodPending + unschedulable := v1.PodCondition{ + Type: v1.PodScheduled, + Status: v1.ConditionFalse, + Reason: v1.PodReasonUnschedulable, + Message: "no nodes with enough resources", + LastTransitionTime: metav1.Unix(1767323045, 0), + } + resizePending := v1.PodCondition{Type: v1.PodResizePending, Status: v1.ConditionTrue} + pod.Status.Conditions = []v1.PodCondition{unschedulable, {Type: v1.PodReady}, resizePending} + + transformed, err := compactSchedulerPod(pod) + Expect(err).NotTo(HaveOccurred()) + + compact := transformed.(*v1.Pod) + Expect(compact.Status.Conditions).To(Equal([]v1.PodCondition{unschedulable, resizePending})) + }) }) })