PDB MaxUnavailable: e2e tests

This commit is contained in:
Anirudh 2017-05-15 16:51:00 -07:00
parent 078f9566d9
commit 63e51dc66e
3 changed files with 63 additions and 21 deletions

View File

@ -478,6 +478,7 @@ func runDrainTest(f *framework.Framework, migSizes map[string]int, podsPerNode,
defer framework.DeleteRCAndPods(f.ClientSet, f.InternalClientset, f.Namespace.Name, "reschedulable-pods") defer framework.DeleteRCAndPods(f.ClientSet, f.InternalClientset, f.Namespace.Name, "reschedulable-pods")
By("Create a PodDisruptionBudget") By("Create a PodDisruptionBudget")
minAvailable := intstr.FromInt(numPods - pdbSize)
pdb := &policy.PodDisruptionBudget{ pdb := &policy.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "test_pdb", Name: "test_pdb",
@ -485,7 +486,7 @@ func runDrainTest(f *framework.Framework, migSizes map[string]int, podsPerNode,
}, },
Spec: policy.PodDisruptionBudgetSpec{ Spec: policy.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{MatchLabels: labelMap}, Selector: &metav1.LabelSelector{MatchLabels: labelMap},
MinAvailable: intstr.FromInt(numPods - pdbSize), MinAvailable: &minAvailable,
}, },
} }
_, err = f.StagingClient.Policy().PodDisruptionBudgets(namespace).Create(pdb) _, err = f.StagingClient.Policy().PodDisruptionBudgets(namespace).Create(pdb)

View File

@ -52,11 +52,11 @@ var _ = framework.KubeDescribe("DisruptionController", func() {
}) })
It("should create a PodDisruptionBudget", func() { It("should create a PodDisruptionBudget", func() {
createPodDisruptionBudgetOrDie(cs, ns, intstr.FromString("1%")) createPDBMinAvailableOrDie(cs, ns, intstr.FromString("1%"))
}) })
It("should update PodDisruptionBudget status", func() { It("should update PodDisruptionBudget status", func() {
createPodDisruptionBudgetOrDie(cs, ns, intstr.FromInt(2)) createPDBMinAvailableOrDie(cs, ns, intstr.FromInt(2))
createPodsOrDie(cs, ns, 3) createPodsOrDie(cs, ns, 3)
waitForPodsOrDie(cs, ns, 3) waitForPodsOrDie(cs, ns, 3)
@ -71,12 +71,12 @@ var _ = framework.KubeDescribe("DisruptionController", func() {
return pdb.Status.PodDisruptionsAllowed > 0, nil return pdb.Status.PodDisruptionsAllowed > 0, nil
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
evictionCases := []struct { evictionCases := []struct {
description string description string
minAvailable intstr.IntOrString minAvailable intstr.IntOrString
maxUnavailable intstr.IntOrString
podCount int podCount int
replicaSetSize int32 replicaSetSize int32
shouldDeny bool shouldDeny bool
@ -86,27 +86,50 @@ var _ = framework.KubeDescribe("DisruptionController", func() {
{ {
description: "no PDB", description: "no PDB",
minAvailable: intstr.FromString(""), minAvailable: intstr.FromString(""),
maxUnavailable: intstr.FromString(""),
podCount: 1, podCount: 1,
shouldDeny: false, shouldDeny: false,
}, { }, {
description: "too few pods, absolute", description: "too few pods, absolute",
minAvailable: intstr.FromInt(2), minAvailable: intstr.FromInt(2),
maxUnavailable: intstr.FromString(""),
podCount: 2, podCount: 2,
shouldDeny: true, shouldDeny: true,
}, { }, {
description: "enough pods, absolute", description: "enough pods, absolute",
minAvailable: intstr.FromInt(2), minAvailable: intstr.FromInt(2),
maxUnavailable: intstr.FromString(""),
podCount: 3, podCount: 3,
shouldDeny: false, shouldDeny: false,
}, { }, {
description: "enough pods, replicaSet, percentage", description: "enough pods, replicaSet, percentage",
minAvailable: intstr.FromString("90%"), minAvailable: intstr.FromString("90%"),
maxUnavailable: intstr.FromString(""),
replicaSetSize: 10, replicaSetSize: 10,
exclusive: false, exclusive: false,
shouldDeny: false, shouldDeny: false,
}, { }, {
description: "too few pods, replicaSet, percentage", description: "too few pods, replicaSet, percentage",
minAvailable: intstr.FromString("90%"), minAvailable: intstr.FromString("90%"),
maxUnavailable: intstr.FromString(""),
replicaSetSize: 10,
exclusive: true,
shouldDeny: true,
// This tests assumes that there is less than replicaSetSize nodes in the cluster.
skipForBigClusters: true,
},
{
description: "maxUnavailable allow single eviction, percentage",
minAvailable: intstr.FromString(""),
maxUnavailable: intstr.FromString("10%"),
replicaSetSize: 10,
exclusive: false,
shouldDeny: false,
},
{
description: "maxUnavailable deny evictions, integer",
minAvailable: intstr.FromString(""),
maxUnavailable: intstr.FromInt(1),
replicaSetSize: 10, replicaSetSize: 10,
exclusive: true, exclusive: true,
shouldDeny: true, shouldDeny: true,
@ -130,7 +153,11 @@ var _ = framework.KubeDescribe("DisruptionController", func() {
} }
if c.minAvailable.String() != "" { if c.minAvailable.String() != "" {
createPodDisruptionBudgetOrDie(cs, ns, c.minAvailable) createPDBMinAvailableOrDie(cs, ns, c.minAvailable)
}
if c.maxUnavailable.String() != "" {
createPDBMaxUnavailableOrDie(cs, ns, c.maxUnavailable)
} }
// Locate a running pod. // Locate a running pod.
@ -186,10 +213,9 @@ var _ = framework.KubeDescribe("DisruptionController", func() {
} }
}) })
} }
}) })
func createPodDisruptionBudgetOrDie(cs *kubernetes.Clientset, ns string, minAvailable intstr.IntOrString) { func createPDBMinAvailableOrDie(cs *kubernetes.Clientset, ns string, minAvailable intstr.IntOrString) {
pdb := policy.PodDisruptionBudget{ pdb := policy.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "foo", Name: "foo",
@ -197,7 +223,22 @@ func createPodDisruptionBudgetOrDie(cs *kubernetes.Clientset, ns string, minAvai
}, },
Spec: policy.PodDisruptionBudgetSpec{ Spec: policy.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}}, Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
MinAvailable: minAvailable, MinAvailable: &minAvailable,
},
}
_, err := cs.Policy().PodDisruptionBudgets(ns).Create(&pdb)
Expect(err).NotTo(HaveOccurred())
}
func createPDBMaxUnavailableOrDie(cs *kubernetes.Clientset, ns string, maxUnavailable intstr.IntOrString) {
pdb := policy.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: ns,
},
Spec: policy.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
MaxUnavailable: &maxUnavailable,
}, },
} }
_, err := cs.Policy().PodDisruptionBudgets(ns).Create(&pdb) _, err := cs.Policy().PodDisruptionBudgets(ns).Create(&pdb)

View File

@ -200,7 +200,7 @@ func newPDB() *v1beta1.PodDisruptionBudget {
Name: "test-pdb", Name: "test-pdb",
}, },
Spec: v1beta1.PodDisruptionBudgetSpec{ Spec: v1beta1.PodDisruptionBudgetSpec{
MinAvailable: intstr.IntOrString{ MinAvailable: &intstr.IntOrString{
Type: intstr.Int, Type: intstr.Int,
IntVal: 0, IntVal: 0,
}, },