Skip to content

Commit d2936df

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 fac5b21 commit d2936df

11 files changed

+93
-59
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ cluster-templates: ## Generate cluster templates for all flavors
286286
.PHONY: docker-build-e2e
287287
docker-build-e2e: ## Build docker image with the manager with e2e tag.
288288
echo "Git commit hash: ${GIT_COMMIT_HASH}"
289-
KO_DOCKER_REPO=ko.local GOFLAGS="-ldflags=-X=main.gitCommitHash=${GIT_COMMIT_HASH}" ko build -B --platform=${PLATFORMS_E2E} -t ${IMG_TAG} -L .
289+
KO_DOCKER_REPO=ko.local GOFLAGS="-ldflags=-X=main.gitCommitHash=${GIT_COMMIT_HASH}" ko build -B --platform=${PLATFORMS_E2E} -t ${IMG_TAG} .
290290
docker tag ko.local/cluster-api-provider-nutanix:${IMG_TAG} ${IMG_REPO}:e2e
291291

292292
.PHONY: prepare-local-clusterctl
@@ -335,7 +335,7 @@ test-e2e: docker-build-e2e cluster-e2e-templates cluster-templates ## Run the en
335335
mkdir -p $(ARTIFACTS)
336336
NUTANIX_LOG_LEVEL=debug ginkgo -v \
337337
--trace \
338-
--progress \
338+
--show-node-events \
339339
--tags=e2e \
340340
--label-filter=$(LABEL_FILTER_ARGS) \
341341
$(_SKIP_ARGS) \
@@ -345,7 +345,7 @@ test-e2e: docker-build-e2e cluster-e2e-templates cluster-templates ## Run the en
345345
--output-dir="$(ARTIFACTS)" \
346346
--junit-report=${JUNIT_REPORT_FILE} \
347347
--timeout="24h" \
348-
--always-emit-ginkgo-writer \
348+
-v \
349349
$(GINKGO_ARGS) ./test/e2e -- \
350350
-e2e.artifacts-folder="$(ARTIFACTS)" \
351351
-e2e.config="$(E2E_CONF_FILE)" \
@@ -357,7 +357,7 @@ test-e2e-no-kubeproxy: docker-build-e2e cluster-e2e-templates-no-kubeproxy clust
357357
mkdir -p $(ARTIFACTS)
358358
NUTANIX_LOG_LEVEL=debug ginkgo -v \
359359
--trace \
360-
--progress \
360+
--show-node-events \
361361
--tags=e2e \
362362
--label-filter=$(LABEL_FILTER_ARGS) \
363363
$(_SKIP_ARGS) \
@@ -366,7 +366,7 @@ test-e2e-no-kubeproxy: docker-build-e2e cluster-e2e-templates-no-kubeproxy clust
366366
--output-dir="$(ARTIFACTS)" \
367367
--junit-report=${JUNIT_REPORT_FILE} \
368368
--timeout="24h" \
369-
--always-emit-ginkgo-writer \
369+
-v \
370370
$(GINKGO_ARGS) ./test/e2e -- \
371371
-e2e.artifacts-folder="$(ARTIFACTS)" \
372372
-e2e.config="$(E2E_CONF_FILE)" \

api/v1beta1/nutanixcluster_types.go

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

4949
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
5050
// host can be either DNS name or ip address
51-
// +optional
5251
ControlPlaneEndpoint capiv1.APIEndpoint `json:"controlPlaneEndpoint"`
5352

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

6159
// failureDomains configures failure domains information for the Nutanix platform.
@@ -64,7 +62,7 @@ type NutanixClusterSpec struct {
6462
// +listType=map
6563
// +listMapKey=name
6664
// +optional
67-
FailureDomains []NutanixFailureDomain `json:"failureDomains"`
65+
FailureDomains []NutanixFailureDomain `json:"failureDomains,omitempty"`
6866
}
6967

7068
// 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: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ import (
2323
"testing"
2424

