Skip to content

Commit 0e5dd6b

Browse files
committed
Watch for failing expansion using different function
1 parent de5e496 commit 0e5dd6b

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

test/e2e/storage/csimock/csi_volume_expansion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ func validateRecoveryBehaviour(ctx context.Context, pvc *v1.PersistentVolumeClai
569569
func validateExpansionSuccess(ctx context.Context, pvc *v1.PersistentVolumeClaim, m *mockDriverSetup, test recoveryTest, expectedAllocatedSize string) {
570570
var err error
571571
ginkgo.By(fmt.Sprintf("Waiting for PV %s to be expanded to %s", pvc.Spec.VolumeName, test.recoverySize.String()))
572-
err = testsuites.WaitForRecoveryPVSize(pvc, m.cs, csiResizeWaitPeriod)
572+
err = testsuites.WaitForControllerVolumeResize(ctx, pvc, m.cs, csiResizeWaitPeriod)
573573
framework.ExpectNoError(err, "While waiting for PV resize to finish")
574574

575575
ginkgo.By(fmt.Sprintf("Waiting for PVC %s to be expanded to %s", pvc.Name, test.recoverySize.String()))

test/e2e/storage/testsuites/volume_expand.go

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver storageframework.TestDriver,
184184
newSize := currentPvcSize.DeepCopy()
185185
newSize.Add(resource.MustParse("1Gi"))
186186
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)
188188
gomega.Expect(err).To(gomega.MatchError(apierrors.IsForbidden, "While updating non-expandable PVC"))
189189
})
190190
} else {
@@ -343,6 +343,42 @@ func ExpandPVCSize(ctx context.Context, origPVC *v1.PersistentVolumeClaim, size
343343
return updatedPVC, nil
344344
}
345345

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+
346382
// WaitForResizingCondition waits for the pvc condition to be PersistentVolumeClaimResizing
347383
func WaitForResizingCondition(ctx context.Context, pvc *v1.PersistentVolumeClaim, c clientset.Interface, duration time.Duration) error {
348384
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
392428
return nil
393429
}
394430

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-
423431
// WaitForPendingFSResizeCondition waits for pvc to have resize condition
424432
func WaitForPendingFSResizeCondition(ctx context.Context, pvc *v1.PersistentVolumeClaim, c clientset.Interface) (*v1.PersistentVolumeClaim, error) {
425433
var updatedPVC *v1.PersistentVolumeClaim
@@ -451,9 +459,9 @@ func WaitForPendingFSResizeCondition(ctx context.Context, pvc *v1.PersistentVolu
451459
// WaitForFSResize waits for the filesystem in the pv to be resized
452460
func WaitForFSResize(ctx context.Context, pvc *v1.PersistentVolumeClaim, c clientset.Interface) (*v1.PersistentVolumeClaim, error) {
453461
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) {
455463
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{})
457465

458466
if err != nil {
459467
return false, fmt.Errorf("error fetching pvc %q for checking for resize status : %w", pvc.Name, err)

0 commit comments

Comments
 (0)