Skip to content

Commit 41e14f6

Browse files
committed
Added multi disk support
1 parent 8f46e35 commit 41e14f6

File tree

8 files changed

+145
-0
lines changed

8 files changed

+145
-0
lines changed

apis/v1alpha3/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha4/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1beta1/types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ type VirtualMachineCloneSpec struct {
203203
// Check the compatibility with the ESXi version before setting the value.
204204
// +optional
205205
HardwareVersion string `json:"hardwareVersion,omitempty"`
206+
// DataDisks holds information for additional disks to add to the VM that are not part of the VM's OVA template.
207+
// +optional
208+
DataDisks []VSphereDisk `json:"dataDisks,omitempty"`
209+
}
210+
211+
// VSphereDisk describes additional disks for vSphere to be added to VM that are not part of the VM OVA template.
212+
type VSphereDisk struct {
213+
// DeviceName is a name to be used to identify the disk definition. If deviceName is not specified,
214+
// the disk will still be created. The deviceName should be unique so that it can be used to clearly
215+
// identify purpose of the disk, but is not required to be unique.
216+
// +optional
217+
DeviceName string `json:"deviceName,omitempty"`
218+
// SizeGiB is the size of the disk (in GiB).
219+
// +kubebuilder:validation:Required
220+
SizeGiB int64 `json:"sizeGiB"`
206221
}
207222

208223
// VSphereMachineTemplateResource describes the data needed to create a VSphereMachine from a template.

apis/v1beta1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachines.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,27 @@ spec:
988988
CustomVMXKeys is a dictionary of advanced VMX options that can be set on VM
989989
Defaults to empty map
990990
type: object
991+
dataDisks:
992+
description: DataDisks holds information for additional disks to add
993+
to the VM that are not part of the VM's OVA template.
994+
items:
995+
description: VSphereDisk describes additional disks for vSphere
996+
to be added to VM that are not part of the VM OVA template.
997+
properties:
998+
deviceName:
999+
description: |-
1000+
DeviceName is a name to be used to identify the disk definition. If deviceName is not specified,
1001+
the disk will still be created. The deviceName should be unique so that it can be used to clearly
1002+
identify purpose of the disk, but is not required to be unique.
1003+
type: string
1004+
sizeGiB:
1005+
description: SizeGiB is the size of the disk (in GiB).
1006+
format: int64
1007+
type: integer
1008+
required:
1009+
- sizeGiB
1010+
type: object
1011+
type: array
9911012
datacenter:
9921013
description: |-
9931014
Datacenter is the name or inventory path of the datacenter in which the

config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,28 @@ spec:
857857
CustomVMXKeys is a dictionary of advanced VMX options that can be set on VM
858858
Defaults to empty map
859859
type: object
860+
dataDisks:
861+
description: DataDisks holds information for additional disks
862+
to add to the VM that are not part of the VM's OVA template.
863+
items:
864+
description: VSphereDisk describes additional disks for
865+
vSphere to be added to VM that are not part of the VM
866+
OVA template.
867+
properties:
868+
deviceName:
869+
description: |-
870+
DeviceName is a name to be used to identify the disk definition. If deviceName is not specified,
871+
the disk will still be created. The deviceName should be unique so that it can be used to clearly
872+
identify purpose of the disk, but is not required to be unique.
873+
type: string
874+
sizeGiB:
875+
description: SizeGiB is the size of the disk (in GiB).
876+
format: int64
877+
type: integer
878+
required:
879+
- sizeGiB
880+
type: object
881+
type: array
860882
datacenter:
861883
description: |-
862884
Datacenter is the name or inventory path of the datacenter in which the

config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherevms.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,27 @@ spec:
10811081
CustomVMXKeys is a dictionary of advanced VMX options that can be set on VM
10821082
Defaults to empty map
10831083
type: object
1084+
dataDisks:
1085+
description: DataDisks holds information for additional disks to add
1086+
to the VM that are not part of the VM's OVA template.
1087+
items:
1088+
description: VSphereDisk describes additional disks for vSphere
1089+
to be added to VM that are not part of the VM OVA template.
1090+
properties:
1091+
deviceName:
1092+
description: |-
1093+
DeviceName is a name to be used to identify the disk definition. If deviceName is not specified,
1094+
the disk will still be created. The deviceName should be unique so that it can be used to clearly
1095+
identify purpose of the disk, but is not required to be unique.
1096+
type: string
1097+
sizeGiB:
1098+
description: SizeGiB is the size of the disk (in GiB).
1099+
format: int64
1100+
type: integer
1101+
required:
1102+
- sizeGiB
1103+
type: object
1104+
type: array
10841105
datacenter:
10851106
description: |-
10861107
Datacenter is the name or inventory path of the datacenter in which the

pkg/services/govmomi/vcenter/clone.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
pbmTypes "github.com/vmware/govmomi/pbm/types"
3030
"github.com/vmware/govmomi/vim25/mo"
3131
"github.com/vmware/govmomi/vim25/types"
32+
"k8s.io/klog/v2"
3233
"k8s.io/utils/ptr"
3334
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
3435
ctrl "sigs.k8s.io/controller-runtime"
@@ -369,6 +370,49 @@ func getDiskSpec(vmCtx *capvcontext.VMContext, devices object.VirtualDeviceList)
369370
diskSpecs = append(diskSpecs, additionalDiskConfigSpec)
370371
}
371372
}
373+
374+
// Now if we have increased the disk size of any additional disks that were in the template, we can now add new disks
375+
// that are present in the additionalDisks list.
376+
for i, dataDisk := range vmCtx.VSphereVM.Spec.DataDisks {
377+
klog.InfoS("Adding disk", "spec", dataDisk)
378+
379+
// Need storage policy
380+
// Need scsi controller
381+
controller, err := devices.FindDiskController("scsi")
382+
if err != nil {
383+
klog.Infof("Unable to get scsi controller")
384+
}
385+
386+
unit := int32(i + 1)
387+
388+
dev := &types.VirtualDisk{
389+
VirtualDevice: types.VirtualDevice{
390+
Key: devices.NewKey() - int32(i),
391+
Backing: &types.VirtualDiskFlatVer2BackingInfo{
392+
DiskMode: string(types.VirtualDiskModePersistent),
393+
ThinProvisioned: types.NewBool(true),
394+
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
395+
FileName: "",
396+
//Datastore: types.NewReference(datastore.Reference()),
397+
},
398+
},
399+
UnitNumber: &unit,
400+
ControllerKey: controller.GetVirtualController().Key,
401+
},
402+
CapacityInKB: dataDisk.SizeGiB * 1024 * 1024,
403+
}
404+
405+
diskConfigSpec := types.VirtualDeviceConfigSpec{
406+
Device: dev,
407+
Operation: types.VirtualDeviceConfigSpecOperationAdd,
408+
FileOperation: types.VirtualDeviceConfigSpecFileOperationCreate,
409+
}
410+
411+
klog.InfoS("Generated device", "dev", dev)
412+
413+
diskSpecs = append(diskSpecs, &diskConfigSpec)
414+
}
415+
372416
return diskSpecs, nil
373417
}
374418

0 commit comments

Comments
 (0)