mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-26 12:46:06 +00:00
scheduler: implement role awareness
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
@@ -30,9 +32,13 @@ import (
|
||||
|
||||
var _ = Describe("Mesos", func() {
|
||||
framework := NewFramework("pods")
|
||||
var c *client.Client
|
||||
var ns string
|
||||
|
||||
BeforeEach(func() {
|
||||
SkipUnlessProviderIs("mesos/docker")
|
||||
c = framework.Client
|
||||
ns = framework.Namespace.Name
|
||||
})
|
||||
|
||||
It("applies slave attributes as labels", func() {
|
||||
@@ -66,4 +72,46 @@ var _ = Describe("Mesos", func() {
|
||||
expectNoError(waitForPodsRunningReady(ns, numpods, util.ForeverTestTimeout),
|
||||
fmt.Sprintf("number of static pods in namespace %s is %d", ns, numpods))
|
||||
})
|
||||
|
||||
It("schedules pods labelled with roles on correct slaves", func() {
|
||||
// launch a pod to find a node which can launch a pod. We intentionally do
|
||||
// not just take the node list and choose the first of them. Depending on the
|
||||
// cluster and the scheduler it might be that a "normal" pod cannot be
|
||||
// scheduled onto it.
|
||||
By("Trying to launch a pod with a label to get a node which can launch it.")
|
||||
podName := "with-label"
|
||||
_, err := c.Pods(ns).Create(&api.Pod{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
Kind: "Pod",
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: podName,
|
||||
Labels: map[string]string{
|
||||
"k8s.mesosphere.io/roles": "role1",
|
||||
},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: podName,
|
||||
Image: "beta.gcr.io/google_containers/pause:2.0",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
expectNoError(err)
|
||||
|
||||
expectNoError(waitForPodRunningInNamespace(c, podName, ns))
|
||||
pod, err := c.Pods(ns).Get(podName)
|
||||
expectNoError(err)
|
||||
|
||||
nodeClient := framework.Client.Nodes()
|
||||
role1 := labels.SelectorFromSet(map[string]string{
|
||||
"k8s.mesosphere.io/attribute-role": "role1",
|
||||
})
|
||||
nodes, err := nodeClient.List(role1, fields.Everything())
|
||||
expectNoError(err)
|
||||
|
||||
Expect(nodes.Items[0].Name).To(Equal(pod.Spec.NodeName))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user