From 691fa78e4aba80a9572a63dce7df215d7e12635d Mon Sep 17 00:00:00 2001 From: Dimitri Koshkin Date: Mon, 3 Jun 2024 11:23:48 -0700 Subject: [PATCH] fix: use external Nutanix API types directly From what I can tell there is no longer a need to have these separate types. This also fixes a swagger issue complaining about a circular reference since the types are named the same. --- api/v1alpha1/nutanix_node_types.go | 22 +++----- api/v1alpha1/zz_generated.deepcopy.go | 50 ++----------------- .../inject_control_plane_test.go | 12 ++--- .../mutation/machinedetails/variables_test.go | 14 +++--- 4 files changed, 23 insertions(+), 75 deletions(-) diff --git a/api/v1alpha1/nutanix_node_types.go b/api/v1alpha1/nutanix_node_types.go index 60518a38e..f9cae83d7 100644 --- a/api/v1alpha1/nutanix_node_types.go +++ b/api/v1alpha1/nutanix_node_types.go @@ -29,27 +29,27 @@ type NutanixMachineDetails struct { // image identifies the image uploaded to Prism Central (PC). The identifier // (uuid or name) can be obtained from the console or API. // +kubebuilder:validation:Required - Image NutanixResourceIdentifier `json:"image"` + Image capxv1.NutanixResourceIdentifier `json:"image"` // cluster identifies the Prism Element in which the machine will be created. // The identifier (uuid or name) can be obtained from the console or API. // +kubebuilder:validation:Required - Cluster NutanixResourceIdentifier `json:"cluster"` + Cluster capxv1.NutanixResourceIdentifier `json:"cluster"` // subnet identifies the network subnet to use for the machine. // The identifier (uuid or name) can be obtained from the console or API. // +kubebuilder:validation:Required - Subnets []NutanixResourceIdentifier `json:"subnets"` + Subnets []capxv1.NutanixResourceIdentifier `json:"subnets"` // List of categories that need to be added to the machines. Categories must already // exist in Prism Central. One category key can have more than one value. // +kubebuilder:validation:Optional - AdditionalCategories []NutanixCategoryIdentifier `json:"additionalCategories,omitempty"` + AdditionalCategories []capxv1.NutanixCategoryIdentifier `json:"additionalCategories,omitempty"` // Defines the boot type of the virtual machine. Only supports UEFI and Legacy // +kubebuilder:validation:Optional // +kubebuilder:validation:Enum:=legacy;uefi - BootType NutanixBootType `json:"bootType"` + BootType capxv1.NutanixBootType `json:"bootType"` // systemDiskSize is size (in Quantity format) of the system disk of the VM // The minimum systemDiskSize is 20Gi bytes @@ -59,19 +59,9 @@ type NutanixMachineDetails struct { // add the virtual machines to the project defined in Prism Central. // The project must already be present in the Prism Central. // +kubebuilder:validation:Optional - Project *NutanixResourceIdentifier `json:"project,omitempty"` + Project *capxv1.NutanixResourceIdentifier `json:"project,omitempty"` // List of GPU devices that need to be added to the machines. // +kubebuilder:validation:Optional GPUs []capxv1.NutanixGPU `json:"gpus,omitempty"` } - -// NutanixIdentifierType is an enumeration of different resource identifier types. -type NutanixIdentifierType capxv1.NutanixIdentifierType - -// NutanixBootType is an enumeration of different boot types. -type NutanixBootType capxv1.NutanixBootType - -type NutanixResourceIdentifier capxv1.NutanixResourceIdentifier - -type NutanixCategoryIdentifier capxv1.NutanixCategoryIdentifier diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 1fbf78849..0753fdc56 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -966,21 +966,6 @@ func (in *NFD) DeepCopy() *NFD { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NutanixCategoryIdentifier) DeepCopyInto(out *NutanixCategoryIdentifier) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixCategoryIdentifier. -func (in *NutanixCategoryIdentifier) DeepCopy() *NutanixCategoryIdentifier { - if in == nil { - return nil - } - out := new(NutanixCategoryIdentifier) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NutanixClusterConfig) DeepCopyInto(out *NutanixClusterConfig) { *out = *in @@ -1046,20 +1031,20 @@ func (in *NutanixMachineDetails) DeepCopyInto(out *NutanixMachineDetails) { in.Cluster.DeepCopyInto(&out.Cluster) if in.Subnets != nil { in, out := &in.Subnets, &out.Subnets - *out = make([]NutanixResourceIdentifier, len(*in)) + *out = make([]v1beta1.NutanixResourceIdentifier, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.AdditionalCategories != nil { in, out := &in.AdditionalCategories, &out.AdditionalCategories - *out = make([]NutanixCategoryIdentifier, len(*in)) + *out = make([]v1beta1.NutanixCategoryIdentifier, len(*in)) copy(*out, *in) } out.SystemDiskSize = in.SystemDiskSize.DeepCopy() if in.Project != nil { in, out := &in.Project, &out.Project - *out = new(NutanixResourceIdentifier) + *out = new(v1beta1.NutanixResourceIdentifier) (*in).DeepCopyInto(*out) } if in.GPUs != nil { @@ -1144,9 +1129,7 @@ func (in *NutanixNodeSpec) DeepCopy() *NutanixNodeSpec { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NutanixPrismCentralEndpointCredentials) DeepCopyInto( - out *NutanixPrismCentralEndpointCredentials, -) { +func (in *NutanixPrismCentralEndpointCredentials) DeepCopyInto(out *NutanixPrismCentralEndpointCredentials) { *out = *in out.SecretRef = in.SecretRef } @@ -1177,31 +1160,6 @@ func (in *NutanixPrismCentralEndpointSpec) DeepCopy() *NutanixPrismCentralEndpoi return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NutanixResourceIdentifier) DeepCopyInto(out *NutanixResourceIdentifier) { - *out = *in - if in.UUID != nil { - in, out := &in.UUID, &out.UUID - *out = new(string) - **out = **in - } - if in.Name != nil { - in, out := &in.Name, &out.Name - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixResourceIdentifier. -func (in *NutanixResourceIdentifier) DeepCopy() *NutanixResourceIdentifier { - if in == nil { - return nil - } - out := new(NutanixResourceIdentifier) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NutanixSpec) DeepCopyInto(out *NutanixSpec) { *out = *in diff --git a/pkg/handlers/nutanix/mutation/machinedetails/inject_control_plane_test.go b/pkg/handlers/nutanix/mutation/machinedetails/inject_control_plane_test.go index 7ce186425..cb425b949 100644 --- a/pkg/handlers/nutanix/mutation/machinedetails/inject_control_plane_test.go +++ b/pkg/handlers/nutanix/mutation/machinedetails/inject_control_plane_test.go @@ -20,26 +20,26 @@ import ( var ( variableWithAllFieldsSet = v1alpha1.NutanixMachineDetails{ - BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy), + BootType: capxv1.NutanixBootTypeLegacy, VCPUSockets: 2, VCPUsPerSocket: 1, - Image: v1alpha1.NutanixResourceIdentifier{ + Image: capxv1.NutanixResourceIdentifier{ Type: capxv1.NutanixIdentifierName, Name: ptr.To("fake-image"), }, - Cluster: v1alpha1.NutanixResourceIdentifier{ + Cluster: capxv1.NutanixResourceIdentifier{ Type: capxv1.NutanixIdentifierName, Name: ptr.To("fake-pe-cluster"), }, MemorySize: resource.MustParse("8Gi"), SystemDiskSize: resource.MustParse("40Gi"), - Subnets: []v1alpha1.NutanixResourceIdentifier{ + Subnets: []capxv1.NutanixResourceIdentifier{ { Type: capxv1.NutanixIdentifierName, Name: ptr.To("fake-subnet"), }, }, - AdditionalCategories: []v1alpha1.NutanixCategoryIdentifier{ + AdditionalCategories: []capxv1.NutanixCategoryIdentifier{ { Key: "fake-key", Value: "fake-value", @@ -49,7 +49,7 @@ var ( Value: "fake-value2", }, }, - Project: ptr.To(v1alpha1.NutanixResourceIdentifier{ + Project: ptr.To(capxv1.NutanixResourceIdentifier{ Type: capxv1.NutanixIdentifierName, Name: ptr.To("fake-project"), }), diff --git a/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go b/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go index ad85fc9ac..6b28c1f99 100644 --- a/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go +++ b/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go @@ -20,7 +20,7 @@ func TestVariableValidation(t *testing.T) { withAdditionalCategories := minimumClusterConfigSpec() //nolint:lll // gofumpt formats is this way - withAdditionalCategories.ControlPlane.Nutanix.MachineDetails.AdditionalCategories = []v1alpha1.NutanixCategoryIdentifier{ + withAdditionalCategories.ControlPlane.Nutanix.MachineDetails.AdditionalCategories = []capxv1.NutanixCategoryIdentifier{ { Key: "fake-key", Value: "fake-value1", @@ -33,7 +33,7 @@ func TestVariableValidation(t *testing.T) { withProject := minimumClusterConfigSpec() withProject.ControlPlane.Nutanix.MachineDetails.Project = ptr.To( - v1alpha1.NutanixResourceIdentifier{ + capxv1.NutanixResourceIdentifier{ Type: capxv1.NutanixIdentifierName, Name: ptr.To("fake-project"), }, @@ -50,7 +50,7 @@ func TestVariableValidation(t *testing.T) { invalidProjectType := minimumClusterConfigSpec() invalidProjectType.ControlPlane.Nutanix.MachineDetails.Project = ptr.To( - v1alpha1.NutanixResourceIdentifier{ + capxv1.NutanixResourceIdentifier{ Type: "invalid-project-type", Name: ptr.To("fake-project"), }, @@ -102,20 +102,20 @@ func minimumClusterConfigSpec() v1alpha1.NutanixClusterConfigSpec { ControlPlane: &v1alpha1.NutanixNodeConfigSpec{ Nutanix: &v1alpha1.NutanixNodeSpec{ MachineDetails: v1alpha1.NutanixMachineDetails{ - BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy), + BootType: capxv1.NutanixBootTypeLegacy, VCPUSockets: 2, VCPUsPerSocket: 1, - Image: v1alpha1.NutanixResourceIdentifier{ + Image: capxv1.NutanixResourceIdentifier{ Type: capxv1.NutanixIdentifierName, Name: ptr.To("fake-image"), }, - Cluster: v1alpha1.NutanixResourceIdentifier{ + Cluster: capxv1.NutanixResourceIdentifier{ Type: capxv1.NutanixIdentifierName, Name: ptr.To("fake-pe-cluster"), }, MemorySize: resource.MustParse("8Gi"), SystemDiskSize: resource.MustParse("40Gi"), - Subnets: []v1alpha1.NutanixResourceIdentifier{}, + Subnets: []capxv1.NutanixResourceIdentifier{}, }, }, },