mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Remove the generation altering code - validate an update for a PDB by running ValidatePodDisruptionBudget only.
This commit is contained in:
@@ -122,111 +122,6 @@ func TestValidatePodDisruptionBudgetStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatePodDisruptionBudgetUpdate(t *testing.T) {
|
||||
c1 := intstr.FromString("10%")
|
||||
c2 := intstr.FromInt(1)
|
||||
c3 := intstr.FromInt(2)
|
||||
oldPdb := &policy.PodDisruptionBudget{}
|
||||
pdb := &policy.PodDisruptionBudget{}
|
||||
testCases := []struct {
|
||||
generations []int64
|
||||
name string
|
||||
specs []policy.PodDisruptionBudgetSpec
|
||||
status []policy.PodDisruptionBudgetStatus
|
||||
ok bool
|
||||
}{
|
||||
{
|
||||
name: "only update status",
|
||||
generations: []int64{int64(2), int64(3)},
|
||||
specs: []policy.PodDisruptionBudgetSpec{
|
||||
{
|
||||
MinAvailable: &c1,
|
||||
},
|
||||
{
|
||||
MinAvailable: &c1,
|
||||
},
|
||||
},
|
||||
status: []policy.PodDisruptionBudgetStatus{
|
||||
{
|
||||
PodDisruptionsAllowed: 10,
|
||||
CurrentHealthy: 5,
|
||||
ExpectedPods: 2,
|
||||
},
|
||||
{
|
||||
PodDisruptionsAllowed: 8,
|
||||
CurrentHealthy: 5,
|
||||
DesiredHealthy: 3,
|
||||
},
|
||||
},
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
name: "update pdb spec causing clash",
|
||||
generations: []int64{int64(2), int64(3)},
|
||||
specs: []policy.PodDisruptionBudgetSpec{
|
||||
{
|
||||
MaxUnavailable: &c2,
|
||||
},
|
||||
{
|
||||
MinAvailable: &c1,
|
||||
MaxUnavailable: &c3,
|
||||
},
|
||||
},
|
||||
status: []policy.PodDisruptionBudgetStatus{
|
||||
{
|
||||
PodDisruptionsAllowed: 10,
|
||||
},
|
||||
{
|
||||
PodDisruptionsAllowed: 10,
|
||||
},
|
||||
},
|
||||
ok: false,
|
||||
},
|
||||
{
|
||||
name: "update spec and status",
|
||||
generations: []int64{int64(2), int64(3)},
|
||||
specs: []policy.PodDisruptionBudgetSpec{
|
||||
{
|
||||
MaxUnavailable: &c2,
|
||||
},
|
||||
{
|
||||
MaxUnavailable: &c3,
|
||||
},
|
||||
},
|
||||
status: []policy.PodDisruptionBudgetStatus{
|
||||
{
|
||||
PodDisruptionsAllowed: 10,
|
||||
CurrentHealthy: 5,
|
||||
ExpectedPods: 2,
|
||||
},
|
||||
{
|
||||
PodDisruptionsAllowed: 8,
|
||||
CurrentHealthy: 5,
|
||||
DesiredHealthy: 3,
|
||||
},
|
||||
},
|
||||
ok: true,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
oldPdb.Spec = tc.specs[0]
|
||||
oldPdb.Generation = tc.generations[0]
|
||||
oldPdb.Status = tc.status[0]
|
||||
|
||||
pdb.Spec = tc.specs[1]
|
||||
pdb.Generation = tc.generations[1]
|
||||
pdb.Status = tc.status[1]
|
||||
|
||||
errs := ValidatePodDisruptionBudgetUpdate(pdb, oldPdb)
|
||||
if tc.ok && len(errs) > 0 {
|
||||
t.Errorf("[%d:%s] unexpected errors: %v", i, tc.name, errs)
|
||||
} else if !tc.ok && len(errs) == 0 {
|
||||
t.Errorf("[%d:%s] expected errors: %v", i, tc.name, errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatePodSecurityPolicy(t *testing.T) {
|
||||
validPSP := func() *policy.PodSecurityPolicy {
|
||||
return &policy.PodSecurityPolicy{
|
||||
|
||||
Reference in New Issue
Block a user