Skip to content

Commit 023aa81

Browse files
authored
feat(block): allow waiting for specific snapshot status (scaleway#2334)
1 parent 87e7668 commit 023aa81

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

api/block/v1alpha1/snapshot_utils.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ type WaitForSnapshotRequest struct {
1414
Zone scw.Zone
1515
Timeout *time.Duration
1616
RetryInterval *time.Duration
17+
18+
// If set, will wait until this specific status has been reached or the
19+
// snapshot has an error status. This is useful when we need to wait for
20+
// the snapshot to transition from "in_use" to "available".
21+
TerminalStatus *SnapshotStatus
1722
}
1823

1924
// WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning.
@@ -28,11 +33,16 @@ func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest, opts ...scw.RequestOp
2833
}
2934

3035
terminalStatus := map[SnapshotStatus]struct{}{
31-
SnapshotStatusAvailable: {},
32-
SnapshotStatusInUse: {},
33-
SnapshotStatusError: {},
34-
SnapshotStatusLocked: {},
35-
SnapshotStatusDeleted: {},
36+
SnapshotStatusError: {},
37+
SnapshotStatusLocked: {},
38+
SnapshotStatusDeleted: {},
39+
}
40+
41+
if req.TerminalStatus != nil {
42+
terminalStatus[*req.TerminalStatus] = struct{}{}
43+
} else {
44+
terminalStatus[SnapshotStatusAvailable] = struct{}{}
45+
terminalStatus[SnapshotStatusInUse] = struct{}{}
3646
}
3747

3848
snapshot, err := async.WaitSync(&async.WaitSyncConfig{

0 commit comments

Comments
 (0)