Skip to content

Commit 0bec23c

Browse files
committed
Check for newer fields when deciding expansion recovery feature status
1 parent d5df907 commit 0bec23c

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

pkg/volume/util/operationexecutor/operation_generator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,11 @@ func (og *operationGenerator) checkForRecoveryFromExpansion(pvc *v1.PersistentVo
20752075
featureGateStatus := utilfeature.DefaultFeatureGate.Enabled(features.RecoverVolumeExpansionFailure)
20762076

20772077
if !featureGateStatus {
2078+
// even though RecoverVolumeExpansionFailure feature-gate is disabled, we should consider it enabled
2079+
// if resizeStatus is not empty or allocatedresources is set
2080+
if resizeStatus != "" || allocatedResource != nil {
2081+
return true
2082+
}
20782083
return false
20792084
}
20802085

pkg/volume/util/operationexecutor/operation_generator_test.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,109 @@ func TestExpandDuringMount(t *testing.T) {
402402
})
403403
}
404404
}
405+
func TestCheckForRecoveryFromExpansion(t *testing.T) {
406+
tests := []struct {
407+
name string
408+
pvc *v1.PersistentVolumeClaim
409+
featureGateEnabled bool
410+
expectedRecoveryCheck bool
411+
}{
412+
{
413+
name: "feature gate disabled, no resize status or allocated resources",
414+
pvc: &v1.PersistentVolumeClaim{
415+
ObjectMeta: metav1.ObjectMeta{
416+
Name: "test-pvc-1",
417+
},
418+
Status: v1.PersistentVolumeClaimStatus{
419+
AllocatedResourceStatuses: nil,
420+
AllocatedResources: nil,
421+
},
422+
},
423+
featureGateEnabled: false,
424+
expectedRecoveryCheck: false,
425+
},
426+
{
427+
name: "feature gate disabled, resize status set",
428+
pvc: &v1.PersistentVolumeClaim{
429+
ObjectMeta: metav1.ObjectMeta{
430+
Name: "test-pvc-2",
431+
},
432+
Status: v1.PersistentVolumeClaimStatus{
433+
AllocatedResourceStatuses: map[v1.ResourceName]v1.ClaimResourceStatus{
434+
v1.ResourceStorage: v1.PersistentVolumeClaimNodeResizePending,
435+
},
436+
},
437+
},
438+
featureGateEnabled: false,
439+
expectedRecoveryCheck: true,
440+
},
441+
{
442+
name: "feature gate enabled, resize status and allocated resources set",
443+
pvc: &v1.PersistentVolumeClaim{
444+
ObjectMeta: metav1.ObjectMeta{
445+
Name: "test-pvc-3",
446+
},
447+
Status: v1.PersistentVolumeClaimStatus{
448+
AllocatedResourceStatuses: map[v1.ResourceName]v1.ClaimResourceStatus{
449+
v1.ResourceStorage: v1.PersistentVolumeClaimNodeResizePending,
450+
},
451+
AllocatedResources: v1.ResourceList{
452+
v1.ResourceStorage: resource.MustParse("10Gi"),
453+
},
454+
},
455+
},
456+
featureGateEnabled: true,
457+
expectedRecoveryCheck: true,
458+
},
459+
{
460+
name: "feature gate enabled, no resize status or allocated resources",
461+
pvc: &v1.PersistentVolumeClaim{
462+
ObjectMeta: metav1.ObjectMeta{
463+
Name: "test-pvc-4",
464+
},
465+
Status: v1.PersistentVolumeClaimStatus{
466+
AllocatedResourceStatuses: nil,
467+
AllocatedResources: nil,
468+
},
469+
},
470+
featureGateEnabled: true,
471+
expectedRecoveryCheck: false,
472+
},
473+
{
474+
name: "feature gate enabled, older external resize controller",
475+
pvc: &v1.PersistentVolumeClaim{
476+
ObjectMeta: metav1.ObjectMeta{
477+
Name: "test-pvc-5",
478+
},
479+
Status: v1.PersistentVolumeClaimStatus{
480+
AllocatedResourceStatuses: nil,
481+
AllocatedResources: nil,
482+
},
483+
},
484+
featureGateEnabled: true,
485+
expectedRecoveryCheck: false,
486+
},
487+
}
488+
489+
for _, test := range tests {
490+
t.Run(test.name, func(t *testing.T) {
491+
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.RecoverVolumeExpansionFailure, test.featureGateEnabled)
492+
493+
pod := getTestPod("test-pod", test.pvc.Name)
494+
pv := getTestPV("test-vol0", "2G")
495+
og := &operationGenerator{}
496+
497+
vmt := VolumeToMount{
498+
Pod: pod,
499+
VolumeName: v1.UniqueVolumeName(pv.Name),
500+
VolumeSpec: volume.NewSpecFromPersistentVolume(pv, false),
501+
}
502+
result := og.checkForRecoveryFromExpansion(test.pvc, vmt)
503+
504+
assert.Equal(t, test.expectedRecoveryCheck, result, "unexpected recovery check result for test: %s", test.name)
505+
})
506+
}
507+
}
405508

406509
func getTestPod(podName, pvcName string) *v1.Pod {
407510
return &v1.Pod{

0 commit comments

Comments
 (0)