Skip to content

Commit

Permalink
Merge pull request #293 from tsmetana/err-on-missing-snapshot
Browse files Browse the repository at this point in the history
Return correct error when restoring non-existent snapshot
  • Loading branch information
bertinatto committed May 7, 2019
2 parents e539e1b + 745f54f commit 61128d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func (c *cloud) CreateDisk(ctx context.Context, volumeName string, diskOptions *

response, err := c.ec2.CreateVolumeWithContext(ctx, request)
if err != nil {
if isAWSErrorSnapshotNotFound(err) {
return nil, ErrNotFound
}
return nil, fmt.Errorf("could not create volume in EC2: %v", err)
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol

disk, err = d.cloud.CreateDisk(ctx, volName, opts)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not create volume %q: %v", volName, err)
errCode := codes.Internal
if err == cloud.ErrNotFound {
errCode = codes.NotFound
}
return nil, status.Errorf(errCode, "Could not create volume %q: %v", volName, err)
}
disk.FsType = fsType
return newCreateVolumeResponse(disk), nil
Expand Down

0 comments on commit 61128d6

Please sign in to comment.