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

Add check for volumecontent source in CreateVolume #148

Merged
merged 2 commits into from
Feb 13, 2020

Conversation

Madhu-1
Copy link
Contributor

@Madhu-1 Madhu-1 commented Feb 12, 2020

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change
/kind bug
/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

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?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 12, 2020
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 12, 2020
@Madhu-1
Copy link
Contributor Author

Madhu-1 commented Feb 12, 2020

/assign @jsafrane
/assign @msau42

@jsafrane
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 12, 2020
}
if srcVolume := contentSource.GetVolume(); srcVolume != nil {
err = loadFromVolume(srcVolume.GetVolumeId(), path)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why extra space?

}
default:
err = fmt.Errorf("%v not a proper volume source", volumeSource)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra blank line

@Madhu-1 Madhu-1 force-pushed the add-parent-check branch 2 times, most recently from 30e5e00 to 87399b0 Compare February 12, 2020 08:58
@Madhu-1
Copy link
Contributor Author

Madhu-1 commented Feb 12, 2020

@jsafrane removed extra blank lines

@@ -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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra blank line?

default:
err = fmt.Errorf("%v not a proper volume source", volumeSource)
}
return nil, status.Error(codes.InvalidArgument, err.Error())
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes correct, fixed now

pkg/hostpath/controllerserver.go Outdated Show resolved Hide resolved
@Madhu-1 Madhu-1 force-pushed the add-parent-check branch 3 times, most recently from 3054761 to f16a8b2 Compare February 12, 2020 09:12
Copy link
Contributor

@jsafrane jsafrane left a 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 ifs?

err = fmt.Errorf("%v not a proper volume source", volumeSource)
}
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
Copy link
Contributor

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.

Copy link
Contributor Author

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

Comment on lines 130 to 132
if exVol.VolSize >= int64(req.GetCapacityRange().GetRequiredBytes()) {
// exisiting volume is compatible with new request and should be reused.
if req.GetVolumeContentSource() != nil {
Copy link
Contributor

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 ifs 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{}

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@Madhu-1 Madhu-1 force-pushed the add-parent-check branch 5 times, most recently from 443ca59 to b9ac9cb Compare February 12, 2020 09:56
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 12, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 12, 2020
@Madhu-1
Copy link
Contributor Author

Madhu-1 commented Feb 13, 2020

@jsafrane @humblec PTAL

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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.
@jsafrane
Copy link
Contributor

/lgtm
/approve
Thanks for the patience :-)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 13, 2020
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 13, 2020
@Madhu-1
Copy link
Contributor Author

Madhu-1 commented Feb 13, 2020

/retest

@k8s-ci-robot k8s-ci-robot merged commit b9f759c into kubernetes-csi:master Feb 13, 2020
TerryHowe pushed a commit to TerryHowe/csi-driver-host-path that referenced this pull request Oct 17, 2024
…o-prow

prow.sh: enable -csi.checkpathcmd option in csi-sanity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants