mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
vsphere: check if volume exists before create
Sometimes, volume creation can succeed right as the request times out, causing k8s to interpret it as a failure. When the request is retried, we want it to succeed. When trying this in vSphere, the second create request failed with "already exists" and it never recovered. This adds a check to the in-tree vsphere storage plugin that checks if a VMDK exists before trying to create it. The check is done BEFORE create. Tested: manual only )-:
This commit is contained in:
parent
eedfb6bc7a
commit
131668a03f
@ -39,11 +39,17 @@ func (diskManager virtualDiskManager) Create(ctx context.Context, datastore *vcl
|
||||
if diskManager.volumeOptions.SCSIControllerType == "" {
|
||||
diskManager.volumeOptions.SCSIControllerType = vclib.LSILogicControllerType
|
||||
}
|
||||
// Create virtual disk
|
||||
diskFormat := vclib.DiskFormatValidType[diskManager.volumeOptions.DiskFormat]
|
||||
// Create a virtual disk manager
|
||||
vdm := object.NewVirtualDiskManager(datastore.Client())
|
||||
|
||||
// Check for existing VMDK before attempting create. Because a name collision
|
||||
// is unlikely, "VMDK already exists" is likely from a previous attempt to
|
||||
// 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
|
||||
diskFormat := vclib.DiskFormatValidType[diskManager.volumeOptions.DiskFormat]
|
||||
vmDiskSpec := &types.FileBackedVirtualDiskSpec{
|
||||
VirtualDiskSpec: types.VirtualDiskSpec{
|
||||
AdapterType: diskManager.volumeOptions.SCSIControllerType,
|
||||
@ -51,6 +57,8 @@ func (diskManager virtualDiskManager) Create(ctx context.Context, datastore *vcl
|
||||
},
|
||||
CapacityKb: int64(diskManager.volumeOptions.CapacityKB),
|
||||
}
|
||||
|
||||
vdm := object.NewVirtualDiskManager(datastore.Client())
|
||||
requestTime := time.Now()
|
||||
// Create virtual disk
|
||||
task, err := vdm.CreateVirtualDisk(ctx, diskManager.diskPath, datastore.Datacenter.Datacenter, vmDiskSpec)
|
||||
|
Loading…
Reference in New Issue
Block a user