mirror of
https://github.com/outbackdingo/kubernetes.git
synced 2026-03-02 06:40:16 +00:00
Merge pull request #13857 from mesosphere/node-labels
Auto commit by PR queue bot
This commit is contained in:
53
test/e2e/mesos.go
Normal file
53
test/e2e/mesos.go
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
)
|
||||
|
||||
var _ = Describe("Mesos", func() {
|
||||
framework := NewFramework("pods")
|
||||
|
||||
BeforeEach(func() {
|
||||
SkipUnlessProviderIs("mesos/docker")
|
||||
})
|
||||
|
||||
It("applies slave attributes as labels", func() {
|
||||
nodeClient := framework.Client.Nodes()
|
||||
|
||||
rackA := labels.SelectorFromSet(map[string]string{"k8s.mesosphere.io/attribute-rack": "1"})
|
||||
nodes, err := nodeClient.List(rackA, fields.Everything())
|
||||
if err != nil {
|
||||
Failf("Failed to query for node: %v", err)
|
||||
}
|
||||
Expect(len(nodes.Items)).To(Equal(1))
|
||||
|
||||
var addr string
|
||||
for _, a := range nodes.Items[0].Status.Addresses {
|
||||
if a.Type == api.NodeInternalIP {
|
||||
addr = a.Address
|
||||
}
|
||||
}
|
||||
Expect(len(addr)).NotTo(Equal(""))
|
||||
})
|
||||
})
|
||||
@@ -334,7 +334,7 @@ var _ = Describe("SchedulerPredicates", func() {
|
||||
|
||||
// Test Nodes does not have any label, hence it should be impossible to schedule Pod with
|
||||
// nonempty Selector set.
|
||||
It("validates that NodeSelector is respected.", func() {
|
||||
It("validates that NodeSelector is respected if not matching", func() {
|
||||
By("Trying to schedule Pod with nonempty NodeSelector.")
|
||||
podName := "restricted-pod"
|
||||
|
||||
@@ -371,4 +371,77 @@ var _ = Describe("SchedulerPredicates", func() {
|
||||
verifyResult(c, podName, ns, currentlyDeadPods)
|
||||
cleanupPods(c, ns)
|
||||
})
|
||||
|
||||
It("validates that NodeSelector is respected if matching.", 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 without a label to get a node which can launch it.")
|
||||
podName := "without-label"
|
||||
_, err := c.Pods(ns).Create(&api.Pod{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
Kind: "Pod",
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: podName,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: podName,
|
||||
Image: "gcr.io/google_containers/pause:go",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
expectNoError(err)
|
||||
expectNoError(waitForPodRunningInNamespace(c, podName, ns))
|
||||
pod, err := c.Pods(ns).Get(podName)
|
||||
expectNoError(err)
|
||||
|
||||
nodeName := pod.Spec.NodeName
|
||||
err = c.Pods(ns).Delete(podName, api.NewDeleteOptions(0))
|
||||
expectNoError(err)
|
||||
|
||||
By("Trying to apply a random label on the found node.")
|
||||
k := fmt.Sprintf("kubernetes.io/e2e-%s", string(util.NewUUID()))
|
||||
v := "42"
|
||||
patch := fmt.Sprintf(`{"metadata":{"labels":{"%s":"%s"}}}`, k, v)
|
||||
err = c.Patch(api.MergePatchType).Resource("nodes").Name(nodeName).Body([]byte(patch)).Do().Error()
|
||||
expectNoError(err)
|
||||
|
||||
node, err := c.Nodes().Get(nodeName)
|
||||
expectNoError(err)
|
||||
Expect(node.Labels[k]).To(Equal(v))
|
||||
|
||||
By("Trying to relaunch the pod, now with labels.")
|
||||
labelPodName := "with-labels"
|
||||
_, err = c.Pods(ns).Create(&api.Pod{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
Kind: "Pod",
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: labelPodName,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: labelPodName,
|
||||
Image: "gcr.io/google_containers/pause:go",
|
||||
},
|
||||
},
|
||||
NodeSelector: map[string]string{
|
||||
"kubernetes.io/hostname": nodeName,
|
||||
k: v,
|
||||
},
|
||||
},
|
||||
})
|
||||
expectNoError(err)
|
||||
defer c.Pods(ns).Delete(labelPodName, api.NewDeleteOptions(0))
|
||||
expectNoError(waitForPodRunningInNamespace(c, labelPodName, ns))
|
||||
labelPod, err := c.Pods(ns).Get(labelPodName)
|
||||
expectNoError(err)
|
||||
Expect(labelPod.Spec.NodeName).To(Equal(nodeName))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user