Merge pull request #91099 from snowplayfire/skip_unnecessary_scheduling

skip unnecessary scheduling attempt when pod has its Finalizers updated
This commit is contained in:
Kubernetes Prow Robot 2020-05-15 23:02:22 -07:00 committed by GitHub
commit 52ae8b1ebb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -306,7 +306,7 @@ func responsibleForPod(pod *v1.Pod, profiles profile.Map) bool {
// skipPodUpdate checks whether the specified pod update should be ignored.
// This function will return true if
// - The pod has already been assumed, AND
// - The pod has only its ResourceVersion, Spec.NodeName and/or Annotations
// - The pod has only its ResourceVersion, Spec.NodeName, Annotations, ManagedFields and/or Finalizers
// updated.
func (sched *Scheduler) skipPodUpdate(pod *v1.Pod) bool {
// Non-assumed pods should never be skipped.
@ -343,6 +343,8 @@ func (sched *Scheduler) skipPodUpdate(pod *v1.Pod) bool {
// Same as above, when annotations are modified with ServerSideApply,
// ManagedFields may also change and must be excluded
p.ManagedFields = nil
// Finalizers must be excluded because scheduled result can not be affected
p.Finalizers = nil
return p
}
assumedPodCopy, podCopy := f(assumedPod), f(pod)

View File

@ -183,6 +183,27 @@ func TestSkipPodUpdate(t *testing.T) {
},
expected: false,
},
{
name: "with changes on Finalizers",
pod: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-0",
Finalizers: []string{"a", "b"},
},
},
isAssumedPodFunc: func(*v1.Pod) bool {
return true
},
getPodFunc: func(*v1.Pod) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-0",
Finalizers: []string{"c", "d"},
},
}
},
expected: true,
},
} {
t.Run(test.name, func(t *testing.T) {
c := &Scheduler{