mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-12 12:48:51 +00:00
Add Host to PodSpec and add a predicate to make the scheduler work.
This commit is contained in:
@@ -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)
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user