Skip to content

Commit 52ae8b1

Browse files
authored
Merge pull request kubernetes#91099 from snowplayfire/skip_unnecessary_scheduling
skip unnecessary scheduling attempt when pod has its Finalizers updated
2 parents 6b6945b + b95191f commit 52ae8b1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pkg/scheduler/eventhandlers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func responsibleForPod(pod *v1.Pod, profiles profile.Map) bool {
306306
// skipPodUpdate checks whether the specified pod update should be ignored.
307307
// This function will return true if
308308
// - The pod has already been assumed, AND
309-
// - The pod has only its ResourceVersion, Spec.NodeName and/or Annotations
309+
// - The pod has only its ResourceVersion, Spec.NodeName, Annotations, ManagedFields and/or Finalizers
310310
// updated.
311311
func (sched *Scheduler) skipPodUpdate(pod *v1.Pod) bool {
312312
// Non-assumed pods should never be skipped.
@@ -343,6 +343,8 @@ func (sched *Scheduler) skipPodUpdate(pod *v1.Pod) bool {
343343
// Same as above, when annotations are modified with ServerSideApply,
344344
// ManagedFields may also change and must be excluded
345345
p.ManagedFields = nil
346+
// Finalizers must be excluded because scheduled result can not be affected
347+
p.Finalizers = nil
346348
return p
347349
}
348350
assumedPodCopy, podCopy := f(assumedPod), f(pod)

pkg/scheduler/eventhandlers_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,27 @@ func TestSkipPodUpdate(t *testing.T) {
183183
},
184184
expected: false,
185185
},
186+
{
187+
name: "with changes on Finalizers",
188+
pod: &v1.Pod{
189+
ObjectMeta: metav1.ObjectMeta{
190+
Name: "pod-0",
191+
Finalizers: []string{"a", "b"},
192+
},
193+
},
194+
isAssumedPodFunc: func(*v1.Pod) bool {
195+
return true
196+
},
197+
getPodFunc: func(*v1.Pod) *v1.Pod {
198+
return &v1.Pod{
199+
ObjectMeta: metav1.ObjectMeta{
200+
Name: "pod-0",
201+
Finalizers: []string{"c", "d"},
202+
},
203+
}
204+
},
205+
expected: true,
206+
},
186207
} {
187208
t.Run(test.name, func(t *testing.T) {
188209
c := &Scheduler{

0 commit comments

Comments
 (0)