mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #84211 from misterikkit/create-idempotent
vsphere: check if volume exists before create
This commit is contained in:
commit
c558e7f1f2
@ -39,11 +39,17 @@ func (diskManager virtualDiskManager) Create(ctx context.Context, datastore *vcl
|
|||||||
if diskManager.volumeOptions.SCSIControllerType == "" {
|
if diskManager.volumeOptions.SCSIControllerType == "" {
|
||||||
diskManager.volumeOptions.SCSIControllerType = vclib.LSILogicControllerType
|
diskManager.volumeOptions.SCSIControllerType = vclib.LSILogicControllerType
|
||||||
}
|
}
|
||||||
// Create virtual disk
|
|
||||||
diskFormat := vclib.DiskFormatValidType[diskManager.volumeOptions.DiskFormat]
|
// Check for existing VMDK before attempting create. Because a name collision
|
||||||
// Create a virtual disk manager
|
// is unlikely, "VMDK already exists" is likely from a previous attempt to
|
||||||
vdm := object.NewVirtualDiskManager(datastore.Client())
|
// create this volume.
|
||||||
|
if dsPath := vclib.GetPathFromVMDiskPath(diskManager.diskPath); datastore.Exists(ctx, dsPath) {
|
||||||
|
klog.V(2).Infof("Create: VirtualDisk already exists, returning success. Name=%q", diskManager.diskPath)
|
||||||
|
return diskManager.diskPath, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Create specification for new virtual disk
|
// Create specification for new virtual disk
|
||||||
|
diskFormat := vclib.DiskFormatValidType[diskManager.volumeOptions.DiskFormat]
|
||||||
vmDiskSpec := &types.FileBackedVirtualDiskSpec{
|
vmDiskSpec := &types.FileBackedVirtualDiskSpec{
|
||||||
VirtualDiskSpec: types.VirtualDiskSpec{
|
VirtualDiskSpec: types.VirtualDiskSpec{
|
||||||
AdapterType: diskManager.volumeOptions.SCSIControllerType,
|
AdapterType: diskManager.volumeOptions.SCSIControllerType,
|
||||||
@ -51,6 +57,8 @@ func (diskManager virtualDiskManager) Create(ctx context.Context, datastore *vcl
|
|||||||
},
|
},
|
||||||
CapacityKb: int64(diskManager.volumeOptions.CapacityKB),
|
CapacityKb: int64(diskManager.volumeOptions.CapacityKB),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vdm := object.NewVirtualDiskManager(datastore.Client())
|
||||||
requestTime := time.Now()
|
requestTime := time.Now()
|
||||||
// Create virtual disk
|
// Create virtual disk
|
||||||
task, err := vdm.CreateVirtualDisk(ctx, diskManager.diskPath, datastore.Datacenter.Datacenter, vmDiskSpec)
|
task, err := vdm.CreateVirtualDisk(ctx, diskManager.diskPath, datastore.Datacenter.Datacenter, vmDiskSpec)
|
||||||
|
Loading…
Reference in New Issue
Block a user