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

Take image virtual size into account when creating VMs #976

Merged
merged 4 commits into from
Aug 16, 2024

Conversation

tserong
Copy link

@tserong tserong commented Mar 20, 2024

Prior to this, the default size for volumes attached to VMs was 10GiB, regardless of the size of the underlying image. This is fine if the image is smaller, but if the image is either physically larger (as in the case of a >10GiB ISO), or has a larger virtual size (as can be true with qcow2 images), the result is a corrupt volume.

This PR fixes the problem by checking both the physical size and virtual size of the image, and using whichever is greater as the default size of the volume. Virtual size should always be >= physical size, but it is still theoretically possible for either value to be zero in case of error, so taking the greater of the two is the safest approach.

There are two exceptions to the above rule:

  1. For non-ISO images, if the image is < 10GiB, we still default to a size of 10GiB for consistency with the behaviour of earlier Harvester releases. The user can always lower this if they want/need to.
  2. ISO images smaller than 1GiB will be given a size of 1GiB, simply because the size control in the UI is set to work in GiB units. It is actually possible to get a value of 0.2 GiB in there for a 200MiB ISO, but doing that is pretty ugly IMO, and there's no real harm in having the volume that backs a CD-ROM image be a bit larger than the source in this case.

This PR also adds Virtual Size as an additional column when listing images. I don't know whether or not this is the best way to present this information. Another alternative could be to make the existing Size column simply report the greater of Size and Virtual Size, on the assumption that what you really care about is the size that a volume needs to be when based on that image.

I've included a couple other small tweaks as well relating to automatically setting disk type and bus for ISO images (see the commit messages for details).

Note that this PR depends on harvester/harvester#5387 which in turn depends on changes in Longhorn.

Related issue: harvester/harvester#5142
Related issue: harvester/harvester#4905
Related issue: harvester/harvester#2189

@tserong
Copy link
Author

tserong commented Mar 20, 2024

Example display of the Virtual Size column:

image

@tserong tserong marked this pull request as draft March 20, 2024 11:35
@tserong
Copy link
Author

tserong commented Mar 20, 2024

Apparently the tests need work... :-/

@tserong
Copy link
Author

tserong commented Mar 21, 2024

Gotta be careful with those ? thingies ;-)

@tserong tserong marked this pull request as ready for review May 24, 2024 01:47
@tserong
Copy link
Author

tserong commented May 24, 2024

Rebased on latest master. Relies on harvester/harvester#5387 which is not yet merged, but otherwise ready for review.

@tserong
Copy link
Author

tserong commented Jul 4, 2024

Updated to add Virtual Size to the image detail page (thanks for the suggestion @bk201)

image

@tserong tserong requested a review from votdev July 4, 2024 05:39
@tserong
Copy link
Author

tserong commented Jul 4, 2024

...and now that harvester/harvester#5387 is in, this is actually possible to test and good to review!

The onImageChange() function in
edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue
includes logic to set type="cd-rom" and bus="sata" when you select an
ISO image as the source for a volume.  This commit applies the same
logic when initially creating a VM from a given image.

Signed-off-by: Tim Serong <[email protected]>
The onImageChange() function sets the VM volume type="cd-rom" and
bus="sata" when an ISO image is selected, but it only works for
the first volume.  This commit enables the automatic type and bus
selection for all volumes attached to a VM.

Related issue: harvester/harvester#5142

Signed-off-by: Tim Serong <[email protected]>
Prior to this, the default size for volumes attached to VMs was 10GiB,
regardless of the size of the underlying image.  This is fine if the
image is smaller, but if the image is either physically larger (as in
the case of a >10GiB ISO), or has a larger virtual size (as can be true
with qcow2 images), the result is a corrupt volume.

This commit fixes the problem by checking both the physical size and
virtual size of the image, and using whichever is greater as the default
size of the volume.  Virtual size should always be >= physical size, but
it is still theoretically possible for either value to be zero in case
of error, so taking the greater of the two is the safest approach.

There are two exceptions to the above rule:

1) For non-ISO images, if the image is < 10GiB, we still default to a
   size of 10GiB for consistency with the behaviour of earlier Harvester
   releases.  The user can always lower this if they want/need to.

2) ISO images smaller than 1GiB will be given a size of 1GiB, simply
   because the size control in the UI is set to work in GiB units.  It is
   actually possible to get a value of 0.2 GiB in there for a 200MiB ISO,
   but doing that is pretty ugly IMO, and there's no real harm in having
   the volume that backs a CD-ROM image be a bit larger than the source
   in this case.

Related issue: harvester/harvester#4905
Related issue: harvester/harvester#2189

Signed-off-by: Tim Serong <[email protected]>
This commit adds Virtual Size as an additional column when listing
images.  I don't know whether or not this is the best way to present
this information.  Another alternative could be to make the existing
Size column simply report the greater of Size and Virtual Size, on
the assumption that what you really care about is the size that a
volume needs to be when based on that image.

I've also added Virtual Size to the Image Detail page.

Related issue: harvester/harvester#4905

Signed-off-by: Tim Serong <[email protected]>
@tserong
Copy link
Author

tserong commented Jul 18, 2024

Rebased on latest master

@tserong
Copy link
Author

tserong commented Aug 15, 2024

ping @a110605 @votdev when you have time :-)

Copy link
Member

@votdev votdev left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@a110605 a110605 left a comment

Choose a reason for hiding this comment

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

Test locally, LGTM.

Remember to backport to release-harvester-v1.4 after merge

@tserong tserong merged commit b97bf06 into master Aug 16, 2024
7 checks passed
@tserong
Copy link
Author

tserong commented Aug 16, 2024

@Mergifyio backport release-harvester-v1.4

@tserong tserong deleted the wip-add-virtualSize branch August 16, 2024 03:35
Copy link

mergify bot commented Aug 16, 2024

backport release-harvester-v1.4

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants