Skip to content

Commit 1ca3501

Browse files
committed
Search: e2e
1 parent 409ec56 commit 1ca3501

21 files changed

Lines changed: 2696 additions & 138 deletions

.evergreen-tasks.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,3 +1359,13 @@ tasks:
13591359
tags: [ "patch-run" ]
13601360
commands:
13611361
- func: "e2e_test"
1362+
1363+
- name: e2e_search_sharded_enterprise_external_lb
1364+
tags: [ "patch-run" ]
1365+
commands:
1366+
- func: "e2e_test"
1367+
1368+
- name: e2e_search_sharded_enterprise_external_mongod
1369+
tags: [ "patch-run" ]
1370+
commands:
1371+
- func: "e2e_test"

.evergreen.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,8 @@ task_groups:
811811
- e2e_search_enterprise_basic
812812
- e2e_search_enterprise_tls
813813
- e2e_search_enterprise_x509_cluster_auth
814+
- e2e_search_sharded_enterprise_external_lb
815+
- e2e_search_sharded_enterprise_external_mongod
814816
<<: *teardown_group
815817

816818
# this task group contains just a one task, which is smoke testing whether the operator
@@ -1318,7 +1320,7 @@ buildvariants:
13181320
display_name: e2e_mdb_kind_ubi_cloudqa
13191321
tags: [ "pr_patch", "staging", "e2e_test_suite", "cloudqa", "cloudqa_non_static" ]
13201322
run_on:
1321-
- ubuntu2404-medium
1323+
- ubuntu2404-large
13221324
<<: *base_no_om_image_dependency
13231325
tasks:
13241326
- name: e2e_mdb_kind_cloudqa_task_group
@@ -1336,7 +1338,7 @@ buildvariants:
13361338
display_name: e2e_static_mdb_kind_ubi_cloudqa
13371339
tags: [ "pr_patch", "staging", "e2e_test_suite", "cloudqa", "static" ]
13381340
run_on:
1339-
- ubuntu2404-medium
1341+
- ubuntu2404-large
13401342
<<: *base_no_om_image_dependency
13411343
tasks:
13421344
- name: e2e_mdb_kind_cloudqa_task_group

docker/mongodb-kubernetes-tests/kubetester/certs.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def create_sharded_cluster_certs(
487487
shard_distribution: Optional[List[int]] = None,
488488
mongos_distribution: Optional[List[int]] = None,
489489
config_srv_distribution: Optional[List[int]] = None,
490+
mongos_service_dns_names: Optional[List[str]] = None,
490491
):
491492
cert_generation_func = create_mongodb_tls_certs
492493
if x509_certs:
@@ -573,9 +574,8 @@ def create_sharded_cluster_certs(
573574
secret_backend=secret_backend,
574575
)
575576

