-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add check for volumecontent source in CreateVolume #148
Conversation
Hi @Madhu-1. Thanks for your PR. I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
abfad08
to
f0d3ade
Compare
/ok-to-test |
pkg/hostpath/controllerserver.go
Outdated
} | ||
if srcVolume := contentSource.GetVolume(); srcVolume != nil { | ||
err = loadFromVolume(srcVolume.GetVolumeId(), path) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why extra space?
pkg/hostpath/controllerserver.go
Outdated
} | ||
default: | ||
err = fmt.Errorf("%v not a proper volume source", volumeSource) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra blank line
30e5e00
to
87399b0
Compare
@jsafrane removed extra blank lines |
pkg/hostpath/controllerserver.go
Outdated
@@ -129,6 +129,23 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol | |||
// request | |||
if exVol.VolSize >= int64(req.GetCapacityRange().GetRequiredBytes()) { | |||
// exisiting volume is compatible with new request and should be reused. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra blank line?
pkg/hostpath/controllerserver.go
Outdated
default: | ||
err = fmt.Errorf("%v not a proper volume source", volumeSource) | ||
} | ||
return nil, status.Error(codes.InvalidArgument, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This always returns error even if VolumeContentSource
was fine and err == nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes correct, fixed now
3054761
to
f16a8b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have spotted this earlier, but can you fix the nested if
s?
pkg/hostpath/controllerserver.go
Outdated
err = fmt.Errorf("%v not a proper volume source", volumeSource) | ||
} | ||
if err != nil { | ||
return nil, status.Error(codes.InvalidArgument, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In spirit of container-storage-interface/spec#412, the first two cases should return AlreadyExists, while the default
branch should return InvalidArgument. Moving return
to the cases would be IMO better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated code to return already exists
pkg/hostpath/controllerserver.go
Outdated
if exVol.VolSize >= int64(req.GetCapacityRange().GetRequiredBytes()) { | ||
// exisiting volume is compatible with new request and should be reused. | ||
if req.GetVolumeContentSource() != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not happy with nested if
s here.
IMO it would be better to do negative conditions:
if (size does not match){
return AlreadyExists
}
if (source is not empty)
... return AlreadyExists / InvalidArgument on mismatch ...
}
// everything matches
return &csi.CreateVolumeResponse{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I need to check
- content source is empty or not
- if not need empty check is it snapshot or volume or not
- if it is a snapshot or volume check id is matching
nothing content source is neither snapshot nor volume return error
updated with if
else if
and else
check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now i got it, making changes
443ca59
to
b9ac9cb
Compare
b9ac9cb
to
bad2de2
Compare
bad2de2
to
5fe37e0
Compare
5fe37e0
to
9a41fb9
Compare
pkg/hostpath/controllerserver.go
Outdated
switch volumeSource.Type.(type) { | ||
case *csi.VolumeContentSource_Snapshot: | ||
if volumeSource.GetSnapshot() != nil && exVol.ParentSnapID != volumeSource.GetSnapshot().GetSnapshotId() { | ||
err = status.Error(codes.AlreadyExists, "existing volume source snapshot id not matching") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: return
right here, no need to pass err
around. This applies to all cases + default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
If the returning error message doesnot require formatting, use errors.New(). the error message should not be capitalized, replace it with smaller case
If the volume is already found,we also need to check the volumecountent source id valid or not.
9a41fb9
to
366d752
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jsafrane, Madhu-1 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
…o-prow prow.sh: enable -csi.checkpathcmd option in csi-sanity
What type of PR is this?
What this PR does / why we need it:
If the volume is already found during create volume request,we also need to check the volume content source id valid or not.
If the returning error message doesn't require formatting, use errors.New().
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: