Fix incorrect disk sizes during VMware VM import#140
Conversation
Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com>
There was a problem hiding this comment.
Pull request overview
Adjusts VMware VM import logic so disk sizes are derived from the VM’s hardware configuration (per-disk capacity) rather than relying on NFC lease item sizes, which can represent aggregate VM capacity in some environments.
Changes:
- Retrieves
config.hardware.devicefrom vCenter and builds a lookup ofVirtualDiskdevices. - Determines per-disk size using
VirtualDisk.CapacityInKB(bytes = KB * 1024) and falls back to leaseSizeif mapping fails. - Adds
parseDeviceIdhelper to map lease items to hardware disks by(bus, unit).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com>
Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com>
ibrokethecloud
left a comment
There was a problem hiding this comment.
i was able to verify the disk sizes via a simple unit test
/Users/gauravmehta/go/src/github.com/harvester/vm-import-controller/pkg/source/vmware/client_test.go:621: disk from vm obj disk-0.vmdk: size 42949672960
/Users/gauravmehta/go/src/github.com/harvester/vm-import-controller/pkg/source/vmware/client_test.go:622: disk from lease disk-0.vmdk: size 48318382080
/Users/gauravmehta/go/src/github.com/harvester/vm-import-controller/pkg/source/vmware/client_test.go:621: disk from vm obj disk-1.vmdk: size 5368709120
/Users/gauravmehta/go/src/github.com/harvester/vm-import-controller/pkg/source/vmware/client_test.go:622: disk from lease disk-1.vmdk: size 48318382080
the vm obj does reflect the correct disk size, compared to the lease object.
Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com>
|
|
||
| unit64, err := strconv.ParseInt(colon[1], 10, 32) | ||
| if err != nil { | ||
| return |
There was a problem hiding this comment.
minor nit, should we also log the error here so we know which device was skipped?
There was a problem hiding this comment.
I don't think this is necessary because some lines below where the parseDeviceId function is called a log message is generated when the code is using the fallback path:
if diskSize == 0 {
// fallback to lease size if mapping failed
logrus.WithFields(logrus.Fields{
"name": vm.Name, "namespace": vm.Namespace,
"path": i.Path,
"deviceId": i.DeviceId,
"size": i.Size,
}).Warn("Failed to map lease VMDK to VirtualDisk capacity; falling back to lease item size")
diskSize = i.Size
}
This log message contains all relevant info that is necessary to know what happened.
|
@Mergifyio backport v1.8 |
✅ Backports have been createdDetails
|
* vmware: determine disk size from VM hardware instead of NFC lease Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com> (cherry picked from commit d540117) * apply suggestions Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com> (cherry picked from commit 2852e6a) * apply suggestions Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com> (cherry picked from commit 6869512) * add test for parseDeviceID and some comments Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com> (cherry picked from commit fd6f2e0) --------- Signed-off-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com> Co-authored-by: Samuel Vasconcelos <samuel.vasconcelos@suse.com>
Problem:
When importing virtual machines from VMware vCenter, the vm-import-controller determines disk sizes using nfc.LeaseItem.Size. In some VMware environments this value represents the total provisioned capacity of the VM, not the size of the individual disk.
As a result, each imported disk may incorrectly receive the aggregate VM size, causing PVCs to be over-provisioned and migrations to fail due to insufficient storage.
Solution:
Disk capacities are now determined using the VM hardware configuration retrieved from:
mo.VirtualMachine.Config.Hardware.DeviceFor each VirtualDisk, the code reads:VirtualDisk.CapacityInKB and maps disks to lease items using the busNumber.Related Issue:
harvester/harvester#10167
Test plan:
Observations
on the previous PR, we couldn't match the key, so we now matching the busNumber since is unique per controller instance in hardware model.