From 4b62cc9a86c6f1f09e3f6d3704020efb25558d3d Mon Sep 17 00:00:00 2001 From: Avesh Agarwal Date: Tue, 15 Aug 2017 12:31:56 -0400 Subject: [PATCH] Fix computation of nodes with low utilization. --- .../strategies/lownodeutilization.go | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/rescheduler/strategies/lownodeutilization.go b/pkg/rescheduler/strategies/lownodeutilization.go index 7e7286f11..3d8c5d0d3 100644 --- a/pkg/rescheduler/strategies/lownodeutilization.go +++ b/pkg/rescheduler/strategies/lownodeutilization.go @@ -44,10 +44,23 @@ func LowNodeUtilization(client clientset.Interface, strategy api.ReschedulerStra return } + // todo: move to config validation? thresholds := strategy.Params.NodeResourceUtilizationThresholds.Thresholds if thresholds == nil { fmt.Printf("no resource threshold is configured\n") return + } else { + found := false + for name, _ := range thresholds { + if name == v1.ResourceCPU || name == v1.ResourceMemory || name == v1.ResourcePods { + found = true + break + } + } + if !found { + fmt.Printf("one of cpu, memory, or pods resource threshold must be configured\n") + return + } } targetThresholds := strategy.Params.NodeResourceUtilizationThresholds.TargetThresholds @@ -181,19 +194,16 @@ func IsNodeAboveTargetUtilization(nodeThresholds api.ResourceThresholds, thresho } func IsNodeWithLowUtilization(nodeThresholds api.ResourceThresholds, thresholds api.ResourceThresholds) bool { - found := false for name, nodeValue := range nodeThresholds { if name == v1.ResourceCPU || name == v1.ResourceMemory || name == v1.ResourcePods { if value, ok := thresholds[name]; !ok { continue } else if nodeValue > value { - found = found && false - } else { - found = found && true + return false } } } - return found + return true } func NodeUtilization(node *v1.Node, pods []*v1.Pod) (api.ResourceThresholds, []*v1.Pod, []*v1.Pod, []*v1.Pod) {