Skip to content

Commit

Permalink
fix: return empty when the specify source volume id does not exist
Browse files Browse the repository at this point in the history
Signed-off-by: ZeroMagic <[email protected]>
  • Loading branch information
ZeroMagic committed Jul 12, 2019
1 parent 9be575a commit 888db51
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,23 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("Unknown list snapshot error: %v", err))
}
match := false
entries := []*csi.ListSnapshotsResponse_Entry{}
for _, snapshot := range snapshotListPage.Values() {
if req.SourceVolumeId == getSourceVolumeId(&snapshot) {
match = true
}
csiSnapshot, err := generateCSISnapshot(req.SourceVolumeId, &snapshot)
if err != nil {
return nil, fmt.Errorf("failed to generate snapshot entry: %v", err)
}
entries = append(entries, &csi.ListSnapshotsResponse_Entry{Snapshot: csiSnapshot})
}
// return empty if SourceVolumeId is not empty and does not match the listed snapshot's SourceVolumeId
if req.SourceVolumeId != "" && !match {
return &csi.ListSnapshotsResponse{}, nil
}

nextToken := ""
if snapshotListPage.Response().NextLink != nil {
nextToken = *snapshotListPage.Response().NextLink
Expand Down

0 comments on commit 888db51

Please sign in to comment.