mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-28 14:41:10 +01:00
Update implementation of low node utilization strategy.
This commit is contained in:
@@ -114,32 +114,38 @@ func LowNodeUtilization(client clientset.Interface, strategy api.ReschedulerStra
|
|||||||
totalPods += ((float64(podsPercentage) * float64(nodeCapcity.Pods().Value())) / 100)
|
totalPods += ((float64(podsPercentage) * float64(nodeCapcity.Pods().Value())) / 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
podsPerTargetNode := totalPods / float64(len(targetNodes))
|
for _, node := range targetNodes {
|
||||||
if podsPerTargetNode > 0 {
|
nodePodsUsage := node.usage[v1.ResourcePods]
|
||||||
for _, node := range targetNodes {
|
nodeCapcity := node.node.Status.Capacity
|
||||||
n := podsPerTargetNode
|
if len(node.node.Status.Allocatable) > 0 {
|
||||||
// evict best effort pods first
|
nodeCapcity = node.node.Status.Allocatable
|
||||||
|
}
|
||||||
|
onePodPercentage := api.Percentage((float64(1) * 100) / float64(nodeCapcity.Pods().Value()))
|
||||||
|
if nodePodsUsage > targetThresholds[v1.ResourcePods] && totalPods > 0 {
|
||||||
for _, pod := range node.bePods {
|
for _, pod := range node.bePods {
|
||||||
success, err := evictions.EvictPod(client, pod, evictionPolicyGroupVersion)
|
success, err := evictions.EvictPod(client, pod, evictionPolicyGroupVersion)
|
||||||
if !success {
|
if !success {
|
||||||
fmt.Printf("Error when evicting pod: %#v (%#v)\n", pod.Name, err)
|
fmt.Printf("Error when evicting pod: %#v (%#v)\n", pod.Name, err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Evicted pod: %#v (%#v)\n", pod.Name, err)
|
fmt.Printf("Evicted pod: %#v (%#v)\n", pod.Name, err)
|
||||||
n--
|
nodePodsUsage = nodePodsUsage - onePodPercentage
|
||||||
if n < 0 {
|
totalPods--
|
||||||
|
if nodePodsUsage <= targetThresholds[v1.ResourcePods] || totalPods <= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n > 0 {
|
if nodePodsUsage > targetThresholds[v1.ResourcePods] && totalPods > 0 {
|
||||||
for _, pod := range node.otherPods {
|
for _, pod := range node.otherPods {
|
||||||
success, err := evictions.EvictPod(client, pod, evictionPolicyGroupVersion)
|
success, err := evictions.EvictPod(client, pod, evictionPolicyGroupVersion)
|
||||||
if !success {
|
if !success {
|
||||||
fmt.Printf("Error when evicting pod: %#v (%#v)\n", pod.Name, err)
|
fmt.Printf("Error when evicting pod: %#v (%#v)\n", pod.Name, err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Evicted pod: %#v (%#v)\n", pod.Name, err)
|
fmt.Printf("Evicted pod: %#v (%#v)\n", pod.Name, err)
|
||||||
n--
|
nodePodsUsage = nodePodsUsage - onePodPercentage
|
||||||
if n < 0 {
|
totalPods--
|
||||||
|
if nodePodsUsage <= targetThresholds[v1.ResourcePods] || totalPods <= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user