From ef573703634f186fe3c4693982540a073ad3b1a7 Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Thu, 26 Feb 2026 09:39:51 -0700 Subject: [PATCH] DNM, sseago eyes --- pkg/util/csi/volume_snapshot.go | 137 ++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 58 deletions(-) diff --git a/pkg/util/csi/volume_snapshot.go b/pkg/util/csi/volume_snapshot.go index 4e4103efa8..a6202a5b93 100644 --- a/pkg/util/csi/volume_snapshot.go +++ b/pkg/util/csi/volume_snapshot.go @@ -604,74 +604,95 @@ func WaitUntilVSCHandleIsReady( return vsc, nil } - // We'll wait 10m for the VSC to be reconciled polling - // every 5s unless backup's csiSnapshotTimeout is set + // Poll every 1s for the first 10s to catch fast CSI drivers, + // then fall back to every 5s for the remainder of csiSnapshotTimeout. + fastInterval := 1 * time.Second + fastPhaseDuration := 10 * time.Second interval := 5 * time.Second + currentInterval := fastInterval vsc := new(snapshotv1api.VolumeSnapshotContent) - err := wait.PollUntilContextTimeout( - context.Background(), - interval, - csiSnapshotTimeout, - true, - func(ctx context.Context) (bool, error) { - vs := new(snapshotv1api.VolumeSnapshot) - if err := crClient.Get( - ctx, - crclient.ObjectKeyFromObject(volSnap), - vs, - ); err != nil { - return false, - errors.Wrapf( - err, - "failed to get volumesnapshot %s/%s", - volSnap.Namespace, volSnap.Name, - ) - } + condFunc := func(ctx context.Context) (bool, error) { + vs := new(snapshotv1api.VolumeSnapshot) + if err := crClient.Get( + ctx, + crclient.ObjectKeyFromObject(volSnap), + vs, + ); err != nil { + return false, + errors.Wrapf( + err, + "failed to get volumesnapshot %s/%s", + volSnap.Namespace, volSnap.Name, + ) + } - if vs.Status == nil || vs.Status.BoundVolumeSnapshotContentName == nil { - log.Infof("Waiting for CSI driver to reconcile volumesnapshot %s/%s. Retrying in %ds", - volSnap.Namespace, volSnap.Name, interval/time.Second) - return false, nil - } + if vs.Status == nil || vs.Status.BoundVolumeSnapshotContentName == nil { + log.Infof("Waiting for CSI driver to reconcile volumesnapshot %s/%s. Retrying in %ds", + volSnap.Namespace, volSnap.Name, currentInterval/time.Second) + return false, nil + } - if err := crClient.Get( - ctx, - crclient.ObjectKey{ - Name: *vs.Status.BoundVolumeSnapshotContentName, - }, - vsc, - ); err != nil { - return false, - errors.Wrapf( - err, - "failed to get VolumeSnapshotContent %s for VolumeSnapshot %s/%s", - *vs.Status.BoundVolumeSnapshotContentName, vs.Namespace, vs.Name, - ) - } + if err := crClient.Get( + ctx, + crclient.ObjectKey{ + Name: *vs.Status.BoundVolumeSnapshotContentName, + }, + vsc, + ); err != nil { + return false, + errors.Wrapf( + err, + "failed to get VolumeSnapshotContent %s for VolumeSnapshot %s/%s", + *vs.Status.BoundVolumeSnapshotContentName, vs.Namespace, vs.Name, + ) + } - // we need to wait for the VolumeSnapshotContent - // to have a snapshot handle because during restore, - // we'll use that snapshot handle as the source for - // the VolumeSnapshotContent so it's statically - // bound to the existing snapshot. - if vsc.Status == nil || - vsc.Status.SnapshotHandle == nil { - log.Infof( - "Waiting for VolumeSnapshotContents %s to have snapshot handle. Retrying in %ds", - vsc.Name, interval/time.Second) - if vsc.Status != nil && - vsc.Status.Error != nil { - log.Warnf("VolumeSnapshotContent %s has error: %v", - vsc.Name, *vsc.Status.Error.Message) - } - return false, nil + // we need to wait for the VolumeSnapshotContent + // to have a snapshot handle because during restore, + // we'll use that snapshot handle as the source for + // the VolumeSnapshotContent so it's statically + // bound to the existing snapshot. + if vsc.Status == nil || + vsc.Status.SnapshotHandle == nil { + log.Infof( + "Waiting for VolumeSnapshotContents %s to have snapshot handle. Retrying in %ds", + vsc.Name, currentInterval/time.Second) + if vsc.Status != nil && + vsc.Status.Error != nil { + log.Warnf("VolumeSnapshotContent %s has error: %v", + vsc.Name, *vsc.Status.Error.Message) } + return false, nil + } - return true, nil - }, + return true, nil + } + + phase1Timeout := fastPhaseDuration + if phase1Timeout > csiSnapshotTimeout { + phase1Timeout = csiSnapshotTimeout + } + + err := wait.PollUntilContextTimeout( + context.Background(), + fastInterval, + phase1Timeout, + true, + condFunc, ) + if err != nil && wait.Interrupted(err) && csiSnapshotTimeout > fastPhaseDuration { + currentInterval = interval + err = wait.PollUntilContextTimeout( + context.Background(), + interval, + csiSnapshotTimeout-fastPhaseDuration, + true, + condFunc, + ) + } + if err != nil { if wait.Interrupted(err) { if vsc != nil &&