diff --git a/internal/backup/volumesnapshot_action.go b/internal/backup/volumesnapshot_action.go index 1e78e0e1..caac4f39 100644 --- a/internal/backup/volumesnapshot_action.go +++ b/internal/backup/volumesnapshot_action.go @@ -95,7 +95,7 @@ func (p *VolumeSnapshotBackupItemAction) Execute(item runtime.Unstructured, back p.Log.Infof("Getting VolumesnapshotContent for Volumesnapshot %s/%s", vs.Namespace, vs.Name) - vsc, err := util.GetVolumeSnapshotContentForVolumeSnapshot(&vs, snapshotClient.SnapshotV1(), p.Log, backupOngoing) + vsc, err := util.GetVolumeSnapshotContentForVolumeSnapshot(&vs, snapshotClient.SnapshotV1(), p.Log, backupOngoing, backup.Spec.CSISnapshotTimeout.Duration) if err != nil { util.CleanupVolumeSnapshot(&vs, snapshotClient.SnapshotV1(), p.Log) return nil, nil, "", nil, errors.WithStack(err) diff --git a/internal/util/util.go b/internal/util/util.go index f70aaf1c..e6bcdcf2 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -43,7 +43,8 @@ import ( ) const ( - VolumeSnapshotKindName = "VolumeSnapshot" + VolumeSnapshotKindName = "VolumeSnapshot" + defaultCSISnapshotTimeout = 10 * time.Minute ) func GetPVForPVC(pvc *corev1api.PersistentVolumeClaim, corev1 corev1client.PersistentVolumesGetter) (*corev1api.PersistentVolume, error) { @@ -150,7 +151,7 @@ func GetVolumeSnapshotClassForStorageClass(provisioner string, snapshotClient sn } // GetVolumeSnapshotContentForVolumeSnapshot returns the volumesnapshotcontent object associated with the volumesnapshot -func GetVolumeSnapshotContentForVolumeSnapshot(volSnap *snapshotv1api.VolumeSnapshot, snapshotClient snapshotter.SnapshotV1Interface, log logrus.FieldLogger, shouldWait bool) (*snapshotv1api.VolumeSnapshotContent, error) { +func GetVolumeSnapshotContentForVolumeSnapshot(volSnap *snapshotv1api.VolumeSnapshot, snapshotClient snapshotter.SnapshotV1Interface, log logrus.FieldLogger, shouldWait bool, csiSnapshotTimeout time.Duration) (*snapshotv1api.VolumeSnapshotContent, error) { if !shouldWait { if volSnap.Status == nil || volSnap.Status.BoundVolumeSnapshotContentName == nil { // volumesnapshot hasn't been reconciled and we're not waiting for it. @@ -163,9 +164,11 @@ func GetVolumeSnapshotContentForVolumeSnapshot(volSnap *snapshotv1api.VolumeSnap return vsc, nil } - // We'll wait 10m for the VSC to be reconciled polling every 5s - // TODO: make this timeout configurable. - timeout := 10 * time.Minute + // We'll wait 10m for the VSC to be reconciled polling every 5s unless csiSnapshotTimeout is set + timeout := defaultCSISnapshotTimeout + if csiSnapshotTimeout > 0 { + timeout = csiSnapshotTimeout + } interval := 5 * time.Second var snapshotContent *snapshotv1api.VolumeSnapshotContent diff --git a/internal/util/util_test.go b/internal/util/util_test.go index a415a86b..0bae9e73 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -918,7 +918,7 @@ func TestGetVolumeSnapshotContentForVolumeSnapshot(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - actualVSC, actualError := GetVolumeSnapshotContentForVolumeSnapshot(tc.volSnap, fakeClient.SnapshotV1(), logrus.New().WithField("fake", "test"), tc.wait) + actualVSC, actualError := GetVolumeSnapshotContentForVolumeSnapshot(tc.volSnap, fakeClient.SnapshotV1(), logrus.New().WithField("fake", "test"), tc.wait, 0) if tc.expectError && actualError == nil { assert.NotNil(t, actualError) assert.Nil(t, actualVSC)