✨ Mount vm snapshot disk - #1857
Conversation
fc01553 to
c74b40e
Compare
Co-authored-by: Cursor <cursoragent@cursor.com>
22a2e4d to
bf97481
Compare
Co-authored-by: Cursor <cursoragent@cursor.com>
bf97481 to
661ea04
Compare
stevenhuang-vcf
left a comment
There was a problem hiding this comment.
You need to add more comments in the code.
| } else if volSpec.VirtualMachineSnapshot != nil { | ||
| // For snapshot volumes, we don't block power on for them being unattached here, as they are attached | ||
| // during the reconcile loop itself (in reconcileSnapshotDisks), unlike PVCs which | ||
| // are attached by an external controller. | ||
| // We also don't require them to be in status yet, as they might be added in the same reconcile loop. | ||
| continue |
There was a problem hiding this comment.
This else if is meaningless here as your description. So why not just add comments without the check of the spec type of VM snapshot disk?
| case *vimtypes.VirtualDiskSparseVer2BackingInfo: | ||
| return &vimtypes.VirtualDiskSparseVer2BackingInfo{VirtualDeviceFileBackingInfo: vimtypes.VirtualDeviceFileBackingInfo{FileName: backing.FileName}, DiskMode: string(vimtypes.VirtualDiskModeIndependent_nonpersistent), Parent: backing, Uuid: backing.Uuid} | ||
| default: | ||
| return targetDisk.Backing |
There was a problem hiding this comment.
should return the target backing info for a unsupported type?
Comparing the logic in isSnapshotDisk only VirtualDiskFlatVer2BackingInfo, VirtualDiskSeSparseBackingInfo and VirtualDiskSparseVer2BackingInfo are supported.
| if targetDisk == nil && len(moSnap.Config.Hardware.Device) == 0 && moVM.Config != nil { | ||
| for _, dev := range moVM.Config.Hardware.Device { | ||
| if disk, ok := dev.(*vimtypes.VirtualDisk); ok { | ||
| if strings.EqualFold(getVirtualDiskUUID(disk), diskID) { | ||
| targetDisk = disk | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Why need to look for a target snapshot disk in a VM's device list?
I think it should be in a VM snapshot's device list. Is there any specific case?
| } | ||
| } | ||
|
|
||
| if err := reconcileSnapshotDisks( |
| pkglog.FromContextOrDefault(ctx).Info("Appended new volume to status", "volName", volName, "newVolumesLen", len(vm.Status.Volumes)) | ||
| } | ||
|
|
||
| func isSnapshotDiskAttached(moVM mo.VirtualMachine, configSpec *vimtypes.VirtualMachineConfigSpec, diskID string) bool { |
There was a problem hiding this comment.
why not as setSnapshotVolumeAttached does, the check runs on the status list of volumes?
What does this PR do, and why is it needed?
VirtualMachineSnapshotDiskSpec is used to define a specific disk from a VirtualMachineSnapshot. VirtualMachineSnapshotDiskSpec field added in VirtualMachineVolumeSource is to support mounting a VirtualMachine snapshot disk as a volume of the VM service VM.
PASS
go test -v ./pkg/providers/vsphere/session/...
go test -v ./webhooks/virtualmachine/validation/...
go test -v ./controllers/virtualmachine/volume/...
Are there any special notes for your reviewer:
Expose the disk list in VirtualMachineSnapshot: #1744
CRD change of supporting VM snapshot disk as the volume source: #1751
Please add a release note if necessary:
Support mounting a VM snapshot disk as a VM volume. When using the VM Snapshot disk as the volume source, diskMode must be set to "IndependentNonPersistent" and removable must be set to true.