Switch on the resource requested prioritization.

This commit is contained in:
Brendan Burns
2014-10-09 10:41:42 -07:00
parent b3292e947f
commit b5ec8a747b
6 changed files with 24 additions and 4 deletions

View File

@@ -22,6 +22,13 @@ import (
"github.com/golang/glog"
)
func calculatePercentage(requested, capacity int) int {
if capacity == 0 {
return 0
}
return (requested * 100) / capacity
}
// Calculate the occupancy on a node. 'node' has information about the resources on the node.
// 'pods' is a list of pods currently scheduled on the node.
func calculateOccupancy(node api.Minion, pods []api.Pod) HostPriority {
@@ -34,8 +41,9 @@ func calculateOccupancy(node api.Minion, pods []api.Pod) HostPriority {
totalMemory += container.Memory
}
}
percentageCPU := (totalCPU * 100) / resources.GetIntegerResource(node.NodeResources.Capacity, resources.CPU, 0)
percentageMemory := (totalMemory * 100) / resources.GetIntegerResource(node.NodeResources.Capacity, resources.Memory, 0)
percentageCPU := calculatePercentage(totalCPU, resources.GetIntegerResource(node.NodeResources.Capacity, resources.CPU, 0))
percentageMemory := calculatePercentage(totalMemory, resources.GetIntegerResource(node.NodeResources.Capacity, resources.Memory, 0))
glog.V(4).Infof("Least Requested Priority, AbsoluteRequested: (%d, %d) Percentage:(%d\\%m, %d\\%)", totalCPU, totalMemory, percentageCPU, percentageMemory)
return HostPriority{

View File

@@ -100,6 +100,15 @@ func TestLeastRequested(t *testing.T) {
{DesiredState: cpuAndMemory, CurrentState: machine2State},
},
},
{
nodes: []api.Minion{makeMinion("machine1", 0, 0), makeMinion("machine2", 0, 0)},
expectedList: []HostPriority{{"machine1", 0}, {"machine2", 0}},
test: "zero minion resources",
pods: []api.Pod{
{DesiredState: cpuOnly, CurrentState: machine1State},
{DesiredState: cpuAndMemory, CurrentState: machine2State},
},
},
}
for _, test := range tests {