diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue index be545945fcf..68b46bb2881 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue @@ -140,8 +140,10 @@ export default { onImageChange() { const imageResource = this.$store.getters['harvester/all'](HCI.IMAGE)?.find( I => this.value.image === I.id); + const isIsoImage = /iso$/i.test(imageResource?.imageSuffix); + const imageSize = Math.max(imageResource?.status?.size, imageResource?.status?.virtualSize); - if (/iso$/i.test(imageResource?.imageSuffix)) { + if (isIsoImage) { this.$set(this.value, 'type', 'cd-rom'); this.$set(this.value, 'bus', 'sata'); } else { @@ -149,6 +151,15 @@ export default { this.$set(this.value, 'bus', 'virtio'); } + if (imageSize) { + let imageSizeGiB = Math.ceil(imageSize / 1024 / 1024 / 1024); + + if (!isIsoImage) { + imageSizeGiB = Math.max(imageSizeGiB, 10); + } + this.$set(this.value, 'size', `${ imageSizeGiB }Gi`); + } + this.update(); }, diff --git a/pkg/harvester/mixins/harvester-vm/index.js b/pkg/harvester/mixins/harvester-vm/index.js index 380ca00d767..17f0b729c6c 100644 --- a/pkg/harvester/mixins/harvester-vm/index.js +++ b/pkg/harvester/mixins/harvester-vm/index.js @@ -414,14 +414,26 @@ export default { if (_disks.length === 0) { let bus = 'virtio'; let type = HARD_DISK; + let size = '10Gi'; const imageResource = this.images.find( I => this.imageId === I.id); + const isIsoImage = /iso$/i.test(imageResource?.imageSuffix); + const imageSize = Math.max(imageResource?.status?.size, imageResource?.status?.virtualSize); - if (/iso$/i.test(imageResource?.imageSuffix)) { + if (isIsoImage) { bus = 'sata'; type = CD_ROM; } + if (imageSize) { + let imageSizeGiB = Math.ceil(imageSize / 1024 / 1024 / 1024); + + if (!isIsoImage) { + imageSizeGiB = Math.max(imageSizeGiB, 10); + } + size = `${ imageSizeGiB }Gi`; + } + out.push({ id: randomStr(5), source: SOURCE_TYPE.IMAGE, @@ -429,7 +441,7 @@ export default { accessMode: 'ReadWriteMany', bus, volumeName: '', - size: '10Gi', + size, type, storageClassName: '', image: this.imageId,