Skip to content

✨ Mount vm snapshot disk - #1857

Draft
cc005511 wants to merge 3 commits into
vmware-tanzu:mainfrom
cc005511:mount_vm_snapshot_disk
Draft

✨ Mount vm snapshot disk#1857
cc005511 wants to merge 3 commits into
vmware-tanzu:mainfrom
cc005511:mount_vm_snapshot_disk

Conversation

@cc005511

@cc005511 cc005511 commented Aug 27, 2026

Copy link
Copy Markdown

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.

  • Only one member (virtualMachineSnapshot or persistentVolumeClaim) of VirtualMachineVolumeSource could be specified at a time. The webhook validation will reject a VirtualMachineVolume whose source sets both persistentVolumeClaim and virtualMachineSnapshot.
  • If virtualMachineSnapshot is set in VirtualMachineVolumeSource, the requester must have the permission to get, create, or delete VM snapshot in the VM snapshot namespace.
  • The name or the diskID of VirtualMachineSnapshotDiskSpec must not be empty.
  • If virtualMachineSnapshot is set in VirtualMachineVolumeSource but the VirtualMachineSnapshot is not-found or not-ready, the specific error will be set in status.volumes[].error.
  • Once the volume is attached (VirtualMachine.status.volumes[].attached = true), changes on the volume source (the name or the diskID) is not allowed.

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.

@github-actions github-actions Bot added the size/XXL Denotes a PR that changes 1000+ lines. label Aug 27, 2026
@cc005511
cc005511 force-pushed the mount_vm_snapshot_disk branch 3 times, most recently from fc01553 to c74b40e Compare September 7, 2026 06:45
@cc005511
cc005511 force-pushed the mount_vm_snapshot_disk branch 2 times, most recently from 22a2e4d to bf97481 Compare September 7, 2026 10:10
@cc005511 cc005511 changed the title Mount vm snapshot disk ✨ Mount vm snapshot disk Sep 7, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@cc005511
cc005511 force-pushed the mount_vm_snapshot_disk branch from bf97481 to 661ea04 Compare September 8, 2026 08:44

@stevenhuang-vcf stevenhuang-vcf left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You need to add more comments in the code.

Comment on lines +881 to +886
} 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should return the target backing info for a unsupported type?
Comparing the logic in isSnapshotDisk only VirtualDiskFlatVer2BackingInfo, VirtualDiskSeSparseBackingInfo and VirtualDiskSparseVer2BackingInfo are supported.

Comment on lines +1899 to +1908
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
}
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Need to add FSS.

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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why not as setSnapshotVolumeAttached does, the check runs on the status list of volumes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL Denotes a PR that changes 1000+ lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants