Skip to content

Commit f3c7ef6

Browse files
committed
removed optional annotation from non-optional fields
same code as https://github.com/nutanix-cloud-native/cluster-api-provider-nutanix/pull/400/files which was reverted in #414
1 parent 8228f42 commit f3c7ef6

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

api/v1beta1/nutanixcluster_types.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ type NutanixClusterSpec struct {
4646

4747
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
4848
// host can be either DNS name or ip address
49-
// +optional
5049
ControlPlaneEndpoint capiv1.APIEndpoint `json:"controlPlaneEndpoint"`
5150

5251
// prismCentral holds the endpoint address and port to access the Nutanix Prism Central.
5352
// When a cluster-wide proxy is installed, by default, this endpoint will be accessed via the proxy.
5453
// Should you wish for communication with this endpoint not to be proxied, please add the endpoint to the
5554
// proxy spec.noProxy list.
56-
// +optional
5755
PrismCentral *credentialTypes.NutanixPrismEndpoint `json:"prismCentral"`
5856

5957
// failureDomains configures failure domains information for the Nutanix platform.
@@ -62,7 +60,7 @@ type NutanixClusterSpec struct {
6260
// +listType=map
6361
// +listMapKey=name
6462
// +optional
65-
FailureDomains []NutanixFailureDomain `json:"failureDomains"`
63+
FailureDomains []NutanixFailureDomain `json:"failureDomains,omitempty"`
6664
}
6765

6866
// NutanixClusterStatus defines the observed state of NutanixCluster

api/v1beta1/nutanixmachine_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type NutanixMachineSpec struct {
8383
Subnets []NutanixResourceIdentifier `json:"subnet"`
8484
// List of categories that need to be added to the machines. Categories must already exist in Prism Central
8585
// +kubebuilder:validation:Optional
86+
// +optional
8687
AdditionalCategories []NutanixCategoryIdentifier `json:"additionalCategories,omitempty"`
8788
// Add the machine resources to a Prism Central project
8889
// +optional
@@ -104,6 +105,7 @@ type NutanixMachineSpec struct {
104105

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

config/crd/bases/infrastructure.cluster.x-k8s.io_nutanixclusters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ spec:
512512
- address
513513
- port
514514
type: object
515+
required:
516+
- controlPlaneEndpoint
517+
- prismCentral
515518
type: object
516519
status:
517520
description: NutanixClusterStatus defines the observed state of NutanixCluster

config/crd/bases/infrastructure.cluster.x-k8s.io_nutanixclustertemplates.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ spec:
228228
- address
229229
- port
230230
type: object
231+
required:
232+
- controlPlaneEndpoint
233+
- prismCentral
231234
type: object
232235
required:
233236
- spec

controllers/helpers_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2526
"sigs.k8s.io/cluster-api/util"
2627

2728
infrav1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
@@ -52,6 +53,7 @@ func TestControllerHelpers(t *testing.T) {
5253
Namespace: "default",
5354
},
5455
Spec: infrav1.NutanixClusterSpec{
56+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
5557
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
5658
// Adding port info to override default value (0)
5759
Port: 9440,

controllers/nutanixcluster_controller_test.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func TestNutanixClusterReconciler(t *testing.T) {
8383
UID: utilruntime.NewUUID(),
8484
},
8585
Spec: infrav1.NutanixClusterSpec{
86+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
8687
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
8788
// Adding port info to override default value (0)
8889
Port: 9440,
@@ -245,6 +246,7 @@ func TestNutanixClusterReconciler(t *testing.T) {
245246
Namespace: corev1.NamespaceDefault,
246247
},
247248
Spec: infrav1.NutanixClusterSpec{
249+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
248250
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
249251
// Adding port info to override default value (0)
250252
Port: 9440,
@@ -409,6 +411,7 @@ func TestNutanixClusterReconciler(t *testing.T) {
409411
Namespace: "default",
410412
},
411413
Spec: infrav1.NutanixClusterSpec{
414+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
412415
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
413416
// Adding port info to override default value (0)
414417
Port: 9440,
@@ -471,6 +474,7 @@ func TestNutanixClusterReconciler(t *testing.T) {
471474
Namespace: "default",
472475
},
473476
Spec: infrav1.NutanixClusterSpec{
477+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
474478
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
475479
// Adding port info to override default value (0)
476480
Port: 9440,
@@ -505,6 +509,7 @@ func TestNutanixClusterReconciler(t *testing.T) {
505509
Namespace: "default",
506510
},
507511
Spec: infrav1.NutanixClusterSpec{
512+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
508513
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
509514
// Adding port info to override default value (0)
510515
Port: 9440,
@@ -530,34 +535,23 @@ func TestNutanixClusterReconciler(t *testing.T) {
530535
})
531536
})
532537

533-
Context("Delete credentials ref reconcile failed: PrismCentral Info is null", func() {
538+
Context("NutanixCluster creation failed: PrismCentral Info is null", func() {
534539
It("Should not return error", func() {
535540
ctx := context.Background()
536-
reconciler := &NutanixClusterReconciler{
537-
Client: k8sClient,
538-
Scheme: runtime.NewScheme(),
539-
}
540541

541542
ntnxCluster := &infrav1.NutanixCluster{
542543
ObjectMeta: metav1.ObjectMeta{
543544
Name: "test",
544545
Namespace: "default",
545546
},
546547
Spec: infrav1.NutanixClusterSpec{
547-
PrismCentral: nil,
548+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
549+
PrismCentral: nil,
548550
},
549551
}
550552

551553
// Create the NutanixCluster object
552-
g.Expect(k8sClient.Create(ctx, ntnxCluster)).To(Succeed())
553-
defer func() {
554-
err := k8sClient.Delete(ctx, ntnxCluster)
555-
Expect(err).NotTo(HaveOccurred())
556-
}()
557-
558-
// Reconile Delete credential ref
559-
err := reconciler.reconcileCredentialRefDelete(ctx, ntnxCluster)
560-
g.Expect(err).NotTo(HaveOccurred())
554+
g.Expect(k8sClient.Create(ctx, ntnxCluster)).NotTo(Succeed())
561555
})
562556
})
563557
})

0 commit comments

Comments
 (0)