Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#123 from ZeroMagic/mismatching
Browse files Browse the repository at this point in the history
fix: return empty when the specify source volume id does not exist
  • Loading branch information
k8s-ci-robot authored Jul 12, 2019
2 parents 9be575a + 888db51 commit d7ae3eb
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 d7ae3eb

Please sign in to comment.