Skip to content

Commit 7d263bd

Browse files
authored
feat: adds image tempalting for capx (#1096)
**What problem does this PR solve?**: exposes image templating and bumps capx version **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent 473d124 commit 7d263bd

File tree

14 files changed

+529
-42
lines changed

14 files changed

+529
-42
lines changed

api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanix_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ type NutanixResourceIdentifier struct {
7474
Name *string `json:"name,omitempty"`
7575
}
7676

77+
func (nri NutanixResourceIdentifier) String() string {
78+
if nri.Type == NutanixIdentifierUUID && nri.UUID != nil {
79+
return *nri.UUID
80+
}
81+
if nri.Type == NutanixIdentifierName && nri.Name != nil {
82+
return *nri.Name
83+
}
84+
return ""
85+
}
86+
87+
func (nri NutanixResourceIdentifier) IsUUID() bool {
88+
return nri.Type == NutanixIdentifierUUID && nri.UUID != nil
89+
}
90+
91+
func (nri NutanixResourceIdentifier) IsName() bool {
92+
return nri.Type == NutanixIdentifierName && nri.Name != nil
93+
}
94+
7795
type NutanixCategoryIdentifier struct {
7896
// key is the Key of category in PC.
7997
// +optional

api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixmachine_types.go

Lines changed: 143 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,59 @@ 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

77+
// NutanixImageLookup defines how to fetch images for the cluster
78+
// using the fields combined.
79+
type NutanixImageLookup struct {
80+
// Format is the naming format to look up the image for this
81+
// machine It will be ignored if an explicit image is set. Supports
82+
// substitutions for {{.BaseOS}} and {{.K8sVersion}} with the base OS and
83+
// kubernetes version, respectively. The BaseOS will be the value in
84+
// BaseOS and the K8sVersion is the value in the Machine .spec.version, with the v prefix removed.
85+
// This is effectively the defined by the packages produced by kubernetes/release without v as a
86+
// prefix: 1.13.0, 1.12.5-mybuild.1, or 1.17.3. For example, the default
87+
// image format of {{.BaseOS}}-?{{.K8sVersion}}-* and BaseOS as "rhel-8.10" will end up
88+
// searching for images that match the pattern rhel-8.10-1.30.5-* for a
89+
// Machine that is targeting kubernetes v1.30.5. See
90+
// also: https://golang.org/pkg/text/template/
91+
// +kubebuilder:default:="capx-{{.BaseOS}}-{{.K8sVersion}}-*"
92+
Format *string `json:"format,omitempty"`
93+
// BaseOS is the name of the base operating system to use for
94+
// image lookup.
95+
// +kubebuilder:validation:MinLength:=1
96+
BaseOS string `json:"baseOS"`
97+
}
98+
5099
// NutanixMachineSpec defines the desired state of NutanixMachine
100+
// +kubebuilder:validation:XValidation:rule="has(self.image) != has(self.imageLookup)",message="Either 'image' or 'imageLookup' must be set, but not both"
51101
type NutanixMachineSpec struct {
52102
// SPEC FIELDS - desired state of NutanixMachine
53103
// Important: Run "make" to regenerate code after modifying this file
@@ -67,11 +117,16 @@ type NutanixMachineSpec struct {
67117
// The minimum memorySize is 2Gi bytes
68118
// +kubebuilder:validation:Required
69119
MemorySize resource.Quantity `json:"memorySize"`
70-
// image is to identify the rhcos image uploaded to the Prism Central (PC)
120+
// image is to identify the nutanix machine image uploaded to the Prism Central (PC)
71121
// The image identifier (uuid or name) can be obtained from the Prism Central console
72122
// or using the prism_central API.
73-
// +kubebuilder:validation:Required
74-
Image NutanixResourceIdentifier `json:"image"`
123+
// +kubebuilder:validation:Optional
124+
// +optional
125+
Image *NutanixResourceIdentifier `json:"image,omitempty"`
126+
// imageLookup is a container that holds how to look up rhcos images for the cluster.
127+
// +kubebuilder:validation:Optional
128+
// +optional
129+
ImageLookup *NutanixImageLookup `json:"imageLookup,omitempty"`
75130
// cluster is to identify the cluster (the Prism Element under management
76131
// of the Prism Central), in which the Machine's VM will be created.
77132
// The cluster identifier (uuid or name) can be obtained from the Prism Central console
@@ -93,22 +148,100 @@ type NutanixMachineSpec struct {
93148
// +kubebuilder:validation:Optional
94149
// +kubebuilder:validation:Enum:=legacy;uefi
95150
BootType NutanixBootType `json:"bootType,omitempty"`
96-
97151
// systemDiskSize is size (in Quantity format) of the system disk of the VM
98152
// The minimum systemDiskSize is 20Gi bytes
99153
// +kubebuilder:validation:Required
100154
SystemDiskSize resource.Quantity `json:"systemDiskSize"`
101155

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+
102160
// BootstrapRef is a reference to a bootstrap provider-specific resource
103161
// that holds configuration details.
104162
// +optional
105163
BootstrapRef *corev1.ObjectReference `json:"bootstrapRef,omitempty"`
106-
107164
// List of GPU devices that need to be added to the machines.
108165
// +kubebuilder:validation:Optional
109166
GPUs []NutanixGPU `json:"gpus,omitempty"`
110167
}
111168

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+
112245
// NutanixMachineStatus defines the observed state of NutanixMachine
113246
type NutanixMachineStatus struct {
114247
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
@@ -144,14 +277,13 @@ type NutanixMachineStatus struct {
144277
FailureMessage *string `json:"failureMessage,omitempty"`
145278
}
146279

147-
//+kubebuilder:object:root=true
148-
//+kubebuilder:resource:path=nutanixmachines,shortName=nma,scope=Namespaced,categories=cluster-api
149-
//+kubebuilder:subresource:status
150-
//+kubebuilder:storageversion
151-
//+kubebuilder:printcolumn:name="Address",type="string",JSONPath=".status.addresses[0].address",description="The VM address"
280+
// +kubebuilder:object:root=true
281+
// +kubebuilder:resource:path=nutanixmachines,shortName=nma,scope=Namespaced,categories=cluster-api
282+
// +kubebuilder:subresource:status
283+
// +kubebuilder:storageversion
284+
// +kubebuilder:printcolumn:name="Address",type="string",JSONPath=".status.addresses[0].address",description="The VM address"
152285
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="NutanixMachine ready status"
153286
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="NutanixMachine instance ID"
154-
155287
// NutanixMachine is the Schema for the nutanixmachines API
156288
type NutanixMachine struct {
157289
metav1.TypeMeta `json:",inline"`

api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/zz_generated.deepcopy.go

Lines changed: 103 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)