Skip to content

Commit 5c4071c

Browse files
authored
Merge pull request kubernetes#130649 from natasha41575/pod-conditions-scheduler
[FG:PodObservedGenerationTracking] scheduler sets observedGeneration on pod conditions
2 parents ab3cec0 + 1889e0c commit 5c4071c

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

pkg/scheduler/framework/preemption/preemption.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,11 @@ func NewEvaluator(pluginName string, fh framework.Handle, i Interface, enableAsy
171171
logger.V(2).Info("Preemptor pod rejected a waiting pod", "preemptor", klog.KObj(preemptor), "waitingPod", klog.KObj(victim), "node", c.Name())
172172
} else {
173173
condition := &v1.PodCondition{
174-
Type: v1.DisruptionTarget,
175-
Status: v1.ConditionTrue,
176-
Reason: v1.PodReasonPreemptionByScheduler,
177-
Message: fmt.Sprintf("%s: preempting to accommodate a higher priority pod", preemptor.Spec.SchedulerName),
174+
Type: v1.DisruptionTarget,
175+
ObservedGeneration: apipod.GetPodObservedGenerationIfEnabledOnCondition(&victim.Status, victim.Generation, v1.DisruptionTarget),
176+
Status: v1.ConditionTrue,
177+
Reason: v1.PodReasonPreemptionByScheduler,
178+
Message: fmt.Sprintf("%s: preempting to accommodate a higher priority pod", preemptor.Spec.SchedulerName),
178179
}
179180
newStatus := victim.Status.DeepCopy()
180181
updated := apipod.UpdatePodCondition(newStatus, condition)

pkg/scheduler/schedule_one.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,11 @@ func (sched *Scheduler) handleSchedulingFailure(ctx context.Context, fwk framewo
10971097
msg := truncateMessage(errMsg)
10981098
fwk.EventRecorder().Eventf(pod, nil, v1.EventTypeWarning, "FailedScheduling", "Scheduling", msg)
10991099
if err := updatePod(ctx, sched.client, pod, &v1.PodCondition{
1100-
Type: v1.PodScheduled,
1101-
Status: v1.ConditionFalse,
1102-
Reason: reason,
1103-
Message: errMsg,
1100+
Type: v1.PodScheduled,
1101+
ObservedGeneration: podutil.GetPodObservedGenerationIfEnabledOnCondition(&pod.Status, pod.Generation, v1.PodScheduled),
1102+
Status: v1.ConditionFalse,
1103+
Reason: reason,
1104+
Message: errMsg,
11041105
}, nominatingInfo); err != nil {
11051106
logger.Error(err, "Error updating pod", "pod", klog.KObj(pod))
11061107
}

test/e2e/node/pods.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ var _ = SIGDescribe("Pods Extended (pod generation)", feature.PodObservedGenerat
529529
}
530530
})
531531

532-
ginkgo.It("custom-set generation on new pods should be overwritten to 1", func(ctx context.Context) {
532+
ginkgo.It("custom-set generation on new pods and graceful delete", func(ctx context.Context) {
533533
ginkgo.By("creating the pod")
534534
name := "pod-generation-" + string(uuid.NewUUID())
535535
value := strconv.Itoa(time.Now().Nanosecond())
@@ -598,6 +598,10 @@ var _ = SIGDescribe("Pods Extended (pod generation)", feature.PodObservedGenerat
598598
gomega.Expect(pod.Generation).To(gomega.BeEquivalentTo(expectedPodGeneration))
599599
})
600600

601+
// This is the same test as https://github.com/kubernetes/kubernetes/blob/aa08c90fca8d30038d3f05c0e8f127b540b40289/test/e2e/node/pod_admission.go#L35,
602+
// except that this verifies the pod generation and observedGeneration, which is
603+
// currently behind a feature gate. When we GA observedGeneration functionality,
604+
// we can fold these tests together into one.
601605
ginkgo.It("pod rejected by kubelet should have updated generation and observedGeneration", func(ctx context.Context) {
602606
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
603607
framework.ExpectNoError(err, "Failed to get a ready schedulable node")
@@ -631,6 +635,18 @@ var _ = SIGDescribe("Pods Extended (pod generation)", feature.PodObservedGenerat
631635
return podClient.Delete(ctx, pod.Name, metav1.DeleteOptions{})
632636
})
633637

638+
// Wait for the scheduler to update the pod status
639+
err = e2epod.WaitForPodNameUnschedulableInNamespace(ctx, f.ClientSet, pod.Name, pod.Namespace)
640+
framework.ExpectNoError(err)
641+
642+
// Fetch the pod to verify that the scheduler has set the PodScheduled condition
643+
// with observedGeneration.
644+
pod, err = podClient.Get(ctx, pod.Name, metav1.GetOptions{})
645+
framework.ExpectNoError(err)
646+
gomega.Expect(len(pod.Status.Conditions)).To(gomega.BeEquivalentTo(1))
647+
gomega.Expect(pod.Status.Conditions[0].Type).To(gomega.BeEquivalentTo(v1.PodScheduled))
648+
gomega.Expect(pod.Status.Conditions[0].ObservedGeneration).To(gomega.BeEquivalentTo(1))
649+
634650
// Force assign the Pod to a node in order to get rejection status.
635651
binding := &v1.Binding{
636652
ObjectMeta: metav1.ObjectMeta{
@@ -650,7 +666,7 @@ var _ = SIGDescribe("Pods Extended (pod generation)", feature.PodObservedGenerat
650666
framework.ExpectNoError(err)
651667

652668
// Fetch the rejected Pod and verify the generation and observedGeneration.
653-
gotPod, err := f.ClientSet.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{})
669+
gotPod, err := podClient.Get(ctx, pod.Name, metav1.GetOptions{})
654670
framework.ExpectNoError(err)
655671
gomega.Expect(gotPod.Generation).To(gomega.BeEquivalentTo(1))
656672
gomega.Expect(gotPod.Status.ObservedGeneration).To(gomega.BeEquivalentTo(1))

0 commit comments

Comments
 (0)