Add Host to PodSpec and add a predicate to make the scheduler work.

This commit is contained in:
Brendan Burns
2014-12-18 14:12:58 -08:00
parent 5bd560de51
commit 2e17193161
9 changed files with 87 additions and 0 deletions

View File

@@ -162,6 +162,13 @@ func (n *NodeSelector) PodSelectorMatches(pod api.Pod, existingPods []api.Pod, n
return selector.Matches(labels.Set(minion.Labels)), nil
}
func PodFitsHost(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
if len(pod.Spec.Host) == 0 {
return true, nil
}
return pod.Spec.Host == node, nil
}
func PodFitsPorts(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
existingPorts := getUsedPorts(existingPods...)
wantPorts := getUsedPorts(pod)

View File

@@ -124,6 +124,52 @@ func TestPodFitsResources(t *testing.T) {
}
}
func TestPodFitsHost(t *testing.T) {
tests := []struct {
pod api.Pod
node string
fits bool
test string
}{
{
pod: api.Pod{},
node: "foo",
fits: true,
test: "no host specified",
},
{
pod: api.Pod{
Spec: api.PodSpec{
Host: "foo",
},
},
node: "foo",
fits: true,
test: "host matches",
},
{
pod: api.Pod{
Spec: api.PodSpec{
Host: "bar",
},
},
node: "foo",
fits: false,
test: "host doesn't match",
},
}
for _, test := range tests {
result, err := PodFitsHost(test.pod, []api.Pod{}, test.node)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if result != test.fits {
t.Errorf("unexpected difference for %s: got: %v expected %v", test.test, test.fits, result)
}
}
}
func TestPodFitsPorts(t *testing.T) {
tests := []struct {
pod api.Pod