mesos.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package e2e
  14. import (
  15. "fmt"
  16. "k8s.io/kubernetes/pkg/api"
  17. "k8s.io/kubernetes/pkg/api/unversioned"
  18. client "k8s.io/kubernetes/pkg/client/unversioned"
  19. "k8s.io/kubernetes/pkg/labels"
  20. "k8s.io/kubernetes/pkg/util/wait"
  21. "k8s.io/kubernetes/test/e2e/framework"
  22. . "github.com/onsi/ginkgo"
  23. . "github.com/onsi/gomega"
  24. )
  25. var _ = framework.KubeDescribe("Mesos", func() {
  26. f := framework.NewDefaultFramework("pods")
  27. var c *client.Client
  28. var ns string
  29. BeforeEach(func() {
  30. framework.SkipUnlessProviderIs("mesos/docker")
  31. c = f.Client
  32. ns = f.Namespace.Name
  33. })
  34. It("applies slave attributes as labels", func() {
  35. nodeClient := f.Client.Nodes()
  36. rackA := labels.SelectorFromSet(map[string]string{"k8s.mesosphere.io/attribute-rack": "1"})
  37. options := api.ListOptions{LabelSelector: rackA}
  38. nodes, err := nodeClient.List(options)
  39. if err != nil {
  40. framework.Failf("Failed to query for node: %v", err)
  41. }
  42. Expect(len(nodes.Items)).To(Equal(1))
  43. var addr string
  44. for _, a := range nodes.Items[0].Status.Addresses {
  45. if a.Type == api.NodeInternalIP {
  46. addr = a.Address
  47. }
  48. }
  49. Expect(len(addr)).NotTo(Equal(""))
  50. })
  51. It("starts static pods on every node in the mesos cluster", func() {
  52. client := f.Client
  53. framework.ExpectNoError(framework.AllNodesReady(client, wait.ForeverTestTimeout), "all nodes ready")
  54. nodelist := framework.GetReadySchedulableNodesOrDie(f.Client)
  55. const ns = "static-pods"
  56. numpods := int32(len(nodelist.Items))
  57. framework.ExpectNoError(framework.WaitForPodsRunningReady(client, ns, numpods, wait.ForeverTestTimeout, map[string]string{}),
  58. fmt.Sprintf("number of static pods in namespace %s is %d", ns, numpods))
  59. })
  60. It("schedules pods annotated with roles on correct slaves", func() {
  61. // launch a pod to find a node which can launch a pod. We intentionally do
  62. // not just take the node list and choose the first of them. Depending on the
  63. // cluster and the scheduler it might be that a "normal" pod cannot be
  64. // scheduled onto it.
  65. By("Trying to launch a pod with a label to get a node which can launch it.")
  66. podName := "with-label"
  67. _, err := c.Pods(ns).Create(&api.Pod{
  68. TypeMeta: unversioned.TypeMeta{
  69. Kind: "Pod",
  70. },
  71. ObjectMeta: api.ObjectMeta{
  72. Name: podName,
  73. Annotations: map[string]string{
  74. "k8s.mesosphere.io/roles": "public",
  75. },
  76. },
  77. Spec: api.PodSpec{
  78. Containers: []api.Container{
  79. {
  80. Name: podName,
  81. Image: framework.GetPauseImageName(f.Client),
  82. },
  83. },
  84. },
  85. })
  86. framework.ExpectNoError(err)
  87. framework.ExpectNoError(framework.WaitForPodNameRunningInNamespace(c, podName, ns))
  88. pod, err := c.Pods(ns).Get(podName)
  89. framework.ExpectNoError(err)
  90. nodeClient := f.Client.Nodes()
  91. // schedule onto node with rack=2 being assigned to the "public" role
  92. rack2 := labels.SelectorFromSet(map[string]string{
  93. "k8s.mesosphere.io/attribute-rack": "2",
  94. })
  95. options := api.ListOptions{LabelSelector: rack2}
  96. nodes, err := nodeClient.List(options)
  97. framework.ExpectNoError(err)
  98. Expect(nodes.Items[0].Name).To(Equal(pod.Spec.NodeName))
  99. })
  100. })