Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

descheduler: only include the overused resources when sorting removable pods #1962

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions pkg/descheduler/framework/plugins/loadaware/utilization_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,7 @@ func evictPodsFromSourceNodes(
klog.V(4).InfoS("No removable pods on node, try next node", "node", klog.KObj(srcNode.node), "nodePool", nodePoolName)
continue
}

sorter.SortPodsByUsage(
removablePods,
srcNode.podMetrics,
map[string]corev1.ResourceList{srcNode.node.Name: srcNode.node.Status.Allocatable},
resourceWeights,
)
sortPodsOnOneOverloadedNode(srcNode, removablePods, resourceWeights)
evictPods(ctx, nodePoolName, dryRun, removablePods, srcNode, totalAvailableUsages, podEvictor, podFilter, continueEviction, evictionReasonGenerator)
}
}
Expand Down Expand Up @@ -472,3 +466,17 @@ func calcAverageResourceUsagePercent(nodeUsages map[string]*NodeUsage) ResourceT
}
return average
}
func sortPodsOnOneOverloadedNode(srcNode NodeInfo, removablePods []*corev1.Pod, resourceWeights map[corev1.ResourceName]int64) {
weights := make(map[corev1.ResourceName]int64)
// get the overused resource of this node, and the weights of appropriately using resources will be zero.
overusedResources, _ := isNodeOverutilized(srcNode.usage, srcNode.thresholds.highResourceThreshold)
for or := range overusedResources {
weights[or] = resourceWeights[or]
}
sorter.SortPodsByUsage(
removablePods,
srcNode.podMetrics,
map[string]corev1.ResourceList{srcNode.node.Name: srcNode.node.Status.Allocatable},
weights,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
)

var (
Expand Down Expand Up @@ -147,3 +150,82 @@ func TestSortNodesByUsageAscendingOrder(t *testing.T) {

assert.Equal(t, expectedNodeList, nodeList)
}
func TestSortPodsOnOneOverloadedNode(t *testing.T) {
nodeInfo := NodeInfo{
NodeUsage: &NodeUsage{
node: &corev1.Node{
Status: corev1.NodeStatus{
Allocatable: testNodeAllocatable,
},
ObjectMeta: metav1.ObjectMeta{Name: "node0"},
},
// only make cpu overused
usage: map[corev1.ResourceName]*resource.Quantity{
corev1.ResourceCPU: resource.NewMilliQuantity(30000, resource.DecimalSI),
corev1.ResourceMemory: resource.NewQuantity(998244353, resource.BinarySI),
},
podMetrics: map[types.NamespacedName]*slov1alpha1.ResourceMap{
{
Namespace: "ns",
Name: "pod1",
}: {
ResourceList: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(1000, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(27487790694, resource.BinarySI),
},
},
{
Namespace: "ns",
Name: "pod2",
}: {
ResourceList: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(3000, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(27487790694, resource.BinarySI),
},
},
{
Namespace: "ns",
Name: "pod3",
}: {
ResourceList: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(1, resource.BinarySI),
},
},
{
Namespace: "ns",
Name: "pod4",
}: {
ResourceList: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(4000, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(1, resource.BinarySI),
},
},
},
},
thresholds: NodeThresholds{
lowResourceThreshold: nil,
highResourceThreshold: map[corev1.ResourceName]*resource.Quantity{
corev1.ResourceCPU: resource.NewMilliQuantity(20000, resource.DecimalSI),
corev1.ResourceMemory: resource.NewQuantity(27487790694, resource.BinarySI),
},
},
}
removablePods := []*corev1.Pod{
{ObjectMeta: metav1.ObjectMeta{Name: "pod1", Namespace: "ns"}, Spec: corev1.PodSpec{NodeName: "node0"}},
{ObjectMeta: metav1.ObjectMeta{Name: "pod2", Namespace: "ns"}, Spec: corev1.PodSpec{NodeName: "node0"}},
{ObjectMeta: metav1.ObjectMeta{Name: "pod3", Namespace: "ns"}, Spec: corev1.PodSpec{NodeName: "node0"}},
{ObjectMeta: metav1.ObjectMeta{Name: "pod4", Namespace: "ns"}, Spec: corev1.PodSpec{NodeName: "node0"}},
}
expectedResult := make([]*corev1.Pod, 4)
expectedResult[0] = removablePods[3]
expectedResult[1] = removablePods[1]
expectedResult[2] = removablePods[2]
expectedResult[3] = removablePods[0]
resourceWeights := map[corev1.ResourceName]int64{
corev1.ResourceCPU: int64(1),
corev1.ResourceMemory: int64(1),
}
sortPodsOnOneOverloadedNode(nodeInfo, removablePods, resourceWeights)
assert.Equal(t, expectedResult, removablePods)
}
Loading