disruption.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. Copyright 2016 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. "time"
  17. . "github.com/onsi/ginkgo"
  18. . "github.com/onsi/gomega"
  19. release_1_4 "k8s.io/client-go/1.4/kubernetes"
  20. "k8s.io/client-go/1.4/pkg/api/unversioned"
  21. api "k8s.io/client-go/1.4/pkg/api/v1"
  22. policy "k8s.io/client-go/1.4/pkg/apis/policy/v1alpha1"
  23. "k8s.io/client-go/1.4/pkg/util/intstr"
  24. "k8s.io/kubernetes/pkg/util/wait"
  25. "k8s.io/kubernetes/test/e2e/framework"
  26. )
  27. var _ = framework.KubeDescribe("DisruptionController [Feature:PodDisruptionbudget]", func() {
  28. f := framework.NewDefaultFramework("disruption")
  29. var ns string
  30. var cs *release_1_4.Clientset
  31. BeforeEach(func() {
  32. cs = f.StagingClient
  33. ns = f.Namespace.Name
  34. })
  35. It("should create a PodDisruptionBudget", func() {
  36. pdb := policy.PodDisruptionBudget{
  37. ObjectMeta: api.ObjectMeta{
  38. Name: "foo",
  39. Namespace: ns,
  40. },
  41. Spec: policy.PodDisruptionBudgetSpec{
  42. Selector: &unversioned.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
  43. MinAvailable: intstr.FromString("1%"),
  44. },
  45. }
  46. _, err := cs.Policy().PodDisruptionBudgets(ns).Create(&pdb)
  47. Expect(err).NotTo(HaveOccurred())
  48. })
  49. It("should update PodDisruptionBudget status", func() {
  50. pdb := policy.PodDisruptionBudget{
  51. ObjectMeta: api.ObjectMeta{
  52. Name: "foo",
  53. Namespace: ns,
  54. },
  55. Spec: policy.PodDisruptionBudgetSpec{
  56. Selector: &unversioned.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
  57. MinAvailable: intstr.FromInt(2),
  58. },
  59. }
  60. _, err := cs.Policy().PodDisruptionBudgets(ns).Create(&pdb)
  61. Expect(err).NotTo(HaveOccurred())
  62. for i := 0; i < 2; i++ {
  63. pod := &api.Pod{
  64. ObjectMeta: api.ObjectMeta{
  65. Name: fmt.Sprintf("pod-%d", i),
  66. Namespace: ns,
  67. Labels: map[string]string{"foo": "bar"},
  68. },
  69. Spec: api.PodSpec{
  70. Containers: []api.Container{
  71. {
  72. Name: "busybox",
  73. Image: "gcr.io/google_containers/echoserver:1.4",
  74. },
  75. },
  76. RestartPolicy: api.RestartPolicyAlways,
  77. },
  78. }
  79. _, err := cs.Pods(ns).Create(pod)
  80. framework.ExpectNoError(err, "Creating pod %q in namespace %q", pod.Name, ns)
  81. }
  82. err = wait.PollImmediate(framework.Poll, 60*time.Second, func() (bool, error) {
  83. pdb, err := cs.Policy().PodDisruptionBudgets(ns).Get("foo")
  84. if err != nil {
  85. return false, err
  86. }
  87. return pdb.Status.PodDisruptionAllowed, nil
  88. })
  89. Expect(err).NotTo(HaveOccurred())
  90. })
  91. })