Skip to content

feat: adds image tempalting for capx #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ type NutanixResourceIdentifier struct {
Name *string `json:"name,omitempty"`
}

func (nri NutanixResourceIdentifier) String() string {
if nri.Type == NutanixIdentifierUUID && nri.UUID != nil {
return *nri.UUID
}
if nri.Type == NutanixIdentifierName && nri.Name != nil {
return *nri.Name
}
return ""
}

func (nri NutanixResourceIdentifier) IsUUID() bool {
return nri.Type == NutanixIdentifierUUID && nri.UUID != nil
}

func (nri NutanixResourceIdentifier) IsName() bool {
return nri.Type == NutanixIdentifierName && nri.Name != nil
}

type NutanixCategoryIdentifier struct {
// key is the Key of category in PC.
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,59 @@ const (
// to Image, the NutanixMachine will be created with the image mounted
// as a CD-ROM.
NutanixMachineBootstrapRefKindImage = "Image"

// NutanixMachineDiskModeStandard represents the standard disk mode.
NutanixMachineDiskModeStandard NutanixMachineDiskMode = "Standard"

// NutanixMachineDiskModeFlash represents the flash disk mode.
NutanixMachineDiskModeFlash NutanixMachineDiskMode = "Flash"

// NutanixMachineDiskDeviceTypeDisk represents the disk device type.
NutanixMachineDiskDeviceTypeDisk NutanixMachineDiskDeviceType = "Disk"

// NutanixMachineDiskDeviceTypeCDRom represents the CD-ROM device type.
NutanixMachineDiskDeviceTypeCDRom NutanixMachineDiskDeviceType = "CDRom"

// NutanixMachineDiskAdapterTypeSCSI represents the SCSI adapter type.
NutanixMachineDiskAdapterTypeSCSI NutanixMachineDiskAdapterType = "SCSI"

// NutanixMachineDiskAdapterTypeIDE represents the IDE adapter type.
NutanixMachineDiskAdapterTypeIDE NutanixMachineDiskAdapterType = "IDE"

// NutanixMachineDiskAdapterTypePCI represents the PCI adapter type.
NutanixMachineDiskAdapterTypePCI NutanixMachineDiskAdapterType = "PCI"

// NutanixMachineDiskAdapterTypeSATA represents the SATA adapter type.
NutanixMachineDiskAdapterTypeSATA NutanixMachineDiskAdapterType = "SATA"

// NutanixMachineDiskAdapterTypeSPAPR represents the SPAPR adapter type.
NutanixMachineDiskAdapterTypeSPAPR NutanixMachineDiskAdapterType = "SPAPR"
)

// NutanixImageLookup defines how to fetch images for the cluster
// using the fields combined.
type NutanixImageLookup struct {
// Format is the naming format to look up the image for this
// machine It will be ignored if an explicit image is set. Supports
// substitutions for {{.BaseOS}} and {{.K8sVersion}} with the base OS and
// kubernetes version, respectively. The BaseOS will be the value in
// BaseOS and the K8sVersion is the value in the Machine .spec.version, with the v prefix removed.
// This is effectively the defined by the packages produced by kubernetes/release without v as a
// prefix: 1.13.0, 1.12.5-mybuild.1, or 1.17.3. For example, the default
// image format of {{.BaseOS}}-?{{.K8sVersion}}-* and BaseOS as "rhel-8.10" will end up
// searching for images that match the pattern rhel-8.10-1.30.5-* for a
// Machine that is targeting kubernetes v1.30.5. See
// also: https://golang.org/pkg/text/template/
// +kubebuilder:default:="capx-{{.BaseOS}}-{{.K8sVersion}}-*"
Format *string `json:"format,omitempty"`
// BaseOS is the name of the base operating system to use for
// image lookup.
// +kubebuilder:validation:MinLength:=1
BaseOS string `json:"baseOS"`
}

// NutanixMachineSpec defines the desired state of NutanixMachine
// +kubebuilder:validation:XValidation:rule="has(self.image) != has(self.imageLookup)",message="Either 'image' or 'imageLookup' must be set, but not both"
type NutanixMachineSpec struct {
// SPEC FIELDS - desired state of NutanixMachine
// Important: Run "make" to regenerate code after modifying this file
Expand All @@ -67,11 +117,16 @@ type NutanixMachineSpec struct {
// The minimum memorySize is 2Gi bytes
// +kubebuilder:validation:Required
MemorySize resource.Quantity `json:"memorySize"`
// image is to identify the rhcos image uploaded to the Prism Central (PC)
// image is to identify the nutanix machine image uploaded to the Prism Central (PC)
// The image identifier (uuid or name) can be obtained from the Prism Central console
// or using the prism_central API.
// +kubebuilder:validation:Required
Image NutanixResourceIdentifier `json:"image"`
// +kubebuilder:validation:Optional
// +optional
Image *NutanixResourceIdentifier `json:"image,omitempty"`
// imageLookup is a container that holds how to look up rhcos images for the cluster.
// +kubebuilder:validation:Optional
// +optional
ImageLookup *NutanixImageLookup `json:"imageLookup,omitempty"`
// cluster is to identify the cluster (the Prism Element under management
// of the Prism Central), in which the Machine's VM will be created.
// The cluster identifier (uuid or name) can be obtained from the Prism Central console
Expand All @@ -93,22 +148,100 @@ type NutanixMachineSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum:=legacy;uefi
BootType NutanixBootType `json:"bootType,omitempty"`

// systemDiskSize is size (in Quantity format) of the system disk of the VM
// The minimum systemDiskSize is 20Gi bytes
// +kubebuilder:validation:Required
SystemDiskSize resource.Quantity `json:"systemDiskSize"`

// dataDisks hold the list of data disks to be attached to the VM
// +kubebuilder:validation:Optional
DataDisks []NutanixMachineVMDisk `json:"dataDisks,omitempty"`

// BootstrapRef is a reference to a bootstrap provider-specific resource
// that holds configuration details.
// +optional
BootstrapRef *corev1.ObjectReference `json:"bootstrapRef,omitempty"`

// List of GPU devices that need to be added to the machines.
// +kubebuilder:validation:Optional
GPUs []NutanixGPU `json:"gpus,omitempty"`
}

// NutanixMachineVMDisk defines the disk configuration for a NutanixMachine
type NutanixMachineVMDisk struct {
// diskSize is the size (in Quantity format) of the disk attached to the VM.
// See https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Format for the Quantity format and example documentation.
// The minimum diskSize is 1GB.
// +kubebuilder:validation:Required
DiskSize resource.Quantity `json:"diskSize"`

// deviceProperties are the properties of the disk device.
// +optional
// +kubebuilder:validation:Optional
DeviceProperties *NutanixMachineVMDiskDeviceProperties `json:"deviceProperties,omitempty"`

// storageConfig are the storage configuration parameters of the VM disks.
// +optional
// +kubebuilder:validation:Optional
StorageConfig *NutanixMachineVMStorageConfig `json:"storageConfig,omitempty"`

// dataSource refers to a data source image for the VM disk.
// +optional
// +kubebuilder:validation:Optional
DataSource *NutanixResourceIdentifier `json:"dataSource,omitempty"`
}

// NutanixMachineVMDiskDeviceProperties defines the device properties for a NutanixMachineVMDisk
type NutanixMachineVMDiskDeviceProperties struct {
// deviceType specifies the disk device type.
// The valid values are "Disk" and "CDRom", and the default is "Disk".
// +kubebuilder:default=Disk
// +kubebuilder:validation:Required
DeviceType NutanixMachineDiskDeviceType `json:"deviceType"`

// adapterType is the adapter type of the disk address.
// If the deviceType is "Disk", the valid adapterType can be "SCSI", "IDE", "PCI", "SATA" or "SPAPR".
// If the deviceType is "CDRom", the valid adapterType can be "IDE" or "SATA".
// +kubebuilder:validation:Required
AdapterType NutanixMachineDiskAdapterType `json:"adapterType,omitempty"`

// deviceIndex is the index of the disk address. The valid values are non-negative integers, with the default value 0.
// For a Machine VM, the deviceIndex for the disks with the same deviceType.adapterType combination should
// start from 0 and increase consecutively afterwards. Note that for each Machine VM, the Disk.SCSI.0
// and CDRom.IDE.0 are reserved to be used by the VM's system. So for dataDisks of Disk.SCSI and CDRom.IDE,
// the deviceIndex should start from 1.
// +kubebuilder:default=0
// +kubebuilder:validation:Minimum=0
// +optional
// +kubebuilder:validation:Optional
DeviceIndex int32 `json:"deviceIndex,omitempty"`
}

// NutanixMachineVMStorageConfig defines the storage configuration for a NutanixMachineVMDisk
type NutanixMachineVMStorageConfig struct {
// diskMode specifies the disk mode.
// The valid values are Standard and Flash, and the default is Standard.
// +kubebuilder:default=Standard
// +kubebuilder:validation:Required
DiskMode NutanixMachineDiskMode `json:"diskMode"`

// storageContainer refers to the storage_container used by the VM disk.
// +optional
// +kubebuilder:validation:Optional
StorageContainer *NutanixResourceIdentifier `json:"storageContainer"`
}

// NutanixMachineDiskMode is an enumeration of different disk modes.
// +kubebuilder:validation:Enum=Standard;Flash
type NutanixMachineDiskMode string

// NutanixMachineDiskDeviceType is the VM disk device type.
// +kubebuilder:validation:Enum=Disk;CDRom
type NutanixMachineDiskDeviceType string

// NutanixMachineDiskAdapterType is an enumeration of different disk device adapter types.
// +kubebuilder:validation:Enum:=SCSI;IDE;PCI;SATA;SPAPR
type NutanixMachineDiskAdapterType string

// NutanixMachineStatus defines the observed state of NutanixMachine
type NutanixMachineStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down Expand Up @@ -144,14 +277,13 @@ type NutanixMachineStatus struct {
FailureMessage *string `json:"failureMessage,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:path=nutanixmachines,shortName=nma,scope=Namespaced,categories=cluster-api
//+kubebuilder:subresource:status
//+kubebuilder:storageversion
//+kubebuilder:printcolumn:name="Address",type="string",JSONPath=".status.addresses[0].address",description="The VM address"
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=nutanixmachines,shortName=nma,scope=Namespaced,categories=cluster-api
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Address",type="string",JSONPath=".status.addresses[0].address",description="The VM address"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="NutanixMachine ready status"
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="NutanixMachine instance ID"

// NutanixMachine is the Schema for the nutanixmachines API
type NutanixMachine struct {
metav1.TypeMeta `json:",inline"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading