From 0ed234dbff3becfac9d35c08c84cf1892a2cad05 Mon Sep 17 00:00:00 2001 From: houjun Date: Fri, 31 Aug 2018 14:12:18 +0800 Subject: [PATCH] Add unit test case for controller/disruption --- pkg/controller/disruption/disruption_test.go | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkg/controller/disruption/disruption_test.go b/pkg/controller/disruption/disruption_test.go index 73426697768..f74295d626b 100644 --- a/pkg/controller/disruption/disruption_test.go +++ b/pkg/controller/disruption/disruption_test.go @@ -431,6 +431,31 @@ func TestIntegerMaxUnavailableWithScaling(t *testing.T) { ps.VerifyPdbStatus(t, pdbName, 0, 1, 3, 5, map[string]metav1.Time{}) } +// Verify that an percentage MaxUnavailable will recompute allowed disruptions when the scale of +// the selected pod's controller is modified. +func TestPercentageMaxUnavailableWithScaling(t *testing.T) { + dc, ps := newFakeDisruptionController() + + pdb, pdbName := newMaxUnavailablePodDisruptionBudget(t, intstr.FromString("30%")) + add(t, dc.pdbStore, pdb) + + rs, _ := newReplicaSet(t, 7) + add(t, dc.rsStore, rs) + + pod, _ := newPod(t, "pod") + updatePodOwnerToRs(t, pod, rs) + add(t, dc.podStore, pod) + dc.sync(pdbName) + ps.VerifyPdbStatus(t, pdbName, 0, 1, 4, 7, map[string]metav1.Time{}) + + // Update scale of ReplicaSet and check PDB + rs.Spec.Replicas = to.Int32Ptr(3) + update(t, dc.rsStore, rs) + + dc.sync(pdbName) + ps.VerifyPdbStatus(t, pdbName, 0, 1, 2, 3, map[string]metav1.Time{}) +} + // Create a pod with no controller, and verify that a PDB with a percentage // specified won't allow a disruption. func TestNakedPod(t *testing.T) {