Use DesiredState.Host in scheduler predicate

This commit is contained in:
Deyuan Deng 2014-10-12 16:39:48 -04:00
parent 695fbee343
commit 19c62d719c
2 changed files with 11 additions and 9 deletions

View File

@ -143,7 +143,7 @@ func MapPodsToMachines(lister PodLister) (map[string][]api.Pod, error) {
return map[string][]api.Pod{}, err return map[string][]api.Pod{}, err
} }
for _, scheduledPod := range pods { for _, scheduledPod := range pods {
host := scheduledPod.CurrentState.Host host := scheduledPod.DesiredState.Host
machineToPods[host] = append(machineToPods[host], scheduledPod) machineToPods[host] = append(machineToPods[host], scheduledPod)
} }
return machineToPods, nil return machineToPods, nil

View File

@ -59,6 +59,7 @@ func TestLeastRequested(t *testing.T) {
{CPU: 2000}, {CPU: 2000},
}, },
}, },
Host: "machine1",
} }
cpuAndMemory := api.PodState{ cpuAndMemory := api.PodState{
Manifest: api.ContainerManifest{ Manifest: api.ContainerManifest{
@ -67,6 +68,7 @@ func TestLeastRequested(t *testing.T) {
{CPU: 2000, Memory: 3000}, {CPU: 2000, Memory: 3000},
}, },
}, },
Host: "machine2",
} }
tests := []struct { tests := []struct {
pod api.Pod pod api.Pod
@ -85,10 +87,10 @@ func TestLeastRequested(t *testing.T) {
expectedList: []HostPriority{{"machine1", 0}, {"machine2", 0}}, expectedList: []HostPriority{{"machine1", 0}, {"machine2", 0}},
test: "no resources requested", test: "no resources requested",
pods: []api.Pod{ pods: []api.Pod{
{CurrentState: machine1State, Labels: labels2}, {DesiredState: machine1State, Labels: labels2},
{CurrentState: machine1State, Labels: labels1}, {DesiredState: machine1State, Labels: labels1},
{CurrentState: machine2State, Labels: labels1}, {DesiredState: machine2State, Labels: labels1},
{CurrentState: machine2State, Labels: labels1}, {DesiredState: machine2State, Labels: labels1},
}, },
}, },
{ {
@ -96,8 +98,8 @@ func TestLeastRequested(t *testing.T) {
expectedList: []HostPriority{{"machine1", 37 /* int(75% / 2) */}, {"machine2", 62 /* int( 75% + 50% / 2) */}}, expectedList: []HostPriority{{"machine1", 37 /* int(75% / 2) */}, {"machine2", 62 /* int( 75% + 50% / 2) */}},
test: "no resources requested", test: "no resources requested",
pods: []api.Pod{ pods: []api.Pod{
{DesiredState: cpuOnly, CurrentState: machine1State}, {DesiredState: cpuOnly},
{DesiredState: cpuAndMemory, CurrentState: machine2State}, {DesiredState: cpuAndMemory},
}, },
}, },
{ {
@ -105,8 +107,8 @@ func TestLeastRequested(t *testing.T) {
expectedList: []HostPriority{{"machine1", 0}, {"machine2", 0}}, expectedList: []HostPriority{{"machine1", 0}, {"machine2", 0}},
test: "zero minion resources", test: "zero minion resources",
pods: []api.Pod{ pods: []api.Pod{
{DesiredState: cpuOnly, CurrentState: machine1State}, {DesiredState: cpuOnly},
{DesiredState: cpuAndMemory, CurrentState: machine2State}, {DesiredState: cpuAndMemory},
}, },
}, },
} }