diff --git a/pkg/controller/disruption/disruption_test.go b/pkg/controller/disruption/disruption_test.go index add3140869..fdd92d8b6c 100644 --- a/pkg/controller/disruption/disruption_test.go +++ b/pkg/controller/disruption/disruption_test.go @@ -430,6 +430,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) {