576-
additional_domains_for_mongos = None
577+
additional_domains_for_mongos = []
577578
if additional_domains is not None:
578-
additional_domains_for_mongos = []
579579
for domain in additional_domains:
580580
if mongos_distribution is None:
581581
for pod_idx in range(mongos):
@@ -585,6 +585,10 @@ def create_sharded_cluster_certs(
585585
for pod_idx in range(pod_count or 0):
586586
additional_domains_for_mongos.append(f"{resource_name}-mongos-{cluster_idx}-{pod_idx}.{domain}")
587587

588+
# Add service DNS names directly (e.g., for mongot to connect to mongos service)
589+
if mongos_service_dns_names is not None:
590+
additional_domains_for_mongos.extend(mongos_service_dns_names)
591+
588592
secret_name = f"{resource_name}-mongos-cert"
589593
if secret_prefix is not None:
590594
secret_name = secret_prefix + secret_name
@@ -596,7 +600,7 @@ def create_sharded_cluster_certs(
596600
service_name=resource_name + "-svc",
597601
replicas=mongos,
598602
replicas_cluster_distribution=mongos_distribution,
599-
additional_domains=additional_domains_for_mongos,
603+
additional_domains=additional_domains_for_mongos if additional_domains_for_mongos else None,
600604
secret_backend=secret_backend,
601605
)
602606

docker/mongodb-kubernetes-tests/kubetester/tests/test___init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from kubeobject import CustomObject
66

77

8-
class TestCreateOrUpdate(ctx, unittest.TestCase):
8+
class TestCreateOrUpdate(unittest.TestCase):
99
def test_create_or_update_is_not_bound(self):
1010
api_client = MagicMock()
1111
custom_object = CustomObject(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import tarfile
2+
import tempfile
3+
4+
from kubernetes import client, config
5+
from kubernetes.stream import stream
6+
from tests import test_logger
7+
8+
logger = test_logger.get_test_logger(__name__)
9+
10+
TOOLS_POD_NAME = "mongodb-tools-pod"
11+
TOOLS_POD_IMAGE = "mongodb/mongodb-community-server:8.0-ubi9"
12+
13+
14+
class ToolsPod:
15+
"""A pod running MongoDB tools for executing commands like mongorestore inside the cluster."""
16+
17+
def __init__(self, namespace: str):
18+
self.namespace = namespace
19+
self.pod_name = TOOLS_POD_NAME
20+
config.load_incluster_config()
21+
self.core_v1 = client.CoreV1Api()
22+
23+
def run_command(self, cmd: list[str]):
24+
"""Execute a command in the tools pod and return the output."""
25+
logger.debug(f"Running command in {self.pod_name}: {' '.join(cmd)}")
26+
resp = stream(
27+
self.core_v1.connect_get_namespaced_pod_exec,
28+
self.pod_name,
29+
self.namespace,
30+
command=cmd,
31+
stderr=True,
32+
stdin=False,
33+
stdout=True,
34+
tty=False,
35+
)
36+
logger.debug(f"Command output: {resp}")
37+
return resp
38+
39+
def copy_file_to_pod(self, src_path: str, dest_path: str):
40+
"""Copy a file from the local filesystem to the tools pod."""
41+
logger.debug(f"Copying {src_path} to {self.pod_name}:{dest_path}")
42+
43+
# Create a tar archive containing the file
44+
with tempfile.NamedTemporaryFile(suffix=".tar") as tar_file:
45+
with tarfile.open(tar_file.name, "w") as tar:
46+
tar.add(src_path, arcname=dest_path.split("/")[-1])
47+
48+
tar_file.seek(0)
49+
tar_data = tar_file.read()
50+
51+
# Extract the tar archive in the pod
52+
exec_command = ["tar", "xf", "-", "-C", "/".join(dest_path.split("/")[:-1]) or "/"]
53+
resp = stream(
54+
self.core_v1.connect_get_namespaced_pod_exec,
55+
self.pod_name,
56+
self.namespace,
57+
command=exec_command,
58+
stderr=True,
59+
stdin=True,
60+
stdout=True,
61+
tty=False,
62+
_preload_content=False,
63+
)
64+
65+
# Send the tar data
66+
resp.write_stdin(tar_data)
67+
resp.close()
68+
logger.debug(f"File copied to {self.pod_name}:{dest_path}")
69+
70+
def run_pod_and_wait(self):
71+
"""Create the tools pod and wait for it to be ready."""
72+
pod_body = client.V1Pod(
73+
api_version="v1",
74+
kind="Pod",
75+
metadata=client.V1ObjectMeta(name=self.pod_name, labels={"app": "mongodb-tools"}),
76+
spec=client.V1PodSpec(
77+
containers=[
78+
client.V1Container(
79+
name="mongodb-tools",
80+
image=TOOLS_POD_IMAGE,
81+
command=["/bin/bash", "-c"],
82+
args=["sleep infinity"],
83+
)
84+
],
85+
restart_policy="Never",
86+
),
87+
)
88+
89+
try:
90+
self.core_v1.create_namespaced_pod(namespace=self.namespace, body=pod_body)
91+
logger.info(f"Created {self.pod_name} in namespace {self.namespace}")
92+
except client.exceptions.ApiException as e:
93+
if e.status == 409:
94+
logger.info(f"Pod {self.pod_name} already exists")
95+
else:
96+
raise
97+
98+
# Wait for pod to be ready
99+
from kubernetes.watch import Watch
100+
101+
w = Watch()
102+
for event in w.stream(
103+
self.core_v1.list_namespaced_pod,
104+
namespace=self.namespace,
105+
label_selector="app=mongodb-tools",
106+
timeout_seconds=120,
107+
):
108+
pod = event["object"]
109+
if pod.status.phase == "Running":
110+
# Check if container is ready
111+
if pod.status.container_statuses:
112+
for container_status in pod.status.container_statuses:
113+
if container_status.ready:
114+
logger.info(f"{self.pod_name} is ready")
115+
w.stop()
116+
return
117+
raise TimeoutError(f"Timed out waiting for {self.pod_name} to be ready")
118+
119+
120+
def get_tools_pod(namespace: str) -> ToolsPod:
121+
"""Create and return a ready tools pod in the given namespace."""
122+
tools_pod = ToolsPod(namespace)
123+
tools_pod.run_pod_and_wait()
124+
return tools_pod

docker/mongodb-kubernetes-tests/tests/common/search/movies_search_helper.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import logging
2-
31
import pymongo.errors
42
from kubetester import kubetester
53
from tests import test_logger
4+
from tests.common.mongodb_tools_pod.mongodb_tools_pod import ToolsPod
65
from tests.common.search.search_tester import SearchTester
76

87
logger = test_logger.get_test_logger(__name__)
@@ -13,15 +12,19 @@ class SampleMoviesSearchHelper:
1312
db_name: str
1413
col_name: str
1514
archive_url: str
15+
tools_pod: ToolsPod
1616

17-
def __init__(self, search_tester: SearchTester):
17+
def __init__(self, search_tester: SearchTester, tools_pod: ToolsPod):
1818
self.search_tester = search_tester
19+
self.tools_pod = tools_pod
1920
self.db_name = "sample_mflix"
2021
self.col_name = "movies"
2122

2223
def restore_sample_database(self):
2324
self.search_tester.mongorestore_from_url(
24-
"https://atlas-education.s3.amazonaws.com/sample_mflix.archive", f"{self.db_name}.*"
25+
"https://atlas-education.s3.amazonaws.com/sample_mflix.archive",
26+
f"{self.db_name}.*",
27+
self.tools_pod,
2528
)
2629

2730
def create_search_index(self):

0 commit comments

Comments
 (0)