Skip to content

Commit

Permalink
Merge pull request #175 from catalogicsoftware/csi_snapshot_timeout
Browse files Browse the repository at this point in the history
Use CSISnapshotTimeout to set the snapshot timeout
  • Loading branch information
sseago committed Jun 29, 2023
2 parents 6b59bde + 28e840b commit aa8c2b7
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 aa8c2b7

Please sign in to comment.