diff --git a/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/conditions.go b/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/conditions.go index a089099ff..7312cb1dd 100644 --- a/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/conditions.go +++ b/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/conditions.go @@ -74,5 +74,7 @@ const ( // CredentialRefSecretOwnerSetCondition shows the status of setting the Owner CredentialRefSecretOwnerSetCondition capiv1.ConditionType = "CredentialRefSecretOwnerSet" - CredentialRefSecretOwnerSetFailed = "CredentialRefSecretOwnerSetFailed" + CredentialRefSecretOwnerSetFailed = "CredentialRefSecretOwnerSetFailed" + TrustBundleSecretOwnerSetCondition = "TrustBundleSecretOwnerSet" + TrustBundleSecretOwnerSetFailed = "TrustBundleSecretOwnerSetFailed" ) diff --git a/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixcluster_types.go b/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixcluster_types.go index daf954f2a..ae91f1c69 100644 --- a/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixcluster_types.go +++ b/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixcluster_types.go @@ -17,9 +17,11 @@ limitations under the License. package v1beta1 import ( + "cmp" "fmt" credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" capiv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/errors" @@ -128,8 +130,6 @@ type NutanixFailureDomain struct { // obtained from the Prism Central console or using the prism_central API. // +kubebuilder:validation:Required // +kubebuilder:validation:MinItems=1 - // +listType=map - // +listMapKey=type Subnets []NutanixResourceIdentifier `json:"subnets"` // indicates if a failure domain is suited for control plane nodes @@ -162,6 +162,24 @@ func (ncl *NutanixCluster) GetPrismCentralCredentialRef() (*credentialTypes.Nuta return prismCentralInfo.CredentialRef, nil } +// GetPrismCentralTrustBundle returns the trust bundle reference for the Nutanix Prism Central. +func (ncl *NutanixCluster) GetPrismCentralTrustBundle() *credentialTypes.NutanixTrustBundleReference { + prismCentralInfo := ncl.Spec.PrismCentral + if prismCentralInfo == nil || + prismCentralInfo.AdditionalTrustBundle == nil || + prismCentralInfo.AdditionalTrustBundle.Kind == credentialTypes.NutanixTrustBundleKindString { + return nil + } + + return prismCentralInfo.AdditionalTrustBundle +} + +// GetNamespacedName returns the namespaced name of the NutanixCluster. +func (ncl *NutanixCluster) GetNamespacedName() string { + namespace := cmp.Or(ncl.Namespace, corev1.NamespaceDefault) + return fmt.Sprintf("%s/%s", namespace, ncl.Name) +} + // +kubebuilder:object:root=true // NutanixClusterList contains a list of NutanixCluster diff --git a/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixmachine_types.go b/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixmachine_types.go index 170011f60..35f7344e2 100644 --- a/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixmachine_types.go +++ b/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixmachine_types.go @@ -35,6 +35,16 @@ const ( // resources associated with NutanixMachine before removing it from the // API Server. NutanixMachineFinalizer = "nutanixmachine.infrastructure.cluster.x-k8s.io" + + // NutanixMachineBootstrapRefKindSecret represents the Kind of Secret + // referenced by NutanixMachine's BootstrapRef. + NutanixMachineBootstrapRefKindSecret = "Secret" + + // NutanixMachineBootstrapRefKindImage represents the Kind of Image + // referenced by NutanixMachine's BootstrapRef. If the BootstrapRef.Kind is set + // to Image, the NutanixMachine will be created with the image mounted + // as a CD-ROM. + NutanixMachineBootstrapRefKindImage = "Image" ) // NutanixMachineSpec defines the desired state of NutanixMachine @@ -42,7 +52,9 @@ type NutanixMachineSpec struct { // SPEC FIELDS - desired state of NutanixMachine // Important: Run "make" to regenerate code after modifying this file - ProviderID string `json:"providerID"` + // ProviderID is the unique identifier as specified by the cloud provider. + // +optional + ProviderID string `json:"providerID,omitempty"` // vcpusPerSocket is the number of vCPUs per socket of the VM // +kubebuilder:validation:Required // +kubebuilder:validation:Minimum=1 diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 0753fdc56..51617e075 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1129,7 +1129,9 @@ 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 } diff --git a/charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/nutanix-cluster-class.yaml b/charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/nutanix-cluster-class.yaml index 41966e73c..a47df3da6 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/nutanix-cluster-class.yaml +++ b/charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/nutanix-cluster-class.yaml @@ -196,7 +196,6 @@ spec: name: "" type: name memorySize: 4Gi - providerID: nutanix://vm-uuid subnet: - name: "" type: name @@ -221,7 +220,6 @@ spec: name: "" type: name memorySize: 4Gi - providerID: nutanix://vm-uuid subnet: - name: "" type: name diff --git a/pkg/handlers/nutanix/mutation/machinedetails/inject.go b/pkg/handlers/nutanix/mutation/machinedetails/inject.go index 123fe9359..41fa11360 100644 --- a/pkg/handlers/nutanix/mutation/machinedetails/inject.go +++ b/pkg/handlers/nutanix/mutation/machinedetails/inject.go @@ -92,9 +92,9 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate( spec := obj.Spec.Template.Spec - spec.BootType = capxv1.NutanixBootType(nutanixMachineDetailsVar.BootType) - spec.Cluster = capxv1.NutanixResourceIdentifier(nutanixMachineDetailsVar.Cluster) - spec.Image = capxv1.NutanixResourceIdentifier(nutanixMachineDetailsVar.Image) + spec.BootType = nutanixMachineDetailsVar.BootType + spec.Cluster = nutanixMachineDetailsVar.Cluster + spec.Image = nutanixMachineDetailsVar.Image spec.VCPUSockets = nutanixMachineDetailsVar.VCPUSockets spec.VCPUsPerSocket = nutanixMachineDetailsVar.VCPUsPerSocket @@ -105,21 +105,19 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate( []capxv1.NutanixResourceIdentifier, len(nutanixMachineDetailsVar.Subnets), ) - for i, subnet := range nutanixMachineDetailsVar.Subnets { - spec.Subnets[i] = capxv1.NutanixResourceIdentifier(subnet) - } + + copy(spec.Subnets, nutanixMachineDetailsVar.Subnets) spec.AdditionalCategories = make( []capxv1.NutanixCategoryIdentifier, len(nutanixMachineDetailsVar.AdditionalCategories), ) - for i, category := range nutanixMachineDetailsVar.AdditionalCategories { - spec.AdditionalCategories[i] = capxv1.NutanixCategoryIdentifier(category) - } + + copy(spec.AdditionalCategories, nutanixMachineDetailsVar.AdditionalCategories) if nutanixMachineDetailsVar.Project != nil { spec.Project = ptr.To( - capxv1.NutanixResourceIdentifier(*nutanixMachineDetailsVar.Project), + *nutanixMachineDetailsVar.Project, ) } spec.GPUs = make( diff --git a/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go b/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go index 6b28c1f99..68efe78f1 100644 --- a/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go +++ b/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go @@ -19,7 +19,7 @@ func TestVariableValidation(t *testing.T) { requiredFields := minimumClusterConfigSpec() withAdditionalCategories := minimumClusterConfigSpec() - //nolint:lll // gofumpt formats is this way + withAdditionalCategories.ControlPlane.Nutanix.MachineDetails.AdditionalCategories = []capxv1.NutanixCategoryIdentifier{ { Key: "fake-key",