@@ -39,18 +39,26 @@ func (diskManager virtualDiskManager) Create(ctx context.Context, datastore *vcl
39
39
if diskManager .volumeOptions .SCSIControllerType == "" {
40
40
diskManager .volumeOptions .SCSIControllerType = vclib .LSILogicControllerType
41
41
}
42
- // Create virtual disk
43
- diskFormat := vclib .DiskFormatValidType [diskManager .volumeOptions .DiskFormat ]
44
- // Create a virtual disk manager
45
- vdm := object .NewVirtualDiskManager (datastore .Client ())
42
+
43
+ // Check for existing VMDK before attempting create. Because a name collision
44
+ // is unlikely, "VMDK already exists" is likely from a previous attempt to
45
+ // create this volume.
46
+ if dsPath := vclib .GetPathFromVMDiskPath (diskManager .diskPath ); datastore .Exists (ctx , dsPath ) {
47
+ klog .V (2 ).Infof ("Create: VirtualDisk already exists, returning success. Name=%q" , diskManager .diskPath )
48
+ return diskManager .diskPath , nil
49
+ }
50
+
46
51
// Create specification for new virtual disk
52
+ diskFormat := vclib .DiskFormatValidType [diskManager .volumeOptions .DiskFormat ]
47
53
vmDiskSpec := & types.FileBackedVirtualDiskSpec {
48
54
VirtualDiskSpec : types.VirtualDiskSpec {
49
55
AdapterType : diskManager .volumeOptions .SCSIControllerType ,
50
56
DiskType : diskFormat ,
51
57
},
52
58
CapacityKb : int64 (diskManager .volumeOptions .CapacityKB ),
53
59
}
60
+
61
+ vdm := object .NewVirtualDiskManager (datastore .Client ())
54
62
requestTime := time .Now ()
55
63
// Create virtual disk
56
64
task , err := vdm .CreateVirtualDisk (ctx , diskManager .diskPath , datastore .Datacenter .Datacenter , vmDiskSpec )
0 commit comments