From 39e459ae9a6c951a2d0ca4a94a935df5b723d5d9 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Fri, 19 Jul 2019 22:52:49 -0700 Subject: [PATCH] fixup: address comments --- pkg/scheduler/algorithm/predicates/BUILD | 1 - pkg/scheduler/algorithm/predicates/predicates.go | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/scheduler/algorithm/predicates/BUILD b/pkg/scheduler/algorithm/predicates/BUILD index dd31d198949..5e6c799e5c4 100644 --- a/pkg/scheduler/algorithm/predicates/BUILD +++ b/pkg/scheduler/algorithm/predicates/BUILD @@ -64,7 +64,6 @@ go_test( "//pkg/scheduler/api:go_default_library", "//pkg/scheduler/nodeinfo:go_default_library", "//pkg/scheduler/testing:go_default_library", - "//pkg/scheduler/util:go_default_library", "//pkg/volume/util:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/storage/v1:go_default_library", diff --git a/pkg/scheduler/algorithm/predicates/predicates.go b/pkg/scheduler/algorithm/predicates/predicates.go index 4fefdbbe577..5ca0853e180 100644 --- a/pkg/scheduler/algorithm/predicates/predicates.go +++ b/pkg/scheduler/algorithm/predicates/predicates.go @@ -1767,11 +1767,9 @@ func EvenPodsSpreadPredicate(pod *v1.Pod, meta PredicateMetadata, nodeInfo *sche // 'existing matching num' + 'if self-match (1 or 0)' - 'global min matching num' <= 'maxSkew' matchNum := len(topologyPairsPodSpreadMap.topologyPairToPods[pair]) - // TODO(Huang-Wei): remove this after thorough testing - // fmt.Printf("node '%s' => spreadConstraint[%s]: matchNum(%d) + selfMatchNum(%d) - minMatchNum(%d) ?<= maxSkew(%d)\n", node.Name, tpKey, matchNum, selfMatchNum, minMatchNum, constraint.MaxSkew) - - // TODO(Huang-Wei): check if it can overflow? - if int32(matchNum+selfMatchNum)-minMatchNum > constraint.MaxSkew { + // cast to int to avoid potential overflow. + skew := matchNum + selfMatchNum - int(minMatchNum) + if skew > int(constraint.MaxSkew) { klog.V(5).Infof("node '%s' failed spreadConstraint[%s]: matchNum(%d) + selfMatchNum(%d) - minMatchNum(%d) > maxSkew(%d)", node.Name, tpKey, matchNum, selfMatchNum, minMatchNum, constraint.MaxSkew) return false, []PredicateFailureReason{ErrTopologySpreadConstraintsNotMatch}, nil }