Skip to content

Commit

Permalink
koord-descheduler: Fix threshold initialization for prod. (#2130)
Browse files Browse the repository at this point in the history
Signed-off-by: zwForrest <[email protected]>
  • Loading branch information
zwForrest authored Jul 16, 2024
1 parent 4c38309 commit db93c61
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
62 changes: 62 additions & 0 deletions pkg/descheduler/framework/plugins/loadaware/low_node_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,68 @@ func TestLowNodeLoad(t *testing.T) {
expectedPodsEvicted: 5,
evictedPods: []string{},
},
{
name: "node is always appropriately for node usage, prod pod rebalance successful",
useDeviationThresholds: true,
thresholds: ResourceThresholds{
corev1.ResourceCPU: 0,
corev1.ResourcePods: 0,
},
targetThresholds: ResourceThresholds{
corev1.ResourceCPU: 100,
corev1.ResourcePods: 100,
},
prodLowThresholds: ResourceThresholds{
corev1.ResourceCPU: 10,
corev1.ResourcePods: 10,
},
prodHighThresholds: ResourceThresholds{
corev1.ResourceCPU: 10,
corev1.ResourcePods: 10,
},
nodes: []*corev1.Node{
test.BuildTestNode(n1NodeName, 4000, 3000, 20, nil),
test.BuildTestNode(n2NodeName, 4000, 3000, 20, nil),
test.BuildTestNode(n3NodeName, 4000, 3000, 20, nil),
},
pods: []*corev1.Pod{
test.BuildTestPod("p1", 400, 0, n1NodeName, test.SetRSOwnerRef),
test.BuildTestPod("p2", 400, 0, n1NodeName, test.SetRSOwnerRef),
test.BuildTestPod("p3", 400, 0, n1NodeName, test.SetRSOwnerRef),
test.BuildTestPod("p4", 400, 0, n1NodeName, test.SetRSOwnerRef),
test.BuildTestPod("p5", 400, 0, n1NodeName, test.SetRSOwnerRef),
// These won't be evicted.
test.BuildTestPod("p6", 400, 0, n1NodeName, test.SetDSOwnerRef),
test.BuildTestPod("p7", 400, 0, n1NodeName, func(pod *corev1.Pod) {
// A pod with local storage.
test.SetNormalOwnerRef(pod)
pod.Spec.Volumes = []corev1.Volume{
{
Name: "sample",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{Path: "somePath"},
EmptyDir: &corev1.EmptyDirVolumeSource{
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI),
},
},
},
}
// A Mirror Pod.
pod.Annotations = test.GetMirrorPodAnnotation()
}),
test.BuildTestPod("p8", 400, 0, n1NodeName, func(pod *corev1.Pod) {
// A Critical Pod.
pod.Namespace = "kube-system"
priority := utils.SystemCriticalPriority
pod.Spec.Priority = &priority
}),
test.BuildTestPod("p9", 400, 0, n2NodeName, test.SetRSOwnerRef),
test.BuildTestPod("p10", 400, 0, n3NodeName, test.SetRSOwnerRef),
test.BuildTestPod("p11", 400, 0, n3NodeName, test.SetRSOwnerRef),
},
expectedPodsEvicted: 4,
evictedPods: []string{},
},
}

