Skip to content

Commit 78db141

Browse files
authored
Add data disk feature implementation to NutanixMachine (#493)
* Add data disk feature implementation to NutanixMachine - add dataDisks field to NutanixMachine manifests - add unit tests - add e2e tests * Fix commants and merge with latest upstream * Update devbox.lock to make test passing * devbox run -- make manifests * Update devbox.lock to make test passing * revert to lint github action instead of call * Revert and fix devbox golang dependencies * Fix tests and devbox dependencies versions * Fix tests after conflict resolution * Fix comments * Fix comments * Fix comments * Get rid of devbox changes * Fix after merge and fix comments
1 parent 9f1addd commit 78db141

13 files changed

+2410
-17
lines changed

api/v1beta1/nutanixmachine_types.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ const (
4545
// to Image, the NutanixMachine will be created with the image mounted
4646
// as a CD-ROM.
4747
NutanixMachineBootstrapRefKindImage = "Image"
48+
49+
// NutanixMachineDiskModeStandard represents the standard disk mode.
50+
NutanixMachineDiskModeStandard NutanixMachineDiskMode = "Standard"
51+
52+
// NutanixMachineDiskModeFlash represents the flash disk mode.
53+
NutanixMachineDiskModeFlash NutanixMachineDiskMode = "Flash"
54+
55+
// NutanixMachineDiskDeviceTypeDisk represents the disk device type.
56+
NutanixMachineDiskDeviceTypeDisk NutanixMachineDiskDeviceType = "Disk"
57+
58+
// NutanixMachineDiskDeviceTypeCDRom represents the CD-ROM device type.
59+
NutanixMachineDiskDeviceTypeCDRom NutanixMachineDiskDeviceType = "CDRom"
60+
61+
// NutanixMachineDiskAdapterTypeSCSI represents the SCSI adapter type.
62+
NutanixMachineDiskAdapterTypeSCSI NutanixMachineDiskAdapterType = "SCSI"
63+
64+
// NutanixMachineDiskAdapterTypeIDE represents the IDE adapter type.
65+
NutanixMachineDiskAdapterTypeIDE NutanixMachineDiskAdapterType = "IDE"
66+
67+
// NutanixMachineDiskAdapterTypePCI represents the PCI adapter type.
68+
NutanixMachineDiskAdapterTypePCI NutanixMachineDiskAdapterType = "PCI"
69+
70+
// NutanixMachineDiskAdapterTypeSATA represents the SATA adapter type.
71+
NutanixMachineDiskAdapterTypeSATA NutanixMachineDiskAdapterType = "SATA"
72+
73+
// NutanixMachineDiskAdapterTypeSPAPR represents the SPAPR adapter type.
74+
NutanixMachineDiskAdapterTypeSPAPR NutanixMachineDiskAdapterType = "SPAPR"
4875
)
4976

5077
// NutanixImageLookup defines how to fetch images for the cluster
@@ -125,6 +152,11 @@ type NutanixMachineSpec struct {
125152
// The minimum systemDiskSize is 20Gi bytes
126153
// +kubebuilder:validation:Required
127154
SystemDiskSize resource.Quantity `json:"systemDiskSize"`
155+
156+
// dataDisks hold the list of data disks to be attached to the VM
157+
// +kubebuilder:validation:Optional
158+
DataDisks []NutanixMachineVMDisk `json:"dataDisks,omitempty"`
159+
128160
// BootstrapRef is a reference to a bootstrap provider-specific resource
129161
// that holds configuration details.
130162
// +optional
@@ -134,6 +166,82 @@ type NutanixMachineSpec struct {
134166
GPUs []NutanixGPU `json:"gpus,omitempty"`
135167
}
136168

169+
// NutanixMachineVMDisk defines the disk configuration for a NutanixMachine
170+
type NutanixMachineVMDisk struct {
171+
// diskSize is the size (in Quantity format) of the disk attached to the VM.
172+
// See https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Format for the Quantity format and example documentation.
173+
// The minimum diskSize is 1GB.
174+
// +kubebuilder:validation:Required
175+
DiskSize resource.Quantity `json:"diskSize"`
176+
177+
// deviceProperties are the properties of the disk device.
178+
// +optional
179+
// +kubebuilder:validation:Optional
180+
DeviceProperties *NutanixMachineVMDiskDeviceProperties `json:"deviceProperties,omitempty"`
181+
182+
// storageConfig are the storage configuration parameters of the VM disks.
183+
// +optional
184+
// +kubebuilder:validation:Optional
185+
StorageConfig *NutanixMachineVMStorageConfig `json:"storageConfig,omitempty"`
186+
187+
// dataSource refers to a data source image for the VM disk.
188+
// +optional
189+
// +kubebuilder:validation:Optional
190+
DataSource *NutanixResourceIdentifier `json:"dataSource,omitempty"`
191+
}
192+
193+
// NutanixMachineVMDiskDeviceProperties defines the device properties for a NutanixMachineVMDisk
194+
type NutanixMachineVMDiskDeviceProperties struct {
195+
// deviceType specifies the disk device type.
196+
// The valid values are "Disk" and "CDRom", and the default is "Disk".
197+
// +kubebuilder:default=Disk
198+
// +kubebuilder:validation:Required
199+
DeviceType NutanixMachineDiskDeviceType `json:"deviceType"`
200+
201+
// adapterType is the adapter type of the disk address.
202+
// If the deviceType is "Disk", the valid adapterType can be "SCSI", "IDE", "PCI", "SATA" or "SPAPR".
203+
// If the deviceType is "CDRom", the valid adapterType can be "IDE" or "SATA".
204+
// +kubebuilder:validation:Required
205+
AdapterType NutanixMachineDiskAdapterType `json:"adapterType,omitempty"`
206+
207+
// deviceIndex is the index of the disk address. The valid values are non-negative integers, with the default value 0.
208+
// For a Machine VM, the deviceIndex for the disks with the same deviceType.adapterType combination should
209+
// start from 0 and increase consecutively afterwards. Note that for each Machine VM, the Disk.SCSI.0
210+
// and CDRom.IDE.0 are reserved to be used by the VM's system. So for dataDisks of Disk.SCSI and CDRom.IDE,
211+
// the deviceIndex should start from 1.
212+
// +kubebuilder:default=0
213+
// +kubebuilder:validation:Minimum=0
214+
// +optional
215+
// +kubebuilder:validation:Optional
216+
DeviceIndex int32 `json:"deviceIndex,omitempty"`
217+
}
218+
219+
// NutanixMachineVMStorageConfig defines the storage configuration for a NutanixMachineVMDisk
220+
type NutanixMachineVMStorageConfig struct {
221+
// diskMode specifies the disk mode.
222+
// The valid values are Standard and Flash, and the default is Standard.
223+
// +kubebuilder:default=Standard
224+
// +kubebuilder:validation:Required
225+
DiskMode NutanixMachineDiskMode `json:"diskMode"`
226+
227+
// storageContainer refers to the storage_container used by the VM disk.
228+
// +optional
229+
// +kubebuilder:validation:Optional
230+
StorageContainer *NutanixResourceIdentifier `json:"storageContainer"`
231+
}
232+
233+
// NutanixMachineDiskMode is an enumeration of different disk modes.
234+
// +kubebuilder:validation:Enum=Standard;Flash
235+
type NutanixMachineDiskMode string
236+
237+
// NutanixMachineDiskDeviceType is the VM disk device type.
238+
// +kubebuilder:validation:Enum=Disk;CDRom
239+
type NutanixMachineDiskDeviceType string
240+
241+
// NutanixMachineDiskAdapterType is an enumeration of different disk device adapter types.
242+
// +kubebuilder:validation:Enum:=SCSI;IDE;PCI;SATA;SPAPR
243+
type NutanixMachineDiskAdapterType string
244+
137245
// NutanixMachineStatus defines the observed state of NutanixMachine
138246
type NutanixMachineStatus struct {
139247
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster

api/v1beta1/zz_generated.deepcopy.go

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

config/crd/bases/infrastructure.cluster.x-k8s.io_nutanixmachines.yaml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,123 @@ spec:
145145
required:
146146
- type
147147
type: object
148+
dataDisks:
149+
description: dataDisks hold the list of data disks to be attached
150+
to the VM
151+
items:
152+
description: NutanixMachineVMDisk defines the disk configuration
153+
for a NutanixMachine
154+
properties:
155+
dataSource:
156+
description: dataSource refers to a data source image for the
157+
VM disk.
158+
properties:
159+
name:
160+
description: name is the resource name in the PC
161+
type: string
162+
type:
163+
description: Type is the identifier type to use for this
164+
resource.
165+
enum:
166+
- uuid
167+
- name
168+
type: string
169+
uuid:
170+
description: uuid is the UUID of the resource in the PC.
171+
type: string
172+
required:
173+
- type
174+
type: object
175+
deviceProperties:
176+
description: deviceProperties are the properties of the disk
177+
device.
178+
properties:
179+
adapterType:
180+
description: |-
181+
adapterType is the adapter type of the disk address.
182+
If the deviceType is "Disk", the valid adapterType can be "SCSI", "IDE", "PCI", "SATA" or "SPAPR".
183+
If the deviceType is "CDRom", the valid adapterType can be "IDE" or "SATA".
184+
enum:
185+
- SCSI
186+
- IDE
187+
- PCI
188+
- SATA
189+
- SPAPR
190+
type: string
191+
deviceIndex:
192+
default: 0
193+
description: |-
194+
deviceIndex is the index of the disk address. The valid values are non-negative integers, with the default value 0.
195+
For a Machine VM, the deviceIndex for the disks with the same deviceType.adapterType combination should
196+
start from 0 and increase consecutively afterwards. Note that for each Machine VM, the Disk.SCSI.0
197+
and CDRom.IDE.0 are reserved to be used by the VM's system. So for dataDisks of Disk.SCSI and CDRom.IDE,
198+
the deviceIndex should start from 1.
199+
format: int32
200+
minimum: 0
201+
type: integer
202+
deviceType:
203+
default: Disk
204+
description: |-
205+
deviceType specifies the disk device type.
206+
The valid values are "Disk" and "CDRom", and the default is "Disk".
207+
enum:
208+
- Disk
209+
- CDRom
210+
type: string
211+
required:
212+
- deviceType
213+
type: object
214+
diskSize:
215+
anyOf:
216+
- type: integer
217+
- type: string
218+
description: |-
219+
diskSize is the size (in Quantity format) of the disk attached to the VM.
220+
See https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Format for the Quantity format and example documentation.
221+
The minimum diskSize is 1GB.
222+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
223+
x-kubernetes-int-or-string: true
224+
storageConfig:
225+
description: storageConfig are the storage configuration parameters
226+
of the VM disks.
227+
properties:
228+
diskMode:
229+
default: Standard
230+
description: |-
231+
diskMode specifies the disk mode.
232+
The valid values are Standard and Flash, and the default is Standard.
233+
enum:
234+
- Standard
235+
- Flash
236+
type: string
237+
storageContainer:
238+
description: storageContainer refers to the storage_container
239+
used by the VM disk.
240+
properties:
241+
name:
242+
description: name is the resource name in the PC
243+
type: string
244+
type:
245+
description: Type is the identifier type to use for
246+
this resource.
247+
enum:
248+
- uuid
249+
- name
250+
type: string
251+
uuid:
252+
description: uuid is the UUID of the resource in the
253+
PC.
254+
type: string
255+
required:
256+
- type
257+
type: object
258+
required:
259+
- diskMode
260+
type: object
261+
required:
262+
- diskSize
263+
type: object
264+
type: array
148265
gpus:
149266
description: List of GPU devices that need to be added to the machines.
150267
items:

0 commit comments

Comments
 (0)