Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check all snapshots for existence #240

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[[GH-243]](https://github.com/digitalocean/csi-digitalocean/pull/243)
* Use WARN log level for non-critical failures to get an action
[[GH-241]](https://github.com/digitalocean/csi-digitalocean/pull/241)
* Check all snapshots for existence
[[GH-240]](https://github.com/digitalocean/csi-digitalocean/pull/240)
* Return error when fetching the snapshot fails
[[GH-233]](https://github.com/digitalocean/csi-digitalocean/pull/233)
* Reject requests for block access type
Expand Down
45 changes: 31 additions & 14 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,25 +642,42 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
log.Info("create snapshot is called")

// get snapshot first, if it's created do no thing
snapshots, _, err := d.storage.ListSnapshots(ctx, req.GetSourceVolumeId(), nil)
if err != nil {
return nil, status.Errorf(codes.Internal, "couldn't fetch snapshots: %s", err.Error())

opts := &godo.ListOptions{
Page: 1,
PerPage: 50,
}
for {
snapshots, resp, err := d.storage.ListSnapshots(ctx, req.GetSourceVolumeId(), opts)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list snapshots on page %d: %s", opts.Page, err)
}

for _, snap := range snapshots {
if snap.Name == req.GetName() && snap.ResourceID == req.GetSourceVolumeId() {
s, err := toCSISnapshot(&snap)
if err != nil {
return nil, status.Errorf(codes.Internal,
"couldn't convert DO snapshot to CSI snapshot: %s", err.Error())
}
for _, snap := range snapshots {
if snap.Name == req.GetName() && snap.ResourceID == req.GetSourceVolumeId() {
s, err := toCSISnapshot(&snap)
if err != nil {
return nil, status.Errorf(codes.Internal,
"failed to convert DO snapshot %q to CSI snapshot: %s", snap.Name, err)
}

snapResp := &csi.CreateSnapshotResponse{
Snapshot: s,
snapResp := &csi.CreateSnapshotResponse{
Snapshot: s,
}
log.WithField("response", snapResp).Info("existing snapshot found")
return snapResp, nil
}
log.WithField("response", snapResp).Info("existing snapshot found")
return snapResp, nil
}

if resp.Links == nil || resp.Links.IsLastPage() {
break
}

page, err := resp.Links.CurrentPage()
if err != nil {
return nil, fmt.Errorf("failed to get current page: %s", err)
}
opts.Page = page + 1
}

snapReq := &godo.SnapshotCreateRequest{
Expand Down