for _, tt := range testCases {
Expand Down
23 changes: 15 additions & 8 deletions pkg/descheduler/framework/plugins/loadaware/utilization_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func getNodeThresholds(
var averageResourceUsagePercent, prodAverageResourceUsagePercent ResourceThresholds
if useDeviationThresholds {
averageResourceUsagePercent, prodAverageResourceUsagePercent = calcAverageResourceUsagePercent(nodeUsages)
klog.V(4).InfoS("useDeviationThresholds", "node", averageResourceUsagePercent, "prod", prodAverageResourceUsagePercent)
}

nodeThresholdsMap := map[string]NodeThresholds{}
Expand All @@ -107,11 +108,14 @@ func getNodeThresholds(
if lowThreshold[resourceName] == MinResourcePercentage {
thresholds.lowResourceThreshold[resourceName] = &resourceCapacity
thresholds.highResourceThreshold[resourceName] = &resourceCapacity
thresholds.prodLowResourceThreshold[resourceName] = &resourceCapacity
thresholds.prodHighResourceThreshold[resourceName] = &resourceCapacity
} else {
thresholds.lowResourceThreshold[resourceName] = resourceThreshold(allocatable, resourceName, normalizePercentage(averageResourceUsagePercent[resourceName]-lowThreshold[resourceName]))
thresholds.highResourceThreshold[resourceName] = resourceThreshold(allocatable, resourceName, normalizePercentage(averageResourceUsagePercent[resourceName]+highThreshold[resourceName]))
}
if prodLowThreshold[resourceName] == MinResourcePercentage {
thresholds.prodLowResourceThreshold[resourceName] = &resourceCapacity
thresholds.prodHighResourceThreshold[resourceName] = &resourceCapacity
} else {
thresholds.prodLowResourceThreshold[resourceName] = resourceThreshold(allocatable, resourceName, normalizePercentage(prodAverageResourceUsagePercent[resourceName]-prodLowThreshold[resourceName]))
thresholds.prodHighResourceThreshold[resourceName] = resourceThreshold(allocatable, resourceName, normalizePercentage(prodAverageResourceUsagePercent[resourceName]+prodHighThreshold[resourceName]))
}
Expand Down Expand Up @@ -253,13 +257,15 @@ func classifyNodes(
lowNodes = append(lowNodes, nodeInfo)
nodeUsageExplain = "lower than node usage and it's appropriately for prod usage"
}
klog.InfoS("Node's utilization", "node", klog.KObj(nodeUsage.node), "result information", nodeUsageExplain, "node usage", nodeUsage.usage, "node usagePercentage", resourceUsagePercentages(nodeUsage, false),
"prod usage", nodeUsage.prodUsage, "prod usagePercentage", resourceUsagePercentages(nodeUsage, true))
klog.V(4).InfoS("Node's utilization", "node", klog.KObj(nodeUsage.node), "result information", nodeUsageExplain, "node usage", nodeUsage.usage, "node usagePercentage", resourceUsagePercentages(nodeUsage, false),
"node high threshold", nodeThresholds[nodeUsage.node.Name].highResourceThreshold, "node low threshold", nodeThresholds[nodeUsage.node.Name].lowResourceThreshold, "prod usage", nodeUsage.prodUsage,
"prod usagePercentage", resourceUsagePercentages(nodeUsage, true), "prod high threshold", nodeThresholds[nodeUsage.node.Name].prodHighResourceThreshold, "prod low threshold", nodeThresholds[nodeUsage.node.Name].prodLowResourceThreshold)
} else if highThresholdFilter(nodeUsage, nodeThresholds[nodeUsage.node.Name]) {
highNodes = append(highNodes, nodeInfo)
nodeUsageExplain = "higher than node usage"
klog.InfoS("Node's utilization", "node", klog.KObj(nodeUsage.node), "result information", nodeUsageExplain, "node usage", nodeUsage.usage, "node usagePercentage", resourceUsagePercentages(nodeUsage, false),
"prod usage", nodeUsage.prodUsage, "prod usagePercentage", resourceUsagePercentages(nodeUsage, true))
klog.V(4).InfoS("Node's utilization", "node", klog.KObj(nodeUsage.node), "result information", nodeUsageExplain, "node usage", nodeUsage.usage, "node usagePercentage", resourceUsagePercentages(nodeUsage, false),
"node high threshold", nodeThresholds[nodeUsage.node.Name].highResourceThreshold, "node low threshold", nodeThresholds[nodeUsage.node.Name].lowResourceThreshold, "prod usage", nodeUsage.prodUsage,
"prod usagePercentage", resourceUsagePercentages(nodeUsage, true), "prod high threshold", nodeThresholds[nodeUsage.node.Name].prodHighResourceThreshold, "prod low threshold", nodeThresholds[nodeUsage.node.Name].prodLowResourceThreshold)
} else {
if prodHighThresholdFilter(nodeUsage, nodeThresholds[nodeUsage.node.Name]) {
prodHighNodes = append(prodHighNodes, nodeInfo)
Expand All @@ -270,8 +276,9 @@ func classifyNodes(
} else {
nodeUsageExplain = "both appropriately for node && prod usage"
}
klog.InfoS("Node's utilization", "node", klog.KObj(nodeUsage.node), "result information", nodeUsageExplain, "node usage", nodeUsage.usage, "node usagePercentage", resourceUsagePercentages(nodeUsage, false),
"prod usage", nodeUsage.prodUsage, "prod usagePercentage", resourceUsagePercentages(nodeUsage, true))
klog.V(4).InfoS("Node's utilization", "node", klog.KObj(nodeUsage.node), "result information", nodeUsageExplain, "node usage", nodeUsage.usage, "node usagePercentage", resourceUsagePercentages(nodeUsage, false),
"node high threshold", nodeThresholds[nodeUsage.node.Name].highResourceThreshold, "node low threshold", nodeThresholds[nodeUsage.node.Name].lowResourceThreshold, "prod usage", nodeUsage.prodUsage,
"prod usagePercentage", resourceUsagePercentages(nodeUsage, true), "prod high threshold", nodeThresholds[nodeUsage.node.Name].prodHighResourceThreshold, "prod low threshold", nodeThresholds[nodeUsage.node.Name].prodLowResourceThreshold)
}
}

Expand Down

0 comments on commit db93c61

Please sign in to comment.