From c1fd8390e5d8403f23cbbf295672602fc5295e87 Mon Sep 17 00:00:00 2001 From: BinacsLee Date: Tue, 20 Apr 2021 20:07:43 +0800 Subject: [PATCH] code cleanup: pkg/scheduler modify framework/types.go --- pkg/scheduler/framework/types.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/scheduler/framework/types.go b/pkg/scheduler/framework/types.go index 440728767f8..a2efff767c2 100644 --- a/pkg/scheduler/framework/types.go +++ b/pkg/scheduler/framework/types.go @@ -86,10 +86,7 @@ type ClusterEvent struct { // IsWildCard returns true if ClusterEvent follows WildCard semantics func (ce ClusterEvent) IsWildCard() bool { - if ce.Resource == WildCard && ce.ActionType == All { - return true - } - return false + return ce.Resource == WildCard && ce.ActionType == All } // QueuedPodInfo is a Pod wrapper with additional information related to @@ -776,6 +773,13 @@ func (n *NodeInfo) resetSlicesIfEmpty() { } } +func max(a, b int64) int64 { + if a >= b { + return a + } + return b +} + // resourceRequest = max(sum(podSpec.Containers), podSpec.InitContainers) + overHead func calculateResource(pod *v1.Pod) (res Resource, non0CPU int64, non0Mem int64) { resPtr := &res @@ -790,13 +794,8 @@ func calculateResource(pod *v1.Pod) (res Resource, non0CPU int64, non0Mem int64) for _, ic := range pod.Spec.InitContainers { resPtr.SetMaxResource(ic.Resources.Requests) non0CPUReq, non0MemReq := schedutil.GetNonzeroRequests(&ic.Resources.Requests) - if non0CPU < non0CPUReq { - non0CPU = non0CPUReq - } - - if non0Mem < non0MemReq { - non0Mem = non0MemReq - } + non0CPU = max(non0CPU, non0CPUReq) + non0Mem = max(non0Mem, non0MemReq) } // If Overhead is being utilized, add to the total requests for the pod