From 8eb8f8ab26d0a28cbe288d3f87bcc727ed126216 Mon Sep 17 00:00:00 2001 From: leileiwan Date: Fri, 15 Jan 2021 17:41:52 +0800 Subject: [PATCH 1/3] fix(*):inter pod affinity default min score is zero --- pkg/scheduler/framework/plugins/interpodaffinity/scoring.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go index d7d23547269..1c38daeade6 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go @@ -19,6 +19,7 @@ package interpodaffinity import ( "context" "fmt" + "math" "sync/atomic" v1 "k8s.io/api/core/v1" @@ -252,7 +253,8 @@ func (pl *InterPodAffinity) NormalizeScore(ctx context.Context, cycleState *fram return nil } - var maxCount, minCount int64 + var minCount int64 = math.MaxInt64 + var maxCount int64 for i := range scores { score := scores[i].Score if score > maxCount { From 273de36b5d224af03b7a7cb244471562b83d73d6 Mon Sep 17 00:00:00 2001 From: leileiwan Date: Mon, 18 Jan 2021 22:55:37 +0800 Subject: [PATCH 2/3] fix unit test --- .../framework/plugins/interpodaffinity/scoring_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go b/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go index 11555ae26a4..116e2d33a20 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go @@ -371,7 +371,7 @@ func TestPreferredAffinity(t *testing.T) { {ObjectMeta: metav1.ObjectMeta{Name: "machine4", Labels: labelRgChina}}, {ObjectMeta: metav1.ObjectMeta{Name: "machine5", Labels: labelRgIndia}}, }, - expectedList: []framework.NodeScore{{Name: "machine1", Score: framework.MaxNodeScore}, {Name: "machine2", Score: 50}, {Name: "machine3", Score: framework.MaxNodeScore}, {Name: "machine4", Score: framework.MaxNodeScore}, {Name: "machine5", Score: 50}}, + expectedList: []framework.NodeScore{{Name: "machine1", Score: framework.MaxNodeScore}, {Name: "machine2", Score: 0}, {Name: "machine3", Score: framework.MaxNodeScore}, {Name: "machine4", Score: framework.MaxNodeScore}, {Name: "machine5", Score: 0}}, name: "Affinity: nodes in one region has more matching pods comparing to other region, so the region which has more matches will get high score", }, // Test with the different operators and values for pod affinity scheduling preference, including some match failures. @@ -517,7 +517,7 @@ func TestPreferredAffinity(t *testing.T) { {ObjectMeta: metav1.ObjectMeta{Name: "machine4", Labels: labelRgChina}}, {ObjectMeta: metav1.ObjectMeta{Name: "machine5", Labels: labelRgIndia}}, }, - expectedList: []framework.NodeScore{{Name: "machine1", Score: framework.MaxNodeScore}, {Name: "machine2", Score: 40}, {Name: "machine3", Score: framework.MaxNodeScore}, {Name: "machine4", Score: framework.MaxNodeScore}, {Name: "machine5", Score: 40}}, + expectedList: []framework.NodeScore{{Name: "machine1", Score: framework.MaxNodeScore}, {Name: "machine2", Score: 0}, {Name: "machine3", Score: framework.MaxNodeScore}, {Name: "machine4", Score: framework.MaxNodeScore}, {Name: "machine5", Score: 0}}, name: "Affinity and Anti Affinity: considering both affinity and anti-affinity, the pod to schedule and existing pods have the same labels", }, // Consider Affinity, Anti Affinity and symmetry together. @@ -555,7 +555,7 @@ func TestPreferredAffinity(t *testing.T) { {ObjectMeta: metav1.ObjectMeta{Name: "machine1", Labels: labelRgChina}}, {ObjectMeta: metav1.ObjectMeta{Name: "machine2", Labels: labelRgChina}}, }, - expectedList: []framework.NodeScore{{Name: "machine1", Score: framework.MaxNodeScore}, {Name: "machine2", Score: framework.MaxNodeScore}}, + expectedList: []framework.NodeScore{{Name: "machine1", Score: 0}, {Name: "machine2", Score: 0}}, name: "Avoid panic when partial nodes in a topology don't have pods with affinity", }, { From 65d2dda44355152dba37fe60269d63bdf79ad40d Mon Sep 17 00:00:00 2001 From: leileiwan Date: Sun, 24 Jan 2021 17:30:27 +0800 Subject: [PATCH 3/3] fix(*): init max score with -maxInt64 --- pkg/scheduler/framework/plugins/interpodaffinity/scoring.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go index 1c38daeade6..a664d22716d 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go @@ -254,7 +254,7 @@ func (pl *InterPodAffinity) NormalizeScore(ctx context.Context, cycleState *fram } var minCount int64 = math.MaxInt64 - var maxCount int64 + var maxCount int64 = -math.MaxInt64 for i := range scores { score := scores[i].Score if score > maxCount {