Skip to content

Commit 9b7af2c

Browse files
committed
envoy wip
1 parent 94b2906 commit 9b7af2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3826
-128
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,7 @@ logs
9595

9696
# locally packaged chart
9797
mongodb-kubernetes-*.tgz
98+
deploy/envoy/captures
9899

99100
scripts/code_snippets/tests/outputs/*
101+
deploy/envoy/tmp-envoy-certs

api/v1/search/mongodbsearch_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,14 @@ func (s *MongoDBSearch) NamespacedName() types.NamespacedName {
262262
return types.NamespacedName{Name: s.Name, Namespace: s.Namespace}
263263
}
264264

265-
func (s *MongoDBSearch) SearchServiceNamespacedName() types.NamespacedName {
265+
func (s *MongoDBSearch) SearchHeadlessServiceNamespacedName() types.NamespacedName {
266266
return types.NamespacedName{Name: s.Name + "-search-svc", Namespace: s.Namespace}
267267
}
268268

269+
func (s *MongoDBSearch) SearchProxyServiceNamespacedName() types.NamespacedName {
270+
return types.NamespacedName{Name: s.Name + "-proxy-svc", Namespace: s.Namespace}
271+
}
272+
269273
func (s *MongoDBSearch) MongotConfigConfigMapNamespacedName() types.NamespacedName {
270274
return types.NamespacedName{Name: s.Name + "-search-config", Namespace: s.Namespace}
271275
}

config/crd/bases/mongodb.com_mongodbsearch.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,24 @@ spec:
116116
minLength: 1
117117
type: string
118118
required:
119-
- endpoint
120-
- shardName
119+
- endpoint
120+
- shardName
121121
type: object
122122
minItems: 1
123123
type: array
124124
required:
125-
- endpoints
125+
- endpoints
126126
type: object
127127
type: object
128128
mode:
129129
description: 'Mode specifies the load balancer mode: Envoy (operator-managed)
130130
or External (BYO L7 LB)'
131131
enum:
132-
- Envoy
133-
- External
132+
- Envoy
133+
- External
134134
type: string
135135
required:
136-
- mode
136+
- mode
137137
type: object
138138
logLevel:
139139
description: Configure verbosity of mongot logs. Defaults to INFO

controllers/operator/mongodbsearch_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TestMongoDBSearchReconcile_Success(t *testing.T) {
208208
checkSearchReconcileSuccessful(ctx, t, reconciler, c, search)
209209

210210
svc := &corev1.Service{}
211-
err := c.Get(ctx, search.SearchServiceNamespacedName(), svc)
211+
err := c.Get(ctx, search.SearchHeadlessServiceNamespacedName(), svc)
212212
assert.NoError(t, err)
213213
servicePortNames := []string{}
214214
for _, port := range svc.Spec.Ports {

controllers/searchcontroller/mongodbsearch_reconcile_helper.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (r *MongoDBSearchReconcileHelper) createOrUpdateStatefulSet(ctx context.Con
324324
}
325325

326326
func (r *MongoDBSearchReconcileHelper) ensureSearchService(ctx context.Context, search *searchv1.MongoDBSearch) error {
327-
svcName := search.SearchServiceNamespacedName()
327+
svcName := search.SearchHeadlessServiceNamespacedName()
328328
svc := &corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: svcName.Name, Namespace: svcName.Namespace}}
329329
op, err := controllerutil.CreateOrUpdate(ctx, r.client, svc, func() error {
330330
resourceVersion := svc.ResourceVersion
@@ -740,7 +740,7 @@ func hashBytes(bytes []byte) string {
740740

741741
func buildSearchHeadlessService(search *searchv1.MongoDBSearch) corev1.Service {
742742
labels := map[string]string{}
743-
name := search.SearchServiceNamespacedName().Name
743+
name := search.SearchHeadlessServiceNamespacedName().Name
744744

745745
labels["app"] = name
746746

@@ -911,8 +911,12 @@ func mongotHostAndPort(search *searchv1.MongoDBSearch, clusterDomain string) str
911911
}
912912

913913
// Otherwise, use the internal service endpoint
914-
svcName := search.SearchServiceNamespacedName()
914+
svcName := search.SearchHeadlessServiceNamespacedName()
915915
port := search.GetEffectiveMongotPort()
916+
if useProxy, ok := search.Annotations["use-proxy"]; ok && useProxy == "true" {
917+
port += 1
918+
svcName = search.SearchProxyServiceNamespacedName()
919+
}
916920
return fmt.Sprintf("%s.%s.svc.%s:%d", svcName.Name, svcName.Namespace, clusterDomain, port)
917921
}
918922

controllers/searchcontroller/mongodbsearch_reconcile_helper_test.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,6 @@ func init() {
3030
zap.ReplaceGlobals(logger)
3131
}
3232

33-
func newTestMongoDBSearch(name, namespace string, modifications ...func(*searchv1.MongoDBSearch)) *searchv1.MongoDBSearch {
34-
mdbSearch := &searchv1.MongoDBSearch{
35-
ObjectMeta: metav1.ObjectMeta{
36-
Name: name,
37-
Namespace: namespace,
38-
},
39-
Spec: searchv1.MongoDBSearchSpec{
40-
Source: &searchv1.MongoDBSource{
41-
MongoDBResourceRef: &userv1.MongoDBResourceRef{
42-
Name: "test-mongodb",
43-
},
44-
},
45-
},
46-
}
47-
48-
for _, modify := range modifications {
49-
modify(mdbSearch)
50-
}
51-
52-
return mdbSearch
53-
}
54-
5533
func newTestMongoDBCommunity(name, namespace string, modifications ...func(*mdbcv1.MongoDBCommunity)) *mdbcv1.MongoDBCommunity {
5634
mdbc := &mdbcv1.MongoDBCommunity{
5735
ObjectMeta: metav1.ObjectMeta{
@@ -102,6 +80,33 @@ func reconcileMongoDBSearch(ctx context.Context, fakeClient kubernetesClient.Cli
10280
return helper.Reconcile(ctx, zap.S())
10381
}
10482

83+
func init() {
84+
logger, _ := zap.NewDevelopment()
85+
zap.ReplaceGlobals(logger)
86+
}
87+
88+
func newTestMongoDBSearch(name, namespace string, modifications ...func(*searchv1.MongoDBSearch)) *searchv1.MongoDBSearch {
89+
mdbSearch := &searchv1.MongoDBSearch{
90+
ObjectMeta: metav1.ObjectMeta{
91+
Name: name,
92+
Namespace: namespace,
93+
},
94+
Spec: searchv1.MongoDBSearchSpec{
95+
Source: &searchv1.MongoDBSource{
96+
MongoDBResourceRef: &userv1.MongoDBResourceRef{
97+
Name: "test-mongodb",
98+
},
99+
},
100+
},
101+
}
102+
103+
for _, modify := range modifications {
104+
modify(mdbSearch)
105+
}
106+
107+
return mdbSearch
108+
}
109+
105110
func TestMongoDBSearchReconcileHelper_ValidateSingleMongoDBSearchForSearchSource(t *testing.T) {
106111
mdbSearchSpec := searchv1.MongoDBSearchSpec{
107112
Source: &searchv1.MongoDBSource{
@@ -240,7 +245,7 @@ func TestGetMongodConfigParameters_TransportAndPorts(t *testing.T) {
240245

241246
func assertServiceBasicProperties(t *testing.T, svc corev1.Service, mdbSearch *searchv1.MongoDBSearch) {
242247
t.Helper()
243-
svcName := mdbSearch.SearchServiceNamespacedName()
248+
svcName := mdbSearch.SearchHeadlessServiceNamespacedName()
244249

245250
assert.Equal(t, svcName.Name, svc.Name)
246251
assert.Equal(t, svcName.Namespace, svc.Namespace)
@@ -309,7 +314,7 @@ func TestMongoDBSearchReconcileHelper_ServiceCreation(t *testing.T) {
309314

310315
reconcileMongoDBSearch(t.Context(), fakeClient, mdbSearch, mdbc, newTestOperatorSearchConfig())
311316

312-
svcName := mdbSearch.SearchServiceNamespacedName()
317+
svcName := mdbSearch.SearchHeadlessServiceNamespacedName()
313318
svc, err := fakeClient.GetService(t.Context(), svcName)
314319
require.NoError(t, err)
315320
require.NotNil(t, svc)

controllers/searchcontroller/search_construction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type TLSSourceConfig struct {
7474
// ReplicaSetOptions returns a set of options which will configure a ReplicaSet StatefulSet
7575
func CreateSearchStatefulSetFunc(mdbSearch *searchv1.MongoDBSearch, sourceDBResource SearchSourceDBResource, searchImage string) statefulset.Modification {
7676
labels := map[string]string{
77-
"app": mdbSearch.SearchServiceNamespacedName().Name,
77+
"app": mdbSearch.SearchHeadlessServiceNamespacedName().Name,
7878
}
7979

8080
tmpVolume := statefulset.CreateVolumeFromEmptyDir("tmp")
@@ -119,7 +119,7 @@ func CreateSearchStatefulSetFunc(mdbSearch *searchv1.MongoDBSearch, sourceDBReso
119119
stsModifications := []statefulset.Modification{
120120
statefulset.WithName(mdbSearch.StatefulSetNamespacedName().Name),
121121
statefulset.WithNamespace(mdbSearch.StatefulSetNamespacedName().Namespace),
122-
statefulset.WithServiceName(mdbSearch.SearchServiceNamespacedName().Name),
122+
statefulset.WithServiceName(mdbSearch.SearchHeadlessServiceNamespacedName().Name),
123123
statefulset.WithLabels(labels),
124124
statefulset.WithOwnerReference(mdbSearch.GetOwnerReferences()),
125125
statefulset.WithMatchLabels(labels),

0 commit comments

Comments
 (0)