Skip to content

Commit 5d44ddc

Browse files
authored
CLOUDP-323995 CLOUDP-321068 Ingress and Egress TLS in mongot (#278)
# Summary Expose new TLS capabilities in mongot. ## Proof of Work New [passing](https://spruce.mongodb.com/task/mongodb_kubernetes_e2e_mdb_community_e2e_search_community_tls_patch_39025950721c5e2a2b7e69665729018adceb7ce7_687e2c0229d5cb0007cf2080_25_07_21_12_01_09/tests?execution=0&sorts=STATUS%3AASC) test. ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you checked for release_note changes?
1 parent 9ed720d commit 5d44ddc

File tree

16 files changed

+635
-47
lines changed

16 files changed

+635
-47
lines changed

.evergreen-tasks.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,3 +1285,8 @@ tasks:
12851285
tags: ["patch-run"]
12861286
commands:
12871287
- func: "e2e_test"
1288+
1289+
- name: e2e_search_community_tls
1290+
tags: ["patch-run"]
1291+
commands:
1292+
- func: "e2e_test"

.evergreen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ task_groups:
686686
tasks:
687687
- e2e_community_replicaset_scale
688688
- e2e_search_community_basic
689+
- e2e_search_community_tls
689690

690691
# This is the task group that contains all the tests run in the e2e_mdb_kind_ubuntu_cloudqa build variant
691692
- name: e2e_mdb_kind_cloudqa_task_group

api/v1/search/mongodbsearch_types.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type MongoDBSearchSpec struct {
3636
Persistence *common.Persistence `json:"persistence,omitempty"`
3737
// +optional
3838
ResourceRequirements *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`
39+
// +optional
40+
Security Security `json:"security"`
3941
}
4042

4143
type MongoDBSource struct {
@@ -47,6 +49,22 @@ type MongoDBSource struct {
4749
Username *string `json:"username,omitempty"`
4850
}
4951

52+
type Security struct {
53+
// +optional
54+
TLS TLS `json:"tls"`
55+
}
56+
57+
type TLS struct {
58+
Enabled bool `json:"enabled"`
59+
// CertificateKeySecret is a reference to a Secret containing a private key and certificate to use for TLS.
60+
// The key and cert are expected to be PEM encoded and available at "tls.key" and "tls.crt".
61+
// This is the same format used for the standard "kubernetes.io/tls" Secret type, but no specific type is required.
62+
// Alternatively, an entry tls.pem, containing the concatenation of cert and key, can be provided.
63+
// 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
64+
// +optional
65+
CertificateKeySecret corev1.LocalObjectReference `json:"certificateKeySecretRef"`
66+
}
67+
5068
type MongoDBSearchStatus struct {
5169
status.Common `json:",inline"`
5270
Version string `json:"version,omitempty"`
@@ -160,3 +178,14 @@ func (s *MongoDBSearch) GetMongotPort() int32 {
160178
func (s *MongoDBSearch) GetMongotMetricsPort() int32 {
161179
return MongotDefaultMetricsPort
162180
}
181+
182+
// TLSSecretNamespacedName will get the namespaced name of the Secret containing the server certificate and key
183+
func (s *MongoDBSearch) TLSSecretNamespacedName() types.NamespacedName {
184+
return types.NamespacedName{Name: s.Spec.Security.TLS.CertificateKeySecret.Name, Namespace: s.Namespace}
185+
}
186+
187+
// TLSOperatorSecretNamespacedName will get the namespaced name of the Secret created by the operator
188+
// containing the combined certificate and key.
189+
func (s *MongoDBSearch) TLSOperatorSecretNamespacedName() types.NamespacedName {
190+
return types.NamespacedName{Name: s.Name + "-search-certificate-key", Namespace: s.Namespace}
191+
}

api/v1/search/zz_generated.deepcopy.go

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

config/crd/bases/mongodb.com_mongodbsearch.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,37 @@ spec:
149149
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
150150
type: object
151151
type: object
152+
security:
153+
properties:
154+
tls:
155+
properties:
156+
certificateKeySecretRef:
157+
description: |-
158+
CertificateKeySecret is a reference to a Secret containing a private key and certificate to use for TLS.
159+
The key and cert are expected to be PEM encoded and available at "tls.key" and "tls.crt".
160+
This is the same format used for the standard "kubernetes.io/tls" Secret type, but no specific type is required.
161+
Alternatively, an entry tls.pem, containing the concatenation of cert and key, can be provided.
162+
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
163+
properties:
164+
name:
165+
default: ""
166+
description: |-
167+
Name of the referent.
168+
This field is effectively required, but due to backwards compatibility is
169+
allowed to be empty. Instances of this type with an empty value here are
170+
almost certainly wrong.
171+
TODO: Add other useful fields. apiVersion, kind, uid?
172+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
173+
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
174+
type: string
175+
type: object
176+
x-kubernetes-map-type: atomic
177+
enabled:
178+
type: boolean
179+
required:
180+
- enabled
181+
type: object
182+
type: object
152183
source:
153184
properties:
154185
mongodbResourceRef:

controllers/operator/mongodbsearch_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1414

1515
appsv1 "k8s.io/api/apps/v1"
16+
corev1 "k8s.io/api/core/v1"
1617
ctrl "sigs.k8s.io/controller-runtime"
1718

1819
searchv1 "github.com/mongodb/mongodb-kubernetes/api/v1/search"
@@ -67,7 +68,7 @@ func getSourceMongoDBForSearch(ctx context.Context, kubeClient client.Client, se
6768
mdbcName := types.NamespacedName{Namespace: search.GetNamespace(), Name: sourceMongoDBResourceRef.Name}
6869
mdbc := &mdbcv1.MongoDBCommunity{}
6970
if err := kubeClient.Get(ctx, mdbcName, mdbc); err != nil {
70-
return nil, xerrors.Errorf("error getting MongoDBCommunity %s", mdbcName)
71+
return nil, xerrors.Errorf("error getting MongoDBCommunity %s: %w", mdbcName, err)
7172
}
7273
return search_controller.NewSearchSourceDBResourceFromMongoDBCommunity(mdbc), nil
7374
}
@@ -89,5 +90,6 @@ func AddMongoDBSearchController(ctx context.Context, mgr manager.Manager, operat
8990
For(&searchv1.MongoDBSearch{}).
9091
Watches(&mdbcv1.MongoDBCommunity{}, r.mdbcWatcher).
9192
Owns(&appsv1.StatefulSet{}).
93+
Owns(&corev1.Secret{}).
9294
Complete(r)
9395
}

0 commit comments

Comments
 (0)