diff --git a/examples/guestbook/frontend-controller.json b/examples/guestbook/frontend-controller.json index aa0b0d92a33..6e4d7dfff05 100644 --- a/examples/guestbook/frontend-controller.json +++ b/examples/guestbook/frontend-controller.json @@ -13,6 +13,7 @@ "containers": [{ "name": "php-redis", "image": "brendanburns/php-redis", + "cpu": 100, "memory": 10000000, "ports": [{"containerPort": 80, "hostPort": 8000}] }] diff --git a/examples/guestbook/redis-master.json b/examples/guestbook/redis-master.json index 667d693ccdb..c1aaf9ff8ff 100644 --- a/examples/guestbook/redis-master.json +++ b/examples/guestbook/redis-master.json @@ -9,6 +9,7 @@ "containers": [{ "name": "master", "image": "dockerfile/redis", + "cpu": 100, "ports": [{ "containerPort": 6379, "hostPort": 6379 diff --git a/examples/guestbook/redis-slave-controller.json b/examples/guestbook/redis-slave-controller.json index 1cd03061ba6..4df013737d3 100644 --- a/examples/guestbook/redis-slave-controller.json +++ b/examples/guestbook/redis-slave-controller.json @@ -13,6 +13,7 @@ "containers": [{ "name": "slave", "image": "brendanburns/redis-slave", + "cpu": 200, "ports": [{"containerPort": 6379, "hostPort": 6380}] }] } diff --git a/pkg/scheduler/priorities.go b/pkg/scheduler/priorities.go index 1fcfaad545a..b338fa30842 100644 --- a/pkg/scheduler/priorities.go +++ b/pkg/scheduler/priorities.go @@ -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{ diff --git a/pkg/scheduler/priorities_test.go b/pkg/scheduler/priorities_test.go index b4a0730b7c0..fbc55944e24 100644 --- a/pkg/scheduler/priorities_test.go +++ b/pkg/scheduler/priorities_test.go @@ -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 { diff --git a/plugin/pkg/scheduler/factory/factory.go b/plugin/pkg/scheduler/factory/factory.go index f229ecc1c9e..d80e7e4275f 100644 --- a/plugin/pkg/scheduler/factory/factory.go +++ b/plugin/pkg/scheduler/factory/factory.go @@ -76,8 +76,8 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) { // Fit is determined by resource availability algorithm.NewResourceFitPredicate(algorithm.StaticNodeInfo{nodes}), }, - // All nodes where things fit are equally likely (Random) - algorithm.EqualPriority, + // Prioritize nodes by least requested utilization. + algorithm.LeastRequestedPriority, &storeToPodLister{podCache}, r) podBackoff := podBackoff{