mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #113358 from mengjiao-liu/fix-StatefulSetAutoDeletePVC
StatefulSet: fix kube-controller-manager panic due to StatefulSetPersistentVolumeClaimRetentionPolicy being nil
This commit is contained in:
commit
9b5fa57654
@ -123,6 +123,8 @@ func runTestOverPVCRetentionPolicies(t *testing.T, testName string, testFn func(
|
|||||||
WhenScaled: apps.DeletePersistentVolumeClaimRetentionPolicyType,
|
WhenScaled: apps.DeletePersistentVolumeClaimRetentionPolicyType,
|
||||||
WhenDeleted: apps.DeletePersistentVolumeClaimRetentionPolicyType,
|
WhenDeleted: apps.DeletePersistentVolumeClaimRetentionPolicyType,
|
||||||
},
|
},
|
||||||
|
// tests the case when no policy is set.
|
||||||
|
nil,
|
||||||
} {
|
} {
|
||||||
subtestName := pvcDeletePolicyString(policy) + "/StatefulSetAutoDeletePVCEnabled"
|
subtestName := pvcDeletePolicyString(policy) + "/StatefulSetAutoDeletePVCEnabled"
|
||||||
if testName != "" {
|
if testName != "" {
|
||||||
@ -136,6 +138,9 @@ func runTestOverPVCRetentionPolicies(t *testing.T, testName string, testFn func(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pvcDeletePolicyString(policy *apps.StatefulSetPersistentVolumeClaimRetentionPolicy) string {
|
func pvcDeletePolicyString(policy *apps.StatefulSetPersistentVolumeClaimRetentionPolicy) string {
|
||||||
|
if policy == nil {
|
||||||
|
return "nullPolicy"
|
||||||
|
}
|
||||||
const retain = apps.RetainPersistentVolumeClaimRetentionPolicyType
|
const retain = apps.RetainPersistentVolumeClaimRetentionPolicyType
|
||||||
const delete = apps.DeletePersistentVolumeClaimRetentionPolicyType
|
const delete = apps.DeletePersistentVolumeClaimRetentionPolicyType
|
||||||
switch {
|
switch {
|
||||||
|
@ -149,7 +149,7 @@ func getPersistentVolumeClaimRetentionPolicy(set *apps.StatefulSet) apps.Statefu
|
|||||||
// claimOwnerMatchesSetAndPod returns false if the ownerRefs of the claim are not set consistently with the
|
// claimOwnerMatchesSetAndPod returns false if the ownerRefs of the claim are not set consistently with the
|
||||||
// PVC deletion policy for the StatefulSet.
|
// PVC deletion policy for the StatefulSet.
|
||||||
func claimOwnerMatchesSetAndPod(claim *v1.PersistentVolumeClaim, set *apps.StatefulSet, pod *v1.Pod) bool {
|
func claimOwnerMatchesSetAndPod(claim *v1.PersistentVolumeClaim, set *apps.StatefulSet, pod *v1.Pod) bool {
|
||||||
policy := set.Spec.PersistentVolumeClaimRetentionPolicy
|
policy := getPersistentVolumeClaimRetentionPolicy(set)
|
||||||
const retain = apps.RetainPersistentVolumeClaimRetentionPolicyType
|
const retain = apps.RetainPersistentVolumeClaimRetentionPolicyType
|
||||||
const delete = apps.DeletePersistentVolumeClaimRetentionPolicyType
|
const delete = apps.DeletePersistentVolumeClaimRetentionPolicyType
|
||||||
switch {
|
switch {
|
||||||
@ -211,7 +211,7 @@ func updateClaimOwnerRefForSetAndPod(claim *v1.PersistentVolumeClaim, set *apps.
|
|||||||
updateMeta(&podMeta, "Pod")
|
updateMeta(&podMeta, "Pod")
|
||||||
setMeta := set.TypeMeta
|
setMeta := set.TypeMeta
|
||||||
updateMeta(&setMeta, "StatefulSet")
|
updateMeta(&setMeta, "StatefulSet")
|
||||||
policy := set.Spec.PersistentVolumeClaimRetentionPolicy
|
policy := getPersistentVolumeClaimRetentionPolicy(set)
|
||||||
const retain = apps.RetainPersistentVolumeClaimRetentionPolicyType
|
const retain = apps.RetainPersistentVolumeClaimRetentionPolicyType
|
||||||
const delete = apps.DeletePersistentVolumeClaimRetentionPolicyType
|
const delete = apps.DeletePersistentVolumeClaimRetentionPolicyType
|
||||||
switch {
|
switch {
|
||||||
|
Loading…
Reference in New Issue
Block a user