mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-28 06:29:29 +01:00
Update low utilization thresholds strategy implementation.
This commit is contained in:
@@ -1,16 +1,4 @@
|
|||||||
apiVersion: "rescheduler/v1alpha1"
|
apiVersion: "rescheduler/v1alpha1"
|
||||||
kind: "ReschedulerPolicy"
|
kind: "ReschedulerPolicy"
|
||||||
strategies:
|
strategies:
|
||||||
"LowNodeUtilization":
|
"test":
|
||||||
enabled: true
|
|
||||||
weight: 1
|
|
||||||
params:
|
|
||||||
nodeResourceUtilizationThresholds:
|
|
||||||
thresholds:
|
|
||||||
"cpu" : 10
|
|
||||||
"memory": 50
|
|
||||||
"pods": 50
|
|
||||||
targetThresholds:
|
|
||||||
"cpu" : 10
|
|
||||||
"memory": 50
|
|
||||||
"pods": 50
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
helper "k8s.io/kubernetes/pkg/api/v1/resource"
|
helper "k8s.io/kubernetes/pkg/api/v1/resource"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||||
|
|
||||||
"github.com/aveshagarwal/rescheduler/pkg/api"
|
"github.com/aveshagarwal/rescheduler/pkg/api"
|
||||||
@@ -32,14 +31,38 @@ import (
|
|||||||
type NodeUsageMap map[*v1.Node]api.ResourceThresholds
|
type NodeUsageMap map[*v1.Node]api.ResourceThresholds
|
||||||
|
|
||||||
func LowNodeUtilization(client clientset.Interface, strategy api.ReschedulerStrategy, evictionPolicyGroupVersion string, nodes []*v1.Node) {
|
func LowNodeUtilization(client clientset.Interface, strategy api.ReschedulerStrategy, evictionPolicyGroupVersion string, nodes []*v1.Node) {
|
||||||
nodeUsageMap := NodeUsageMap{}
|
lowNodes, otherNodes := []*v1.Node{}, []*v1.Node{}
|
||||||
for _, node := range nodes {
|
|
||||||
nodeUsageMap[node] = NodeUtilization(client, node)
|
if strategy.Enabled {
|
||||||
fmt.Printf("Node %#v usage: %#v\n", node.Name, nodeUsageMap[node])
|
thresholds := strategy.Params.NodeResourceUtilizationThresholds.Thresholds
|
||||||
|
if thresholds != nil {
|
||||||
|
nodeUsageMap := NodeUsageMap{}
|
||||||
|
for _, node := range nodes {
|
||||||
|
nodeUsageMap[node] = NodeUtilization(client, node)
|
||||||
|
fmt.Printf("Node %#v usage: %#v\n", node.Name, nodeUsageMap[node])
|
||||||
|
|
||||||
|
if IsNodeWithLowUtilization(nodeUsageMap[node], thresholds) {
|
||||||
|
lowNodes = append(lowNodes, node)
|
||||||
|
} else {
|
||||||
|
otherNodes = append(otherNodes, node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindNodesWithLowUtilization() {
|
func IsNodeWithLowUtilization(nodeThresholds api.ResourceThresholds, thresholds api.ResourceThresholds) bool {
|
||||||
|
found := true
|
||||||
|
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 = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
func NodeUtilization(client clientset.Interface, node *v1.Node) api.ResourceThresholds {
|
func NodeUtilization(client clientset.Interface, node *v1.Node) api.ResourceThresholds {
|
||||||
|
|||||||
Reference in New Issue
Block a user