Skip to content

Commit

Permalink
Use CSISnapshotTimeout to set the snapshot timeout
Browse files Browse the repository at this point in the history
Signed-off-by: David Zaninovic <[email protected]>
  • Loading branch information
dzaninovic committed Jun 28, 2023
1 parent 6b59bde commit 28e840b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/backup/volumesnapshot_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 28e840b

Please sign in to comment.