@@ -402,6 +402,109 @@ func TestExpandDuringMount(t *testing.T) {
402
402
})
403
403
}
404
404
}
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
+ }
405
508
406
509
func getTestPod (podName , pvcName string ) * v1.Pod {
407
510
return & v1.Pod {
0 commit comments