Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit 52a08d2

Browse files
authored
Use LocalObjectReference from in-built corev1 package (#1178)
1 parent d571f2a commit 52a08d2

File tree

6 files changed

+25
-47
lines changed

6 files changed

+25
-47
lines changed

api/v1/mongodbcommunity_types.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/annotations"
1313

1414
appsv1 "k8s.io/api/apps/v1"
15+
corev1 "k8s.io/api/core/v1"
1516

1617
"github.com/mongodb/mongodb-kubernetes-operator/pkg/automationconfig"
1718
"github.com/mongodb/mongodb-kubernetes-operator/pkg/util/scale"
@@ -489,27 +490,18 @@ type TLS struct {
489490
// Alternatively, an entry tls.pem, containing the concatenation of cert and key, can be provided.
490491
// If all of tls.pem, tls.crt and tls.key are present, the tls.pem one needs to be equal to the concatenation of tls.crt and tls.key
491492
// +optional
492-
CertificateKeySecret LocalObjectReference `json:"certificateKeySecretRef"`
493+
CertificateKeySecret corev1.LocalObjectReference `json:"certificateKeySecretRef"`
493494

494495
// CaCertificateSecret is a reference to a Secret containing the certificate for the CA which signed the server certificates
495496
// The certificate is expected to be available under the key "ca.crt"
496497
// +optional
497-
CaCertificateSecret *LocalObjectReference `json:"caCertificateSecretRef,omitempty"`
498+
CaCertificateSecret *corev1.LocalObjectReference `json:"caCertificateSecretRef,omitempty"`
498499

499500
// CaConfigMap is a reference to a ConfigMap containing the certificate for the CA which signed the server certificates
500501
// The certificate is expected to be available under the key "ca.crt"
501502
// This field is ignored when CaCertificateSecretRef is configured
502503
// +optional
503-
CaConfigMap *LocalObjectReference `json:"caConfigMapRef,omitempty"`
504-
}
505-
506-
// LocalObjectReference is a reference to another Kubernetes object by name.
507-
// TODO: Replace with a type from the K8s API. CoreV1 has an equivalent
508-
//
509-
// "LocalObjectReference" type but it contains a TODO in its
510-
// description that we don't want in our CRD.
511-
type LocalObjectReference struct {
512-
Name string `json:"name"`
504+
CaConfigMap *corev1.LocalObjectReference `json:"caConfigMapRef,omitempty"`
513505
}
514506

515507
type Authentication struct {

api/v1/zz_generated.deepcopy.go

Lines changed: 3 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/mongodbcommunity.mongodb.com_mongodbcommunity.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ spec:
273273
under the key "ca.crt"
274274
properties:
275275
name:
276+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
277+
TODO: Add other useful fields. apiVersion, kind, uid?'
276278
type: string
277-
required:
278-
- name
279279
type: object
280280
caConfigMapRef:
281281
description: CaConfigMap is a reference to a ConfigMap containing
@@ -285,9 +285,9 @@ spec:
285285
is configured
286286
properties:
287287
name:
288+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
289+
TODO: Add other useful fields. apiVersion, kind, uid?'
288290
type: string
289-
required:
290-
- name
291291
type: object
292292
certificateKeySecretRef:
293293
description: CertificateKeySecret is a reference to a Secret
@@ -302,9 +302,9 @@ spec:
302302
and tls.key
303303
properties:
304304
name:
305+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
306+
TODO: Add other useful fields. apiVersion, kind, uid?'
305307
type: string
306-
required:
307-
- name
308308
type: object
309309
enabled:
310310
type: boolean

controllers/mongodb_tls_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,25 +405,25 @@ func TestPemSupport(t *testing.T) {
405405

406406
func TestTLSConfig_ReferencesToCACertAreValidated(t *testing.T) {
407407
type args struct {
408-
caConfigMap *mdbv1.LocalObjectReference
409-
caCertificateSecret *mdbv1.LocalObjectReference
408+
caConfigMap *corev1.LocalObjectReference
409+
caCertificateSecret *corev1.LocalObjectReference
410410
expectedError error
411411
}
412412
tests := map[string]args{
413413
"Success if reference to CA cert provided via secret": {
414-
caConfigMap: &mdbv1.LocalObjectReference{
414+
caConfigMap: &corev1.LocalObjectReference{
415415
Name: "certificateKeySecret"},
416416
caCertificateSecret: nil,
417417
},
418418
"Success if reference to CA cert provided via config map": {
419419
caConfigMap: nil,
420-
caCertificateSecret: &mdbv1.LocalObjectReference{
420+
caCertificateSecret: &corev1.LocalObjectReference{
421421
Name: "caConfigMap"},
422422
},
423423
"Succes if reference to CA cert provided both via secret and configMap": {
424-
caConfigMap: &mdbv1.LocalObjectReference{
424+
caConfigMap: &corev1.LocalObjectReference{
425425
Name: "certificateKeySecret"},
426-
caCertificateSecret: &mdbv1.LocalObjectReference{
426+
caCertificateSecret: &corev1.LocalObjectReference{
427427
Name: "caConfigMap"},
428428
},
429429
"Failure if reference to CA cert is missing": {

controllers/replicaset_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ func newScramReplicaSet(users ...mdbv1.MongoDBUser) mdbv1.MongoDBCommunity {
8787
}
8888

8989
func newTestReplicaSetWithTLS() mdbv1.MongoDBCommunity {
90-
return newTestReplicaSetWithTLSCaCertificateReferences(&mdbv1.LocalObjectReference{
90+
return newTestReplicaSetWithTLSCaCertificateReferences(&corev1.LocalObjectReference{
9191
Name: "caConfigMap",
9292
},
93-
&mdbv1.LocalObjectReference{
93+
&corev1.LocalObjectReference{
9494
Name: "certificateKeySecret",
9595
})
9696
}
9797

98-
func newTestReplicaSetWithTLSCaCertificateReferences(caConfigMap, caCertificateSecret *mdbv1.LocalObjectReference) mdbv1.MongoDBCommunity {
98+
func newTestReplicaSetWithTLSCaCertificateReferences(caConfigMap, caCertificateSecret *corev1.LocalObjectReference) mdbv1.MongoDBCommunity {
9999
return mdbv1.MongoDBCommunity{
100100
ObjectMeta: metav1.ObjectMeta{
101101
Name: "my-rs",
@@ -113,7 +113,7 @@ func newTestReplicaSetWithTLSCaCertificateReferences(caConfigMap, caCertificateS
113113
Enabled: true,
114114
CaConfigMap: caConfigMap,
115115
CaCertificateSecret: caCertificateSecret,
116-
CertificateKeySecret: mdbv1.LocalObjectReference{
116+
CertificateKeySecret: corev1.LocalObjectReference{
117117
Name: "certificateKeySecret",
118118
},
119119
},

test/e2e/e2eutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ func NewTestTLSConfig(optional bool) mdbv1.TLS {
150150
return mdbv1.TLS{
151151
Enabled: true,
152152
Optional: optional,
153-
CertificateKeySecret: mdbv1.LocalObjectReference{
153+
CertificateKeySecret: corev1.LocalObjectReference{
154154
Name: "tls-certificate",
155155
},
156-
CaCertificateSecret: &mdbv1.LocalObjectReference{
156+
CaCertificateSecret: &corev1.LocalObjectReference{
157157
Name: "tls-ca-key-pair",
158158
},
159159
}

0 commit comments

Comments
 (0)