Skip to content

Commit

Permalink
fix: fixes suggested from failing make pre-commit run
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderboltsid committed Jun 10, 2024
1 parent 1131754 commit ae37bd3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,26 @@ 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
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
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ spec:
name: ""
type: name
memorySize: 4Gi
providerID: nutanix://vm-uuid
subnet:
- name: ""
type: name
Expand All @@ -221,7 +220,6 @@ spec:
name: ""
type: name
memorySize: 4Gi
providerID: nutanix://vm-uuid
subnet:
- name: ""
type: name
Expand Down
18 changes: 8 additions & 10 deletions pkg/handlers/nutanix/mutation/machinedetails/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ae37bd3

Please sign in to comment.