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

Fix addvolume removevolume bugs #9133

Merged
merged 3 commits into from
Feb 4, 2023

Conversation

ShellyKa13
Copy link
Contributor

What this PR does / why we need it:

  • Fix bug of allowing to add existing volume pvc/dv with another volume name: the code checked for volume.Name instead of checking the dv/pvc name.
  • Fix bug of allowing to remove existing volume which wasnt hotplugged.
  • Add the check of add and remove volume to persistent add/remove volume code path - in case of add/remove to VM the checks should also happen.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes # Jira: CNV-23867
CNV-24856

Special notes for your reviewer:

Release note:

Fix addvolume not rejecting adding existing volume source, fix removevolume allowing to remove non hotpluggable volume

* Fix bug of allowing to add existing volume pvc/dv
with another volume name: the code checked for volume.Name
instead of checking the dv/pvc name.
* Fix bug of allowing to remove existing volume which wasnt
hotplugged.
* Add the check of add and remove volume to persistent add/remove
volume code path - in case of add/remove to VM the checks should also
happen.
* Add and fix current UT accordingly.

Signed-off-by: Shelly Kagan <skagan@redhat.com>
Signed-off-by: Shelly Kagan <skagan@redhat.com>
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/L labels Jan 31, 2023
}

func volumeNameExists(volume v1.Volume, volumeName string) bool {
if volume.Name == volumeName {
Copy link
Member

Choose a reason for hiding this comment

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

you can just

return volume.Name == volumeName

@@ -1052,30 +1052,92 @@ func addVolumeRequestExists(request v1.VirtualMachineVolumeRequest, name string)
return request.AddVolumeOptions != nil && request.AddVolumeOptions.Name == name
}

func generateVMIVolumeRequestPatch(vmi *v1.VirtualMachineInstance, volumeRequest *v1.VirtualMachineVolumeRequest) (string, error) {
func volumeHotpluggable(volume v1.Volume) bool {
if volume.DataVolume != nil && volume.DataVolume.Hotpluggable {
Copy link
Member

Choose a reason for hiding this comment

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

You can

return (volume.DataVolume != nil && volume.DataVolume.Hotpluggable) || (volume.PersistentVolumeClaim != nil && volume.PersistentVolumeClaim.Hotpluggable)

}

func volumeSourceExists(volume v1.Volume, volumeName string) bool {
if volume.DataVolume != nil && volume.DataVolume.Name == volumeName {
Copy link
Member

Choose a reason for hiding this comment

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

You can

return (volume.DataVolume != nil && volume.DataVolume.Name == volumeName) || (volume.PersistentVolumeClaim != nil && volume.PersistentVolumeClaim.ClaimName == volumeName)


func volumeExists(volume v1.Volume, volumeName string) bool {
if volumeNameExists(volume, volumeName) {
Copy link
Member

Choose a reason for hiding this comment

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

You can

return volumeNameExists(volume, volumeName) || volumeSourceExists(volume, volumeName)

})

It("should reject hotplugging the same volume with an existing volume name", func() {
dvBlock := createDataVolumeAndWaitForImport(sc, corev1.PersistentVolumeBlock)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this will work in a WFFC scenario. Since the code wait for the DV to be ready which will never happen. Maybe just create it and assume it is ready (blank ones usually are before you attempt to hotplug them)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@awels the create adds to the dv force bind annotation so it should be fine right?

Copy link
Member

Choose a reason for hiding this comment

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

Oh it does, hmm that might introduce other weirdness but most of these are single disks so it mostly should be fine.

Signed-off-by: Shelly Kagan <skagan@redhat.com>
@mhenriks
Copy link
Member

mhenriks commented Feb 2, 2023

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mhenriks

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 2, 2023
@awels
Copy link
Member

awels commented Feb 2, 2023

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 2, 2023
@awels
Copy link
Member

awels commented Feb 2, 2023

/retest-required

@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

4 similar comments
@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@kubevirt-bot
Copy link
Contributor

@ShellyKa13: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubevirt-fossa 6b4a40d link false /test pull-kubevirt-fossa
pull-kubevirt-e2e-k8s-1.25-sig-compute-migrations-root 6b4a40d link unknown /test pull-kubevirt-e2e-k8s-1.25-sig-compute-migrations-root
pull-kubevirt-e2e-k8s-1.25-sig-performance 6b4a40d link unknown /test pull-kubevirt-e2e-k8s-1.25-sig-performance
pull-kubevirt-e2e-k8s-1.24-sig-network 6b4a40d link unknown /test pull-kubevirt-e2e-k8s-1.24-sig-network

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. I understand the commands that are listed here.

@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@kubevirt-bot kubevirt-bot merged commit dd9bf7f into kubevirt:main Feb 4, 2023
@ShellyKa13
Copy link
Contributor Author

/cherrypick release-0.53

@kubevirt-bot
Copy link
Contributor

@ShellyKa13: #9133 failed to apply on top of branch "release-0.53":

Applying: Fix add/remove volume bugs
Using index info to reconstruct a base tree...
M	pkg/virt-api/rest/subresource.go
M	pkg/virt-api/rest/subresource_test.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/virt-api/rest/subresource_test.go
CONFLICT (content): Merge conflict in pkg/virt-api/rest/subresource_test.go
Auto-merging pkg/virt-api/rest/subresource.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix add/remove volume bugs
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherrypick release-0.53

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.

@ShellyKa13
Copy link
Contributor Author

/cherrypick release-0.59

@kubevirt-bot
Copy link
Contributor

@ShellyKa13: new pull request created: #9197

In response to this:

/cherrypick release-0.59

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.

@ShellyKa13
Copy link
Contributor Author

/cherrypick release-0.58

@kubevirt-bot
Copy link
Contributor

@ShellyKa13: #9133 failed to apply on top of branch "release-0.58":

Applying: Fix add/remove volume bugs
Using index info to reconstruct a base tree...
M	pkg/virt-api/rest/subresource.go
M	pkg/virt-api/rest/subresource_test.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/virt-api/rest/subresource_test.go
CONFLICT (content): Merge conflict in pkg/virt-api/rest/subresource_test.go
Auto-merging pkg/virt-api/rest/subresource.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix add/remove volume bugs
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherrypick release-0.58

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.

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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants