@@ -184,7 +184,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver storageframework.TestDriver,
184
184
newSize := currentPvcSize .DeepCopy ()
185
185
newSize .Add (resource .MustParse ("1Gi" ))
186
186
framework .Logf ("currentPvcSize %v, newSize %v" , currentPvcSize , newSize )
187
- _ , err = ExpandPVCSize (ctx , l .resource .Pvc , newSize , f .ClientSet )
187
+ _ , err = ExpandPVCSizeToError (ctx , l .resource .Pvc , newSize , f .ClientSet )
188
188
gomega .Expect (err ).To (gomega .MatchError (apierrors .IsForbidden , "While updating non-expandable PVC" ))
189
189
})
190
190
} else {
@@ -343,6 +343,42 @@ func ExpandPVCSize(ctx context.Context, origPVC *v1.PersistentVolumeClaim, size
343
343
return updatedPVC , nil
344
344
}
345
345
346
+ func ExpandPVCSizeToError (ctx context.Context , origPVC * v1.PersistentVolumeClaim , size resource.Quantity , c clientset.Interface ) (* v1.PersistentVolumeClaim , error ) {
347
+ pvcName := origPVC .Name
348
+ updatedPVC := origPVC .DeepCopy ()
349
+
350
+ var lastUpdateError error
351
+
352
+ waitErr := wait .PollUntilContextTimeout (ctx , resizePollInterval , 30 * time .Second , true , func (pollContext context.Context ) (bool , error ) {
353
+ var err error
354
+ updatedPVC , err = c .CoreV1 ().PersistentVolumeClaims (origPVC .Namespace ).Get (pollContext , pvcName , metav1.GetOptions {})
355
+ if err != nil {
356
+ return false , fmt .Errorf ("error fetching pvc %q for resizing: %w" , pvcName , err )
357
+ }
358
+
359
+ updatedPVC .Spec .Resources .Requests [v1 .ResourceStorage ] = size
360
+ updatedPVC , err = c .CoreV1 ().PersistentVolumeClaims (origPVC .Namespace ).Update (pollContext , updatedPVC , metav1.UpdateOptions {})
361
+ if err == nil {
362
+ return false , fmt .Errorf ("pvc %s should not be allowed to be updated" , pvcName )
363
+ } else {
364
+ lastUpdateError = err
365
+ if apierrors .IsForbidden (err ) {
366
+ return true , nil
367
+ }
368
+ framework .Logf ("Error updating pvc %s: %v" , pvcName , err )
369
+ return false , nil
370
+ }
371
+ })
372
+
373
+ if wait .Interrupted (waitErr ) {
374
+ return nil , fmt .Errorf ("timed out attempting to update PVC size. last update error: %w" , lastUpdateError )
375
+ }
376
+ if waitErr != nil {
377
+ return nil , fmt .Errorf ("failed to expand PVC size (check logs for error): %w" , waitErr )
378
+ }
379
+ return updatedPVC , lastUpdateError
380
+ }
381
+
346
382
// WaitForResizingCondition waits for the pvc condition to be PersistentVolumeClaimResizing
347
383
func WaitForResizingCondition (ctx context.Context , pvc * v1.PersistentVolumeClaim , c clientset.Interface , duration time.Duration ) error {
348
384
waitErr := wait .PollUntilContextTimeout (ctx , resizePollInterval , duration , true , func (ctx context.Context ) (bool , error ) {
@@ -392,34 +428,6 @@ func WaitForControllerVolumeResize(ctx context.Context, pvc *v1.PersistentVolume
392
428
return nil
393
429
}
394
430
395
- // WaitForRecoveryPVSize waits for the controller resize to be finished when we are reducing volume size
396
- // This is different from WaitForControllerVolumeResize which just waits for PV to report bigger size than
397
- // size requested.
398
- func WaitForRecoveryPVSize (pvc * v1.PersistentVolumeClaim , c clientset.Interface , timeout time.Duration ) error {
399
- pvName := pvc .Spec .VolumeName
400
- waitErr := wait .PollImmediate (resizePollInterval , timeout , func () (bool , error ) {
401
- pvcSpecSize := pvc .Spec .Resources .Requests .Storage ()
402
-
403
- pv , err := c .CoreV1 ().PersistentVolumes ().Get (context .TODO (), pvName , metav1.GetOptions {})
404
- if err != nil {
405
- return false , fmt .Errorf ("error fetching pv %q for resizing %v" , pvName , err )
406
- }
407
-
408
- pvSize := pv .Spec .Capacity [v1 .ResourceStorage ]
409
-
410
- // If pv size is greater than what is mentioned in pvc's status that means control-plane
411
- // volume expansion is finished.
412
- if pvSize .Cmp (* pvcSpecSize ) == 0 {
413
- return true , nil
414
- }
415
- return false , nil
416
- })
417
- if waitErr != nil {
418
- return fmt .Errorf ("error while waiting for controller resize to finish: %v" , waitErr )
419
- }
420
- return nil
421
- }
422
-
423
431
// WaitForPendingFSResizeCondition waits for pvc to have resize condition
424
432
func WaitForPendingFSResizeCondition (ctx context.Context , pvc * v1.PersistentVolumeClaim , c clientset.Interface ) (* v1.PersistentVolumeClaim , error ) {
425
433
var updatedPVC * v1.PersistentVolumeClaim
@@ -451,9 +459,9 @@ func WaitForPendingFSResizeCondition(ctx context.Context, pvc *v1.PersistentVolu
451
459
// WaitForFSResize waits for the filesystem in the pv to be resized
452
460
func WaitForFSResize (ctx context.Context , pvc * v1.PersistentVolumeClaim , c clientset.Interface ) (* v1.PersistentVolumeClaim , error ) {
453
461
var updatedPVC * v1.PersistentVolumeClaim
454
- waitErr := wait .PollImmediate ( resizePollInterval , totalResizeWaitPeriod , func () (bool , error ) {
462
+ waitErr := wait .PollUntilContextTimeout ( ctx , resizePollInterval , totalResizeWaitPeriod , true , func (pollContext context. Context ) (bool , error ) {
455
463
var err error
456
- updatedPVC , err = c .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Get (context . TODO () , pvc .Name , metav1.GetOptions {})
464
+ updatedPVC , err = c .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Get (pollContext , pvc .Name , metav1.GetOptions {})
457
465
458
466
if err != nil {
459
467
return false , fmt .Errorf ("error fetching pvc %q for checking for resize status : %w" , pvc .Name , err )
0 commit comments