2525
"github.com/golang/mock/gomock"
26-
credentialtypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
26+
credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
2727
prismclientv3 "github.com/nutanix-cloud-native/prism-go-client/v3"
2828
. "github.com/onsi/ginkgo/v2"
2929
. "github.com/onsi/gomega"
3030
"github.com/stretchr/testify/assert"
3131
"github.com/stretchr/testify/require"
3232
corev1 "k8s.io/api/core/v1"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34+
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3435
"sigs.k8s.io/cluster-api/util"
3536

3637
infrav1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
@@ -60,7 +61,8 @@ func TestControllerHelpers(t *testing.T) {
6061
Namespace: "default",
6162
},
6263
Spec: infrav1.NutanixClusterSpec{
63-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
64+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
65+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
6466
// Adding port info to override default value (0)
6567
Port: 9440,
6668
},
@@ -134,11 +136,11 @@ func TestGetPrismCentralClientForCluster(t *testing.T) {
134136
ctx := context.Background()
135137
cluster := &infrav1.NutanixCluster{
136138
Spec: infrav1.NutanixClusterSpec{
137-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
139+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
138140
Address: "prismcentral.nutanix.com",
139141
Port: 9440,
140-
CredentialRef: &credentialtypes.NutanixCredentialReference{
141-
Kind: credentialtypes.SecretKind,
142+
CredentialRef: &credentialTypes.NutanixCredentialReference{
143+
Kind: credentialTypes.SecretKind,
142144
Name: "test-credential",
143145
Namespace: "test-ns",
144146
},
@@ -164,9 +166,9 @@ func TestGetPrismCentralClientForCluster(t *testing.T) {
164166
t.Run("GetOrCreate Fails", func(t *testing.T) {
165167
ctrl := gomock.NewController(t)
166168

167-
creds := []credentialtypes.Credential{
169+
creds := []credentialTypes.Credential{
168170
{
169-
Type: credentialtypes.BasicAuthCredentialType,
171+
Type: credentialTypes.BasicAuthCredentialType,
170172
Data: []byte(`{"prismCentral":{"username":"user","password":"password"}}`),
171173
},
172174
}
@@ -175,7 +177,7 @@ func TestGetPrismCentralClientForCluster(t *testing.T) {
175177

176178
secret := &corev1.Secret{
177179
Data: map[string][]byte{
178-
credentialtypes.KeyName: credsMarshal,
180+
credentialTypes.KeyName: credsMarshal,
179181
},
180182
}
181183

@@ -202,9 +204,9 @@ func TestGetPrismCentralClientForCluster(t *testing.T) {
202204
// Create a new client cache with session auth disabled to avoid network calls in tests
203205
nutanixclient.NutanixClientCache = prismclientv3.NewClientCache()
204206

205-
creds := []credentialtypes.Credential{
207+
creds := []credentialTypes.Credential{
206208
{
207-
Type: credentialtypes.BasicAuthCredentialType,
209+
Type: credentialTypes.BasicAuthCredentialType,
208210
Data: []byte(`{"prismCentral":{"username":"user","password":"password"}}`),
209211
},
210212
}
@@ -213,7 +215,7 @@ func TestGetPrismCentralClientForCluster(t *testing.T) {
213215
require.NoError(t, err)
214216
secret := &corev1.Secret{
215217
Data: map[string][]byte{
216-
credentialtypes.KeyName: credsMarshal,
218+
credentialTypes.KeyName: credsMarshal,
217219
},
218220
}
219221

controllers/nutanixcluster_controller_test.go

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"testing"
2323

2424
"github.com/golang/mock/gomock"
25-
credentialtypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
25+
credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
2626
. "github.com/onsi/ginkgo/v2"
2727
. "github.com/onsi/gomega"
2828
"github.com/onsi/gomega/gstruct"
@@ -86,7 +86,8 @@ func TestNutanixClusterReconciler(t *testing.T) {
8686
UID: utilruntime.NewUUID(),
8787
},
8888
Spec: infrav1.NutanixClusterSpec{
89-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
89+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
90+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
9091
// Adding port info to override default value (0)
9192
Port: 9440,
9293
},
@@ -248,7 +249,8 @@ func TestNutanixClusterReconciler(t *testing.T) {
248249
Namespace: corev1.NamespaceDefault,
249250
},
250251
Spec: infrav1.NutanixClusterSpec{
251-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
252+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
253+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
252254
// Adding port info to override default value (0)
253255
Port: 9440,
254256
},
@@ -257,8 +259,8 @@ func TestNutanixClusterReconciler(t *testing.T) {
257259
g.Expect(k8sClient.Create(ctx, additionalNtnxCluster)).To(Succeed())
258260

259261
// Add credential ref to the ntnxCluster resource
260-
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialtypes.NutanixCredentialReference{
261-
Kind: credentialtypes.SecretKind,
262+
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialTypes.NutanixCredentialReference{
263+
Kind: credentialTypes.SecretKind,
262264
Name: ntnxSecret.Name,
263265
Namespace: ntnxSecret.Namespace,
264266
}
@@ -280,8 +282,8 @@ func TestNutanixClusterReconciler(t *testing.T) {
280282
})
281283
It("should add credentialRef and finalizer if not owned by other cluster", func() {
282284
// Add credential ref to the ntnxCluster resource
283-
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialtypes.NutanixCredentialReference{
284-
Kind: credentialtypes.SecretKind,
285+
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialTypes.NutanixCredentialReference{
286+
Kind: credentialTypes.SecretKind,
285287
Name: ntnxSecret.Name,
286288
Namespace: ntnxSecret.Namespace,
287289
}
@@ -307,8 +309,8 @@ func TestNutanixClusterReconciler(t *testing.T) {
307309
})
308310
It("does not add another credentialRef if it is already set", func() {
309311
// Add credential ref to the ntnxCluster resource
310-
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialtypes.NutanixCredentialReference{
311-
Kind: credentialtypes.SecretKind,
312+
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialTypes.NutanixCredentialReference{
313+
Kind: credentialTypes.SecretKind,
312314
Name: ntnxSecret.Name,
313315
Namespace: ntnxSecret.Namespace,
314316
}
@@ -344,8 +346,8 @@ func TestNutanixClusterReconciler(t *testing.T) {
344346

345347
It("allows multiple ownerReferences with different kinds", func() {
346348
// Add credential ref to the ntnxCluster resource
347-
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialtypes.NutanixCredentialReference{
348-
Kind: credentialtypes.SecretKind,
349+
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialTypes.NutanixCredentialReference{
350+
Kind: credentialTypes.SecretKind,
349351
Name: ntnxSecret.Name,
350352
Namespace: ntnxSecret.Namespace,
351353
}
@@ -379,8 +381,8 @@ func TestNutanixClusterReconciler(t *testing.T) {
379381
})
380382
It("should error if secret does not exist", func() {
381383
// Add credential ref to the ntnxCluster resource
382-
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialtypes.NutanixCredentialReference{
383-
Kind: credentialtypes.SecretKind,
384+
ntnxCluster.Spec.PrismCentral.CredentialRef = &credentialTypes.NutanixCredentialReference{
385+
Kind: credentialTypes.SecretKind,
384386
Name: ntnxSecret.Name,
385387
Namespace: ntnxSecret.Namespace,
386388
}
@@ -412,10 +414,11 @@ func TestNutanixClusterReconciler(t *testing.T) {
412414
Namespace: "default",
413415
},
414416
Spec: infrav1.NutanixClusterSpec{
415-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
417+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
418+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
416419
// Adding port info to override default value (0)
417420
Port: 9440,
418-
CredentialRef: &credentialtypes.NutanixCredentialReference{
421+
CredentialRef: &credentialTypes.NutanixCredentialReference{
419422
Name: "test",
420423
Namespace: "default",
421424
Kind: "Secret",
@@ -474,7 +477,8 @@ func TestNutanixClusterReconciler(t *testing.T) {
474477
Namespace: "default",
475478
},
476479
Spec: infrav1.NutanixClusterSpec{
477-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
480+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
481+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
478482
// Adding port info to override default value (0)
479483
Port: 9440,
480484
},
@@ -508,10 +512,11 @@ func TestNutanixClusterReconciler(t *testing.T) {
508512
Namespace: "default",
509513
},
510514
Spec: infrav1.NutanixClusterSpec{
511-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
515+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
516+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
512517
// Adding port info to override default value (0)
513518
Port: 9440,
514-
CredentialRef: &credentialtypes.NutanixCredentialReference{
519+
CredentialRef: &credentialTypes.NutanixCredentialReference{
515520
Name: "test",
516521
Namespace: "default",
517522
Kind: "Secret",
@@ -533,34 +538,23 @@ func TestNutanixClusterReconciler(t *testing.T) {
533538
})
534539
})
535540

536-
Context("Delete credentials ref reconcile failed: PrismCentral Info is null", func() {
541+
Context("NutanixCluster creation failed: PrismCentral Info is null", func() {
537542
It("Should not return error", func() {
538543
ctx := context.Background()
539-
reconciler := &NutanixClusterReconciler{
540-
Client: k8sClient,
541-
Scheme: runtime.NewScheme(),
542-
}
543544

544545
ntnxCluster := &infrav1.NutanixCluster{
545546
ObjectMeta: metav1.ObjectMeta{
546547
Name: "test",
547548
Namespace: "default",
548549
},
549550
Spec: infrav1.NutanixClusterSpec{
550-
PrismCentral: nil,
551+
ControlPlaneEndpoint: capiv1.APIEndpoint{},
552+
PrismCentral: nil,
551553
},
552554
}
553555

554556
// Create the NutanixCluster object
555-
g.Expect(k8sClient.Create(ctx, ntnxCluster)).To(Succeed())
556-
defer func() {
557-
err := k8sClient.Delete(ctx, ntnxCluster)
558-
Expect(err).NotTo(HaveOccurred())
559-
}()
560-
561-
// Reconile Delete credential ref
562-
err := reconciler.reconcileCredentialRefDelete(ctx, ntnxCluster)
563-
g.Expect(err).NotTo(HaveOccurred())
557+
g.Expect(k8sClient.Create(ctx, ntnxCluster)).NotTo(Succeed())
564558
})
565559
})
566560
})
@@ -587,9 +581,9 @@ func TestReconcileCredentialRefWithValidCredentialRef(t *testing.T) {
587581

588582
nutanixCluster := &infrav1.NutanixCluster{
589583
Spec: infrav1.NutanixClusterSpec{
590-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
591-
CredentialRef: &credentialtypes.NutanixCredentialReference{
592-
Kind: credentialtypes.SecretKind,
584+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
585+
CredentialRef: &credentialTypes.NutanixCredentialReference{
586+
Kind: credentialTypes.SecretKind,
593587
Name: "test-credential",
594588
Namespace: "test-ns",
595589
},
@@ -625,9 +619,9 @@ func TestReconcileCredentialRefWithValidCredentialRefFailedUpdate(t *testing.T)
625619
fakeClient := mockctlclient.NewMockClient(mockCtrl)
626620
nutanixCluster := &infrav1.NutanixCluster{
627621
Spec: infrav1.NutanixClusterSpec{
628-
PrismCentral: &credentialtypes.NutanixPrismEndpoint{
629-
CredentialRef: &credentialtypes.NutanixCredentialReference{
630-
Kind: credentialtypes.SecretKind,
622+
PrismCentral: &credentialTypes.NutanixPrismEndpoint{
623+
CredentialRef: &credentialTypes.NutanixCredentialReference{
624+
Kind: credentialTypes.SecretKind,
631625
Name: "test-credential",
632626
Namespace: "test-ns",
633627
},

templates/cluster-template-clusterclass.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,17 @@ metadata:
699699
spec:
700700
template:
701701
spec:
702+
controlPlaneEndpoint:
703+
host: PLACEHOLDER
704+
port: 6443
702705
failureDomains: []
706+
prismCentral:
707+
address: PLACEHOLDER
708+
credentialRef:
709+
kind: Secret
710+
name: PLACEHOLDER
711+
namespace: default
712+
port: 9440
703713
---
704714
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
705715
kind: NutanixMachineTemplate

0 commit comments

Comments
 (0)