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
[Bug fix] Reject VM defined with volume with no matching disk #5585
[Bug fix] Reject VM defined with volume with no matching disk #5585
Conversation
} | ||
|
||
// Validate that volumes match disks correctly | ||
for idx, volume := range spec.Volumes { |
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.
OK! this ensures there's always a disk if a volume exists.
Is the reflexive case required? Do we need a volume if a disk exists?
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.
The reflexive case is already being checked a few lines above (line 877) and there's also a test covering it
This appears to be something we could explicitly test for at the functional test level as well. |
|
||
// Validate that volumes match disks correctly | ||
for idx, volume := range spec.Volumes { | ||
if _, machingDiskExists := diskNames[volume.Name]; !machingDiskExists { |
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.
@iholder-redhat volumes can also match spec.Domain.Devices.Filesystems
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.
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.
Thanks!
diskNames
is now diskAndFilesystemNames
and contain both fs and disk names :)
9e504ef
to
68046b5
Compare
@stu-gott I've added functional tests :) |
/retest |
/test pull-kubevirt-e2e-k8s-1.17-rook-ceph |
Signed-off-by: Itamar Holder <iholder@redhat.com>
68046b5
to
d9d46ca
Compare
/test pull-kubevirt-unit-test |
@@ -861,12 +861,14 @@ func validateNetworkHasOnlyOneType(field *k8sfield.Path, cniTypesCount int, caus | |||
func validateBootOrder(field *k8sfield.Path, spec *v1.VirtualMachineInstanceSpec, volumeNameMap map[string]*v1.Volume) (bootOrderMap map[uint]bool, causes []metav1.StatusCause) { | |||
// used to validate uniqueness of boot orders among disks and interfaces | |||
bootOrderMap = make(map[uint]bool) | |||
// to perform as set of volume / fs names | |||
diskAndFilesystemNames := make(map[string]interface{}) |
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: I think it's somewhat more idiomatic/common to use a map[string]struct{}
, and then "signal the presence" of a disk/fs by having a diskAndFilesystemNames[disk.Name] = struct{}{}
.
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.
Cool. I'm still new to Go, so good to know :)
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.
Here's a related post by the prophet Dave Cheney:
https://dave.cheney.net/2014/03/25/the-empty-struct
|
||
// Validate that volumes match disks and filesystems correctly | ||
for idx, volume := range spec.Volumes { | ||
if _, machingDiskExists := diskAndFilesystemNames[volume.Name]; !machingDiskExists { |
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.
typo-nit: machingDiskExists
--> matchingDiskExists
Addresses this bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1954667 Signed-off-by: Itamar Holder <iholder@redhat.com>
d9d46ca
to
cd67593
Compare
/retest |
It's worthy to mention that for plain Kubernetes pods, it's perfectly legal to define a pod volume but no volumeMount. The justification for that is unclear to me, and still it has been like that for years and there seem to be no open/closed bug about it. Nevertheless, we can do better than pods. Thanks @iholder-redhat! |
Thank @iholder-redhat |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vladikr 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 |
/cherry-pick release-0.41 |
/cherry-pick release-0.36 |
@xpivarc: #5585 failed to apply on top of branch "release-0.36":
In response to this:
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. |
What this PR does / why we need it:
Reject VM defined with volume with no matching disk.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Bugzilla bug: https://bugzilla.redhat.com/show_bug.cgi?id=1954667
Github issue: #5556
Release note: