StatefulSet: fix kube-controller-manager panic due to StatefulSetPersistentVolumeClaimRetentionPolicy being nil

This commit is contained in:
Mengjiao Liu
2022-10-26 18:50:52 +08:00
parent bb12faf15b
commit b9740694f3
2 changed files with 7 additions and 2 deletions

View File

@@ -123,6 +123,8 @@ func runTestOverPVCRetentionPolicies(t *testing.T, testName string, testFn func(
WhenScaled: apps.DeletePersistentVolumeClaimRetentionPolicyType,
WhenDeleted: apps.DeletePersistentVolumeClaimRetentionPolicyType,
},
// tests the case when no policy is set.
nil,
} {
subtestName := pvcDeletePolicyString(policy) + "/StatefulSetAutoDeletePVCEnabled"
if testName != "" {
@@ -136,6 +138,9 @@ func runTestOverPVCRetentionPolicies(t *testing.T, testName string, testFn func(
}
func pvcDeletePolicyString(policy *apps.StatefulSetPersistentVolumeClaimRetentionPolicy) string {
if policy == nil {
return "nullPolicy"
}
const retain = apps.RetainPersistentVolumeClaimRetentionPolicyType
const delete = apps.DeletePersistentVolumeClaimRetentionPolicyType
switch {