Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .evergreen-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1285,3 +1285,8 @@ tasks:
tags: ["patch-run"]
commands:
- func: "e2e_test"

- name: e2e_search_community_tls
tags: ["patch-run"]
commands:
- func: "e2e_test"
1 change: 1 addition & 0 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ task_groups:
tasks:
- e2e_community_replicaset_scale
- e2e_search_community_basic
- e2e_search_community_tls

# This is the task group that contains all the tests run in the e2e_mdb_kind_ubuntu_cloudqa build variant
- name: e2e_mdb_kind_cloudqa_task_group
Expand Down
29 changes: 29 additions & 0 deletions api/v1/search/mongodbsearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type MongoDBSearchSpec struct {
Persistence *common.Persistence `json:"persistence,omitempty"`
// +optional
ResourceRequirements *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`
// +optional
Security Security `json:"security"`
}

type MongoDBSource struct {
Expand All @@ -47,6 +49,22 @@ type MongoDBSource struct {
Username *string `json:"username,omitempty"`
}

type Security struct {
// +optional
TLS TLS `json:"tls"`
}

type TLS struct {
Enabled bool `json:"enabled"`
// CertificateKeySecret is a reference to a Secret containing a private key and certificate to use for TLS.
// The key and cert are expected to be PEM encoded and available at "tls.key" and "tls.crt".
// This is the same format used for the standard "kubernetes.io/tls" Secret type, but no specific type is required.
// Alternatively, an entry tls.pem, containing the concatenation of cert and key, can be provided.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we normally support tls.pem AND tls.crt in secrets? I thought we're only supporting standard tls secret types so tls.key and tls.crt only. We might have some leftovers in the codebase handling tls.pem-type secrets but we shouldn't support them anymore for new things. Could you verify it's the case here?

Copy link
Contributor Author

@fealebenpae fealebenpae Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’re using the community operator’s tls secret handling behind the scenes which does support the concatenated tls.pem field. I copied this comment directly from the Community CRD. I am happy to drop the tls.pem thing altogether, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop it and keep it simple, exactly the same as tls-type secrets are defined 👍

// 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
// +optional
CertificateKeySecret corev1.LocalObjectReference `json:"certificateKeySecretRef"`
}

type MongoDBSearchStatus struct {
status.Common `json:",inline"`
Version string `json:"version,omitempty"`
Expand Down Expand Up @@ -160,3 +178,14 @@ func (s *MongoDBSearch) GetMongotPort() int32 {
func (s *MongoDBSearch) GetMongotMetricsPort() int32 {
return MongotDefaultMetricsPort
}

// TLSSecretNamespacedName will get the namespaced name of the Secret containing the server certificate and key
func (s *MongoDBSearch) TLSSecretNamespacedName() types.NamespacedName {
return types.NamespacedName{Name: s.Spec.Security.TLS.CertificateKeySecret.Name, Namespace: s.Namespace}
}

// TLSOperatorSecretNamespacedName will get the namespaced name of the Secret created by the operator
// containing the combined certificate and key.
func (s *MongoDBSearch) TLSOperatorSecretNamespacedName() types.NamespacedName {
return types.NamespacedName{Name: s.Name + "-search-certificate-key", Namespace: s.Namespace}
}
43 changes: 43 additions & 0 deletions api/v1/search/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions config/crd/bases/mongodb.com_mongodbsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,37 @@ spec:
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
security:
properties:
tls:
properties:
certificateKeySecretRef:
description: |-
CertificateKeySecret is a reference to a Secret containing a private key and certificate to use for TLS.
The key and cert are expected to be PEM encoded and available at "tls.key" and "tls.crt".
This is the same format used for the standard "kubernetes.io/tls" Secret type, but no specific type is required.
Alternatively, an entry tls.pem, containing the concatenation of cert and key, can be provided.
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
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
enabled:
type: boolean
required:
- enabled
type: object
type: object
source:
properties:
mongodbResourceRef:
Expand Down
4 changes: 3 additions & 1 deletion controllers/operator/mongodbsearch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"

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