Skip to content

Commit 3ab1feb

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 3ab1feb

15 files changed

+142
-112
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: 4 additions & 6 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
@@ -152,13 +150,13 @@ func (ncl *NutanixCluster) SetConditions(conditions capiv1.Conditions) {
152150
func (ncl *NutanixCluster) GetPrismCentralCredentialRef() (*credentialTypes.NutanixCredentialReference, error) {
153151
prismCentralInfo := ncl.Spec.PrismCentral
154152
if prismCentralInfo == nil {
155-
return nil, nil
153+
return nil, fmt.Errorf("prismCentral info is not provided.")
156154
}
157155
if prismCentralInfo.CredentialRef == nil {
158-
return nil, fmt.Errorf("credentialRef must be set on prismCentral attribute for cluster %s in namespace %s", ncl.Name, ncl.Namespace)
156+
return nil, nil // returning nil so that we can use default controller's secret
159157
}
160158
if prismCentralInfo.CredentialRef.Kind != credentialTypes.SecretKind {
161-
return nil, nil
159+
return nil, fmt.Errorf("credentialRef should be of kind Secret")
162160
}
163161

164162
return prismCentralInfo.CredentialRef, nil

api/v1beta1/nutanixcluster_types_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/stretchr/testify/assert"
2424
corev1 "k8s.io/api/core/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2627

2728
"github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
2829
)
@@ -43,6 +44,10 @@ func TestGetCredentialRefForCluster(t *testing.T) {
4344
Namespace: corev1.NamespaceDefault,
4445
},
4546
Spec: NutanixClusterSpec{
47+
ControlPlaneEndpoint: capiv1.APIEndpoint{
48+
Host: "host",
49+
Port: 6443,
50+
},
4651
PrismCentral: &credentials.NutanixPrismEndpoint{
4752
Address: "address",
4853
Port: 9440,
@@ -61,45 +66,54 @@ func TestGetCredentialRefForCluster(t *testing.T) {
6166
},
6267
},
6368
{
64-
name: "prismCentralInfo is nil, should not fail",
69+
name: "prismCentralInfo is nil, should fail",
6570
nutanixCluster: &NutanixCluster{
6671
ObjectMeta: metav1.ObjectMeta{
6772
Name: "test",
6873
Namespace: corev1.NamespaceDefault,
6974
},
7075
Spec: NutanixClusterSpec{},
7176
},
77+
expectedErr: fmt.Errorf("prismCentral info is not provided."),
7278
},
7379
{
74-
name: "CredentialRef kind is not kind Secret, should not fail",
80+
name: "CredentialRef kind is not kind Secret, should fail",
7581
nutanixCluster: &NutanixCluster{
7682
ObjectMeta: metav1.ObjectMeta{
7783
Name: "test",
7884
Namespace: corev1.NamespaceDefault,
7985
},
8086
Spec: NutanixClusterSpec{
87+
ControlPlaneEndpoint: capiv1.APIEndpoint{
88+
Host: "host",
89+
Port: 6443,
90+
},
8191
PrismCentral: &credentials.NutanixPrismEndpoint{
8292
CredentialRef: &credentials.NutanixCredentialReference{
8393
Kind: "unknown",
8494
},
8595
},
8696
},
8797
},
98+
expectedErr: fmt.Errorf("credentialRef should be of kind Secret"),
8899
},
89100
{
90-
name: "prismCentralInfo is not nil but CredentialRef is nil, should fail",
101+
name: "prismCentralInfo is not nil but CredentialRef is nil, should not fail",
91102
nutanixCluster: &NutanixCluster{
92103
ObjectMeta: metav1.ObjectMeta{
93104
Name: "test",
94105
Namespace: corev1.NamespaceDefault,
95106
},
96107
Spec: NutanixClusterSpec{
108+
ControlPlaneEndpoint: capiv1.APIEndpoint{
109+
Host: "host",
110+
Port: 6443,
111+
},
97112
PrismCentral: &credentials.NutanixPrismEndpoint{
98113
Address: "address",
99114
},
100115
},
101116
},
102-
expectedErr: fmt.Errorf("credentialRef must be set on prismCentral attribute for cluster test in namespace default"),
103117
},
104118
}
105119
for _, tt := range tests {

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.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func (r *NutanixClusterReconciler) reconcileCredentialRef(ctx context.Context, n
377377
log := ctrl.LoggerFrom(ctx)
378378
credentialRef, err := getPrismCentralCredentialRefForCluster(nutanixCluster)
379379
if err != nil {
380+
log.Error(err, fmt.Sprintf("error occurred while getting credential ref for cluster %s", nutanixCluster.Name))
380381
return err
381382
}
382383

0 commit comments

Comments
 (0)