示例#1
0
func createPodsOrDie(cs *release_1_4.Clientset, ns string, n int) {
	for i := 0; i < n; i++ {
		pod := &api.Pod{
			ObjectMeta: api.ObjectMeta{
				Name:      fmt.Sprintf("pod-%d", i),
				Namespace: ns,
				Labels:    map[string]string{"foo": "bar"},
			},
			Spec: api.PodSpec{
				Containers: []api.Container{
					{
						Name:  "busybox",
						Image: "gcr.io/google_containers/echoserver:1.4",
					},
				},
				RestartPolicy: api.RestartPolicyAlways,
			},
		}

		_, err := cs.Pods(ns).Create(pod)
		framework.ExpectNoError(err, "Creating pod %q in namespace %q", pod.Name, ns)
	}
}
示例#2
0
		// that means the controller is working.
		err := wait.PollImmediate(framework.Poll, 60*time.Second, func() (bool, error) {
			pdb, err := cs.Policy().PodDisruptionBudgets(ns).Get("foo")
			if err != nil {
				return false, err
			}
			return pdb.Status.PodDisruptionAllowed, nil
		})
		Expect(err).NotTo(HaveOccurred())

	})

	It("should allow an eviction when there is no PDB", func() {
		createPodsOrDie(cs, ns, 1)

		pod, err := cs.Pods(ns).Get("pod-0")
		Expect(err).NotTo(HaveOccurred())

		e := &policy.Eviction{
			ObjectMeta: api.ObjectMeta{
				Name:      pod.Name,
				Namespace: ns,
			},
		}

		err = cs.Pods(ns).Evict(e)
		Expect(err).NotTo(HaveOccurred())
	})

	It("should not allow an eviction when too few pods", func() {
		createPodDisruptionBudgetOrDie(cs, ns, intstr.FromInt(2))
示例#3
0
			expectation = "should not allow an eviction"
		}
		It(fmt.Sprintf("evictions: %s => %s", c.description, expectation), func() {
			createPodsOrDie(cs, ns, c.podCount)
			if c.replicaSetSize > 0 {
				createReplicaSetOrDie(cs, ns, c.replicaSetSize, c.exclusive)
			}

			if c.minAvailable.String() != "" {
				createPodDisruptionBudgetOrDie(cs, ns, c.minAvailable)
			}

			// Locate a running pod.
			var pod api.Pod
			err := wait.PollImmediate(framework.Poll, schedulingTimeout, func() (bool, error) {
				podList, err := cs.Pods(ns).List(apiapi.ListOptions{})
				if err != nil {
					return false, err
				}

				for i := range podList.Items {
					if podList.Items[i].Status.Phase == api.PodRunning {
						pod = podList.Items[i]
						return true, nil
					}
				}

				return false, nil
			})
			Expect(err).NotTo(HaveOccurred())
示例#4
0
					Name:      fmt.Sprintf("pod-%d", i),
					Namespace: ns,
					Labels:    map[string]string{"foo": "bar"},
				},
				Spec: api.PodSpec{
					Containers: []api.Container{
						{
							Name:  "busybox",
							Image: "gcr.io/google_containers/echoserver:1.4",
						},
					},
					RestartPolicy: api.RestartPolicyAlways,
				},
			}

			_, err := cs.Pods(ns).Create(pod)
			framework.ExpectNoError(err, "Creating pod %q in namespace %q", pod.Name, ns)
		}
		err = wait.PollImmediate(framework.Poll, 60*time.Second, func() (bool, error) {
			pdb, err := cs.Policy().PodDisruptionBudgets(ns).Get("foo")
			if err != nil {
				return false, err
			}
			return pdb.Status.PodDisruptionAllowed, nil
		})
		Expect(err).NotTo(HaveOccurred())

	})

})