1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 05:14:13 +01:00

Change hard coded leastLoadedNode=[3rd node] to searching for leastLoadedNode worker node

Accomodate dee89a6cc1

And format files according to gofmt verification

update version to 1.11.1
This commit is contained in:
Bowen Song
2019-07-10 17:16:36 -04:00
parent 66a2a87e49
commit 7245a31f52
3 changed files with 23 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ package e2e
import (
"github.com/golang/glog"
"math"
"testing"
"time"
@@ -120,7 +121,8 @@ func startEndToEndForLowNodeUtilization(clientset clientset.Interface) {
func TestE2E(t *testing.T) {
// If we have reached here, it means cluster would have been already setup and the kubeconfig file should
// be in /tmp directory.
// be in /tmp directory as admin.conf.
var leastLoadedNode v1.Node
clientSet, err := client.CreateClient("/tmp/admin.conf")
if err != nil {
t.Errorf("Error during client creation with %v", err)
@@ -131,20 +133,31 @@ func TestE2E(t *testing.T) {
}
// Assumption: We would have 3 node cluster by now. Kubeadm brings all the master components onto master node.
// So, the last node would have least utilization.
leastLoadedNode := nodeList.Items[2]
rc := RcByNameContainer("test-rc", int32(15), map[string]string{"test": "app"}, nil)
_, err = clientSet.CoreV1().ReplicationControllers("default").Create(rc)
if err != nil {
t.Errorf("Error creating deployment %v", err)
}
podsOnleastUtilizedNode, err := podutil.ListPodsOnANode(clientSet, &leastLoadedNode)
if err != nil {
t.Errorf("Error listing pods on a node %v", err)
podsBefore := math.MaxInt16
for i := range nodeList.Items {
// Skip the Master Node
if _, exist := nodeList.Items[i].Labels["node-role.kubernetes.io/master"]; exist {
continue
}
// List all the pods on the current Node
podsOnANode, err := podutil.ListEvictablePodsOnNode(clientSet, &nodeList.Items[i], true)
if err != nil {
t.Errorf("Error listing pods on a node %v", err)
}
// Update leastLoadedNode if necessary
if tmpLoads := len(podsOnANode); tmpLoads < podsBefore {
leastLoadedNode = nodeList.Items[i]
podsBefore = tmpLoads
}
}
podsBefore := len(podsOnleastUtilizedNode)
t.Log("Eviction of pods starting")
startEndToEndForLowNodeUtilization(clientSet)
podsOnleastUtilizedNode, err = podutil.ListPodsOnANode(clientSet, &leastLoadedNode)
podsOnleastUtilizedNode, err := podutil.ListEvictablePodsOnNode(clientSet, &leastLoadedNode, true)
if err != nil {
t.Errorf("Error listing pods on a node %v", err)
}