From 6bac430bf502675fa59d813bd842f25cea698526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sierant?= Date: Wed, 30 Apr 2025 13:02:11 +0200 Subject: [PATCH 1/8] Install CRDs in operator upgrade tests --- .../kubetester/helm.py | 41 ++++++++++--- .../kubetester/operator.py | 5 +- .../tests/conftest.py | 58 ++++++++++--------- ...appdb_tls_operator_upgrade_v1_32_to_mck.py | 8 ++- .../upgrades/operator_upgrade_ops_manager.py | 10 ++-- .../upgrades/operator_upgrade_replica_set.py | 15 ++--- ...d_cluster_operator_upgrade_v1_27_to_mck.py | 8 ++- 7 files changed, 94 insertions(+), 51 deletions(-) diff --git a/docker/mongodb-kubernetes-tests/kubetester/helm.py b/docker/mongodb-kubernetes-tests/kubetester/helm.py index da0a19f39..4e1e3f3e6 100644 --- a/docker/mongodb-kubernetes-tests/kubetester/helm.py +++ b/docker/mongodb-kubernetes-tests/kubetester/helm.py @@ -1,3 +1,4 @@ +import glob import logging import os import re @@ -120,8 +121,16 @@ def helm_repo_add(repo_name: str, url: str): def process_run_and_check(args, **kwargs): try: + logger.debug(f"subprocess.run: {args}") completed_process = subprocess.run(args, **kwargs) - completed_process.check_returncode() + # always print process output + if completed_process.stdout is not None: + stdout = completed_process.stdout.decode("utf-8") + logger.debug(f"stdout: {stdout}") + if completed_process.stderr is not None: + stderr = completed_process.stderr.decode("utf-8") + logger.debug(f"stderr: {stderr}") + completed_process.check_returncode() except subprocess.CalledProcessError as exc: if exc.stdout is not None: stdout = exc.stdout.decode("utf-8") @@ -141,10 +150,17 @@ def helm_upgrade( helm_options: Optional[List[str]] = None, helm_override_path: Optional[bool] = False, custom_operator_version: Optional[str] = None, + apply_crds_first: bool = False, ): if not helm_chart_path: logger.warning("Helm chart path is empty, defaulting to 'helm_chart'") helm_chart_path = "helm_chart" + + chart_dir = helm_chart_path if helm_override_path else _helm_chart_dir(helm_chart_path) + + if apply_crds_first: + apply_crds_from_chart(chart_dir) + command_args = _create_helm_args(helm_args, helm_options) args = [ "helm", @@ -154,19 +170,30 @@ def helm_upgrade( *command_args, name, ] + if custom_operator_version: args.append(f"--version={custom_operator_version}") - if helm_override_path: - args.append(helm_chart_path) - else: - args.append(_helm_chart_dir(helm_chart_path)) + + args.append(chart_dir) command = " ".join(args) - logger.debug("Running helm upgrade command:") - logger.debug(command) process_run_and_check(command, check=True, capture_output=True, shell=True) +def apply_crds_from_chart(chart_dir: str): + crd_files = glob.glob(os.path.join(chart_dir, "crds", "*.yaml")) + + if not crd_files: + raise Exception(f"No CRD files found in chart directory: {chart_dir}") + + logger.info(f"Found {len(crd_files)} CRD files to apply:") + + for crd_file in crd_files: + logger.info(f"Applying CRD from file: {crd_file}") + args = ["kubectl", "apply", "-f", crd_file] + process_run_and_check(args, check=True, capture_output=True, shell=True) + + def helm_uninstall(name): args = ("helm", "uninstall", name) logger.info(args) diff --git a/docker/mongodb-kubernetes-tests/kubetester/operator.py b/docker/mongodb-kubernetes-tests/kubetester/operator.py index 08455c1d5..fa2b90344 100644 --- a/docker/mongodb-kubernetes-tests/kubetester/operator.py +++ b/docker/mongodb-kubernetes-tests/kubetester/operator.py @@ -95,7 +95,9 @@ def install(self, custom_operator_version: Optional[str] = None) -> Operator: return self - def upgrade(self, multi_cluster: bool = False, custom_operator_version: Optional[str] = None) -> Operator: + def upgrade( + self, multi_cluster: bool = False, custom_operator_version: Optional[str] = None, apply_crds_first: bool = False + ) -> Operator: """Upgrades the Operator in Kubernetes cluster using 'helm upgrade', waits until it's running""" helm_upgrade( self.name, @@ -104,6 +106,7 @@ def upgrade(self, multi_cluster: bool = False, custom_operator_version: Optional helm_chart_path=self.helm_chart_path, helm_options=self.helm_options, custom_operator_version=custom_operator_version, + apply_crds_first=apply_crds_first, ) self._wait_for_operator_ready() self._wait_operator_webhook_is_ready(multi_cluster=multi_cluster) diff --git a/docker/mongodb-kubernetes-tests/tests/conftest.py b/docker/mongodb-kubernetes-tests/tests/conftest.py index 9d4364d02..d9a3da265 100644 --- a/docker/mongodb-kubernetes-tests/tests/conftest.py +++ b/docker/mongodb-kubernetes-tests/tests/conftest.py @@ -107,7 +107,7 @@ def get_version_id(): @fixture(scope="module") -def operator_installation_config(namespace: str) -> Dict[str, str]: +def operator_installation_config(namespace: str) -> dict[str, str]: return get_operator_installation_config(namespace) @@ -126,7 +126,7 @@ def get_operator_installation_config(namespace): @fixture(scope="module") -def monitored_appdb_operator_installation_config(operator_installation_config: Dict[str, str]) -> Dict[str, str]: +def monitored_appdb_operator_installation_config(operator_installation_config: dict[str, str]) -> dict[str, str]: """Returns the ConfigMap containing configuration data for the Operator to be created and for the AppDB to be monitored. Created in the single_e2e.sh""" @@ -135,7 +135,7 @@ def monitored_appdb_operator_installation_config(operator_installation_config: D return config -def get_multi_cluster_operator_installation_config(namespace: str) -> Dict[str, str]: +def get_multi_cluster_operator_installation_config(namespace: str) -> dict[str, str]: """Returns the ConfigMap containing configuration data for the Operator to be created. Created in the single_e2e.sh""" config = KubernetesTester.read_configmap( @@ -150,7 +150,7 @@ def get_multi_cluster_operator_installation_config(namespace: str) -> Dict[str, @fixture(scope="module") def multi_cluster_operator_installation_config( central_cluster_client: kubernetes.client.ApiClient, namespace: str -) -> Dict[str, str]: +) -> dict[str, str]: return get_multi_cluster_operator_installation_config(namespace) @@ -159,7 +159,7 @@ def multi_cluster_monitored_appdb_operator_installation_config( central_cluster_client: kubernetes.client.ApiClient, namespace: str, multi_cluster_operator_installation_config: dict[str, str], -) -> Dict[str, str]: +) -> dict[str, str]: multi_cluster_operator_installation_config["customEnvVars"] = f"OPS_MANAGER_MONITOR_APPDB=true" return multi_cluster_operator_installation_config @@ -167,7 +167,7 @@ def multi_cluster_monitored_appdb_operator_installation_config( @fixture(scope="module") def operator_clusterwide( namespace: str, - operator_installation_config: Dict[str, str], + operator_installation_config: dict[str, str], ) -> Operator: return get_operator_clusterwide(namespace, operator_installation_config) @@ -181,7 +181,7 @@ def get_operator_clusterwide(namespace, operator_installation_config): @fixture(scope="module") def operator_vault_secret_backend( namespace: str, - monitored_appdb_operator_installation_config: Dict[str, str], + monitored_appdb_operator_installation_config: dict[str, str], ) -> Operator: helm_args = monitored_appdb_operator_installation_config.copy() helm_args["operator.vaultSecretBackend.enabled"] = "true" @@ -191,7 +191,7 @@ def operator_vault_secret_backend( @fixture(scope="module") def operator_vault_secret_backend_tls( namespace: str, - monitored_appdb_operator_installation_config: Dict[str, str], + monitored_appdb_operator_installation_config: dict[str, str], ) -> Operator: helm_args = monitored_appdb_operator_installation_config.copy() helm_args["operator.vaultSecretBackend.enabled"] = "true" @@ -200,7 +200,7 @@ def operator_vault_secret_backend_tls( @fixture(scope="module") -def operator_installation_config_quick_recovery(operator_installation_config: Dict[str, str]) -> Dict[str, str]: +def operator_installation_config_quick_recovery(operator_installation_config: dict[str, str]) -> dict[str, str]: """ This functions appends automatic recovery settings for CLOUDP-189433. In order to make the test runnable in reasonable time, we override the Recovery back off to 120 seconds. This gives enough time for the initial @@ -480,9 +480,9 @@ def get_custom_om_version(): @fixture(scope="module") def default_operator( namespace: str, - operator_installation_config: Dict[str, str], + operator_installation_config: dict[str, str], central_cluster_name: str, - multi_cluster_operator_installation_config: Dict[str, str], + multi_cluster_operator_installation_config: dict[str, str], central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], member_cluster_names: List[str], @@ -500,8 +500,7 @@ def default_operator( def get_default_operator( - namespace: str, - operator_installation_config: Dict[str, str], + namespace: str, operator_installation_config: dict[str, str], apply_crds_first: bool = False ) -> Operator: """Installs/upgrades a default Operator used by any test not interested in some custom Operator setting. TODO we use the helm template | kubectl apply -f process so far as Helm install/upgrade needs more refactoring in @@ -509,7 +508,7 @@ def get_default_operator( operator = Operator( namespace=namespace, helm_args=operator_installation_config, - ).upgrade() + ).upgrade(apply_crds_first=apply_crds_first) return operator @@ -517,7 +516,7 @@ def get_default_operator( @fixture(scope="module") def operator_with_monitored_appdb( namespace: str, - monitored_appdb_operator_installation_config: Dict[str, str], + monitored_appdb_operator_installation_config: dict[str, str], ) -> Operator: """Installs/upgrades a default Operator used by any test that needs the AppDB monitoring enabled.""" return Operator( @@ -628,7 +627,7 @@ def member_cluster_clients() -> List[MultiClusterClient]: def multi_cluster_operator( namespace: str, central_cluster_name: str, - multi_cluster_operator_installation_config: Dict[str, str], + multi_cluster_operator_installation_config: dict[str, str], central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], member_cluster_names: List[str], @@ -646,10 +645,11 @@ def multi_cluster_operator( def get_multi_cluster_operator( namespace: str, central_cluster_name: str, - multi_cluster_operator_installation_config: Dict[str, str], + multi_cluster_operator_installation_config: dict[str, str], central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], member_cluster_names: List[str], + apply_crds_first: bool = False, ) -> Operator: os.environ["HELM_KUBECONTEXT"] = central_cluster_name @@ -667,6 +667,7 @@ def get_multi_cluster_operator( "operator.createOperatorServiceAccount": "false", }, central_cluster_name, + apply_crds_first=apply_crds_first, ) @@ -674,7 +675,7 @@ def get_multi_cluster_operator( def multi_cluster_operator_with_monitored_appdb( namespace: str, central_cluster_name: str, - multi_cluster_monitored_appdb_operator_installation_config: Dict[str, str], + multi_cluster_monitored_appdb_operator_installation_config: dict[str, str], central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], member_cluster_names: List[str], @@ -703,7 +704,7 @@ def multi_cluster_operator_with_monitored_appdb( def multi_cluster_operator_manual_remediation( namespace: str, central_cluster_name: str, - multi_cluster_operator_installation_config: Dict[str, str], + multi_cluster_operator_installation_config: dict[str, str], central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], member_cluster_names: List[str], @@ -754,7 +755,7 @@ def get_multi_cluster_operator_clustermode(namespace: str) -> Operator: def multi_cluster_operator_clustermode( namespace: str, central_cluster_name: str, - multi_cluster_operator_installation_config: Dict[str, str], + multi_cluster_operator_installation_config: dict[str, str], central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], member_cluster_names: List[str], @@ -767,7 +768,7 @@ def multi_cluster_operator_clustermode( def install_multi_cluster_operator_set_members_fn( namespace: str, central_cluster_name: str, - multi_cluster_operator_installation_config: Dict[str, str], + multi_cluster_operator_installation_config: dict[str, str], central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], ) -> Callable[[List[str]], Operator]: @@ -793,14 +794,15 @@ def _fn(member_cluster_names: List[str]) -> Operator: def _install_multi_cluster_operator( namespace: str, - multi_cluster_operator_installation_config: Dict[str, str], + multi_cluster_operator_installation_config: dict[str, str], central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], - helm_opts: Dict[str, str], + helm_opts: dict[str, str], central_cluster_name: str, operator_name: Optional[str] = MULTI_CLUSTER_OPERATOR_NAME, helm_chart_path: Optional[str] = LOCAL_HELM_CHART_DIR, custom_operator_version: Optional[str] = None, + apply_crds_first: bool = False, ) -> Operator: multi_cluster_operator_installation_config.update(helm_opts) @@ -822,7 +824,7 @@ def _install_multi_cluster_operator( helm_args=multi_cluster_operator_installation_config, api_client=central_cluster_client, helm_chart_path=helm_chart_path, - ).upgrade(multi_cluster=True, custom_operator_version=custom_operator_version) + ).upgrade(multi_cluster=True, custom_operator_version=custom_operator_version, apply_crds_first=apply_crds_first) # If we're running locally, then immediately after installing the deployment, we scale it to zero. # This way operator in POD is not interfering with locally running one. @@ -840,7 +842,7 @@ def _install_multi_cluster_operator( def official_operator( namespace: str, managed_security_context: str, - operator_installation_config: Dict[str, str], + operator_installation_config: dict[str, str], central_cluster_name: str, central_cluster_client: client.ApiClient, member_cluster_clients: List[MultiClusterClient], @@ -919,7 +921,7 @@ def install_legacy_deployment_state_meko( def install_official_operator( namespace: str, managed_security_context: str, - operator_installation_config: Dict[str, str], + operator_installation_config: dict[str, str], central_cluster_name: Optional[str], central_cluster_client: Optional[client.ApiClient], member_cluster_clients: Optional[List[MultiClusterClient]], @@ -1033,7 +1035,7 @@ def log_deployment_and_images(deployments): # Extract container images and deployments names from the nested dict returned by kubetester # Handles any missing key gracefully -def extract_container_images_and_deployments(deployments) -> (Dict[str, str], List[str]): +def extract_container_images_and_deployments(deployments) -> (dict[str, str], List[str]): deployment_images = {} deployment_names = [] deployments = deployments.to_dict() @@ -1318,7 +1320,7 @@ def get_api_servers_from_kubeconfig_secret( return get_api_servers_from_pod_kubeconfig(kubeconfig_secret["kubeconfig"], cluster_clients) -def get_api_servers_from_test_pod_kubeconfig(namespace: str, member_cluster_names: List[str]) -> Dict[str, str]: +def get_api_servers_from_test_pod_kubeconfig(namespace: str, member_cluster_names: List[str]) -> dict[str, str]: test_pod_cluster = get_test_pod_cluster_name() cluster_clients = get_clients_for_clusters(member_cluster_names) diff --git a/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py b/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py index 5d01cb1da..68f588e97 100644 --- a/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py +++ b/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py @@ -11,6 +11,7 @@ LEGACY_OPERATOR_IMAGE_NAME, LEGACY_OPERATOR_NAME, create_appdb_certs, + get_default_operator, install_official_operator, is_multi_cluster, ) @@ -127,8 +128,11 @@ def test_downscale_latest_official_operator(namespace: str): @mark.e2e_appdb_tls_operator_upgrade_v1_32_to_mck -def test_upgrade_operator(default_operator: Operator): - default_operator.assert_is_running() +def test_upgrade_operator(namespace: str, operator_installation_config: dict[str, str]): + operator = get_default_operator( + namespace, operator_installation_config=operator_installation_config, apply_crds_first=True + ) + operator.assert_is_running() @mark.e2e_appdb_tls_operator_upgrade_v1_32_to_mck diff --git a/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_ops_manager.py b/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_ops_manager.py index 0b887299c..532af4a2a 100644 --- a/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_ops_manager.py +++ b/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_ops_manager.py @@ -9,8 +9,7 @@ from kubetester.operator import Operator from kubetester.opsmanager import MongoDBOpsManager from pytest import fixture, mark -from tests.conftest import LEGACY_OPERATOR_NAME -from tests.upgrades import downscale_operator_deployment +from tests.conftest import get_default_operator, operator_installation_config @fixture(scope="module") @@ -144,8 +143,11 @@ def test_mdb_created(some_mdb: MongoDB): @mark.e2e_operator_upgrade_ops_manager -def test_upgrade_operator(default_operator: Operator): - default_operator.assert_is_running() +def test_upgrade_operator(namespace: str, operator_installation_config: dict[str, str]): + operator = get_default_operator( + namespace, operator_installation_config=operator_installation_config, apply_crds_first=True + ) + operator.assert_is_running() @mark.e2e_operator_upgrade_ops_manager diff --git a/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_replica_set.py b/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_replica_set.py index 68a4cd513..13fe618e2 100644 --- a/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_replica_set.py +++ b/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_replica_set.py @@ -7,10 +7,8 @@ from kubetester.mongodb import Phase from kubetester.mongodb_user import MongoDBUser from kubetester.operator import Operator -from pytest import fixture, mark -from tests import test_logger -from tests.conftest import LEGACY_OPERATOR_NAME, log_deployments_info -from tests.upgrades import downscale_operator_deployment +from pytest import fixture +from tests.conftest import get_default_operator RS_NAME = "my-replica-set" USER_PASSWORD = "/qwerty@!#:" @@ -96,9 +94,12 @@ def test_replicaset_user_created(replica_set_user: MongoDBUser): replica_set_user.assert_reaches_phase(Phase.Updated) -@mark.e2e_operator_upgrade_replica_set -def test_upgrade_operator(default_operator: Operator): - default_operator.assert_is_running() +@pytest.mark.e2e_operator_upgrade_replica_set +def test_upgrade_operator(namespace: str, operator_installation_config: dict[str, str]): + operator = get_default_operator( + namespace, operator_installation_config=operator_installation_config, apply_crds_first=True + ) + operator.assert_is_running() @mark.e2e_operator_upgrade_replica_set diff --git a/docker/mongodb-kubernetes-tests/tests/upgrades/sharded_cluster_operator_upgrade_v1_27_to_mck.py b/docker/mongodb-kubernetes-tests/tests/upgrades/sharded_cluster_operator_upgrade_v1_27_to_mck.py index 303b13bab..56454b2a3 100644 --- a/docker/mongodb-kubernetes-tests/tests/upgrades/sharded_cluster_operator_upgrade_v1_27_to_mck.py +++ b/docker/mongodb-kubernetes-tests/tests/upgrades/sharded_cluster_operator_upgrade_v1_27_to_mck.py @@ -12,6 +12,7 @@ LEGACY_OPERATOR_NAME, OPERATOR_NAME, install_legacy_deployment_state_meko, + get_default_operator, log_deployments_info, ) from tests.upgrades import downscale_operator_deployment @@ -113,9 +114,12 @@ def test_downscale_latest_official_operator(self, namespace: str): # and replacing it with MCK downscale_operator_deployment(deployment_name=LEGACY_OPERATOR_NAME, namespace=namespace) - def test_upgrade_operator(self, default_operator: Operator, namespace: str): + def test_upgrade_operator(self, namespace: str, operator_installation_config: dict[str, str]): + operator = get_default_operator( + namespace, operator_installation_config=operator_installation_config, apply_crds_first=True + ) + operator.assert_is_running() logger.info("Installing the operator built from master") - default_operator.assert_is_running() # Dumping deployments in logs ensures we are using the correct operator version log_deployments_info(namespace) From 48735be41afb2464af00d571ce97c8404c4c138a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sierant?= Date: Wed, 30 Apr 2025 14:51:17 +0200 Subject: [PATCH 2/8] Add kubectl download to test_app dockerfile --- docker/mongodb-kubernetes-tests/Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/mongodb-kubernetes-tests/Dockerfile b/docker/mongodb-kubernetes-tests/Dockerfile index fc30c4180..af8c99fa2 100644 --- a/docker/mongodb-kubernetes-tests/Dockerfile +++ b/docker/mongodb-kubernetes-tests/Dockerfile @@ -37,12 +37,19 @@ RUN curl --fail --retry 3 -L -o "${HELM_NAME}" "https://get.helm.sh/${HELM_NAME} && rm "${HELM_NAME}" \ && mv "linux-amd64/helm" "/usr/local/bin/helm" +<<<<<<< HEAD:docker/mongodb-kubernetes-tests/Dockerfile +======= ADD https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.12.0.tgz /tmp/mongodb-tools.tgz RUN mkdir -p /tmp/mongodb-tools && \ tar xfz /tmp/mongodb-tools.tgz -C /tmp/mongodb-tools && \ cp /tmp/mongodb-tools/*/bin/* /usr/local/bin/ && \ rm -rf /tmp/mongodb-tools /tmp/mongodb-tools.tgz +RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" \ + && chmod +x ./kubectl \ + && mv ./kubectl /usr/local/bin/kubectl + +>>>>>>> bb976bad4 (Add kubectl download to test_app dockerfile):docker/mongodb-enterprise-tests/Dockerfile COPY --from=builder /venv /venv ENV PATH="/venv/bin:${PATH}" From 0dcaaff7362e6e05294e699c62b6798035eec010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sierant?= Date: Wed, 30 Apr 2025 15:41:19 +0200 Subject: [PATCH 3/8] Fixed dockerfile --- docker/mongodb-kubernetes-tests/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/mongodb-kubernetes-tests/Dockerfile b/docker/mongodb-kubernetes-tests/Dockerfile index af8c99fa2..65b69d278 100644 --- a/docker/mongodb-kubernetes-tests/Dockerfile +++ b/docker/mongodb-kubernetes-tests/Dockerfile @@ -38,7 +38,6 @@ RUN curl --fail --retry 3 -L -o "${HELM_NAME}" "https://get.helm.sh/${HELM_NAME} && mv "linux-amd64/helm" "/usr/local/bin/helm" <<<<<<< HEAD:docker/mongodb-kubernetes-tests/Dockerfile -======= ADD https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.12.0.tgz /tmp/mongodb-tools.tgz RUN mkdir -p /tmp/mongodb-tools && \ tar xfz /tmp/mongodb-tools.tgz -C /tmp/mongodb-tools && \ @@ -49,7 +48,10 @@ RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl - && chmod +x ./kubectl \ && mv ./kubectl /usr/local/bin/kubectl +<<<<<<< HEAD:docker/mongodb-kubernetes-tests/Dockerfile >>>>>>> bb976bad4 (Add kubectl download to test_app dockerfile):docker/mongodb-enterprise-tests/Dockerfile +======= +>>>>>>> 25ba545ed (Fixed dockerfile):docker/mongodb-enterprise-tests/Dockerfile COPY --from=builder /venv /venv ENV PATH="/venv/bin:${PATH}" From 975605c687b1630e17c6b0a05a5ab208892d85c8 Mon Sep 17 00:00:00 2001 From: Mircea Cosbuc Date: Thu, 15 May 2025 10:29:33 +0200 Subject: [PATCH 4/8] Clean-up rebase --- docker/mongodb-kubernetes-tests/Dockerfile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docker/mongodb-kubernetes-tests/Dockerfile b/docker/mongodb-kubernetes-tests/Dockerfile index 65b69d278..424f5ee76 100644 --- a/docker/mongodb-kubernetes-tests/Dockerfile +++ b/docker/mongodb-kubernetes-tests/Dockerfile @@ -37,7 +37,6 @@ RUN curl --fail --retry 3 -L -o "${HELM_NAME}" "https://get.helm.sh/${HELM_NAME} && rm "${HELM_NAME}" \ && mv "linux-amd64/helm" "/usr/local/bin/helm" -<<<<<<< HEAD:docker/mongodb-kubernetes-tests/Dockerfile ADD https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.12.0.tgz /tmp/mongodb-tools.tgz RUN mkdir -p /tmp/mongodb-tools && \ tar xfz /tmp/mongodb-tools.tgz -C /tmp/mongodb-tools && \ @@ -48,10 +47,6 @@ RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl - && chmod +x ./kubectl \ && mv ./kubectl /usr/local/bin/kubectl -<<<<<<< HEAD:docker/mongodb-kubernetes-tests/Dockerfile ->>>>>>> bb976bad4 (Add kubectl download to test_app dockerfile):docker/mongodb-enterprise-tests/Dockerfile -======= ->>>>>>> 25ba545ed (Fixed dockerfile):docker/mongodb-enterprise-tests/Dockerfile COPY --from=builder /venv /venv ENV PATH="/venv/bin:${PATH}" From 32ccf7c30787a9f4453dd50455cdd7394d792ad2 Mon Sep 17 00:00:00 2001 From: Mircea Cosbuc Date: Thu, 15 May 2025 11:33:31 +0200 Subject: [PATCH 5/8] Fix rebase pytest marks --- .../tests/upgrades/operator_upgrade_replica_set.py | 7 +++---- .../sharded_cluster_operator_upgrade_v1_27_to_mck.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_replica_set.py b/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_replica_set.py index 13fe618e2..121291fa0 100644 --- a/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_replica_set.py +++ b/docker/mongodb-kubernetes-tests/tests/upgrades/operator_upgrade_replica_set.py @@ -1,5 +1,3 @@ -from kubernetes import client -from kubernetes.client import ApiException from kubetester import MongoDB from kubetester.certs import create_mongodb_tls_certs from kubetester.kubetester import KubernetesTester @@ -7,7 +5,8 @@ from kubetester.mongodb import Phase from kubetester.mongodb_user import MongoDBUser from kubetester.operator import Operator -from pytest import fixture +from pytest import fixture, mark +from tests import test_logger from tests.conftest import get_default_operator RS_NAME = "my-replica-set" @@ -94,7 +93,7 @@ def test_replicaset_user_created(replica_set_user: MongoDBUser): replica_set_user.assert_reaches_phase(Phase.Updated) -@pytest.mark.e2e_operator_upgrade_replica_set +@mark.e2e_operator_upgrade_replica_set def test_upgrade_operator(namespace: str, operator_installation_config: dict[str, str]): operator = get_default_operator( namespace, operator_installation_config=operator_installation_config, apply_crds_first=True diff --git a/docker/mongodb-kubernetes-tests/tests/upgrades/sharded_cluster_operator_upgrade_v1_27_to_mck.py b/docker/mongodb-kubernetes-tests/tests/upgrades/sharded_cluster_operator_upgrade_v1_27_to_mck.py index 56454b2a3..9e98bdce7 100644 --- a/docker/mongodb-kubernetes-tests/tests/upgrades/sharded_cluster_operator_upgrade_v1_27_to_mck.py +++ b/docker/mongodb-kubernetes-tests/tests/upgrades/sharded_cluster_operator_upgrade_v1_27_to_mck.py @@ -11,8 +11,8 @@ from tests.conftest import ( LEGACY_OPERATOR_NAME, OPERATOR_NAME, - install_legacy_deployment_state_meko, get_default_operator, + install_legacy_deployment_state_meko, log_deployments_info, ) from tests.upgrades import downscale_operator_deployment From 9ff2b154a8a9659ade738bf36c3f13f92fd14712 Mon Sep 17 00:00:00 2001 From: Mircea Cosbuc Date: Thu, 15 May 2025 11:50:51 +0200 Subject: [PATCH 6/8] Use multi-cluster operator name if required in appdb test --- .../tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py b/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py index 68f588e97..fdf6d28f1 100644 --- a/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py +++ b/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py @@ -10,6 +10,7 @@ LEGACY_OPERATOR_CHART, LEGACY_OPERATOR_IMAGE_NAME, LEGACY_OPERATOR_NAME, + MULTI_CLUSTER_OPERATOR_NAME, create_appdb_certs, get_default_operator, install_official_operator, @@ -129,6 +130,8 @@ def test_downscale_latest_official_operator(namespace: str): @mark.e2e_appdb_tls_operator_upgrade_v1_32_to_mck def test_upgrade_operator(namespace: str, operator_installation_config: dict[str, str]): + if is_multi_cluster(): + operator_installation_config["operator.name"] = MULTI_CLUSTER_OPERATOR_NAME operator = get_default_operator( namespace, operator_installation_config=operator_installation_config, apply_crds_first=True ) From 2b111a43a29a089d4c79a7429187fcb370440fac Mon Sep 17 00:00:00 2001 From: Mircea Cosbuc Date: Thu, 15 May 2025 17:14:05 +0200 Subject: [PATCH 7/8] Fix subprocess call for helm upgrade in tests --- docker/mongodb-kubernetes-tests/kubetester/helm.py | 2 +- scripts/dev/prepare_local_e2e_run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/mongodb-kubernetes-tests/kubetester/helm.py b/docker/mongodb-kubernetes-tests/kubetester/helm.py index 4e1e3f3e6..da6887b81 100644 --- a/docker/mongodb-kubernetes-tests/kubetester/helm.py +++ b/docker/mongodb-kubernetes-tests/kubetester/helm.py @@ -191,7 +191,7 @@ def apply_crds_from_chart(chart_dir: str): for crd_file in crd_files: logger.info(f"Applying CRD from file: {crd_file}") args = ["kubectl", "apply", "-f", crd_file] - process_run_and_check(args, check=True, capture_output=True, shell=True) + process_run_and_check(" ".join(args), check=True, capture_output=True, shell=True) def helm_uninstall(name): diff --git a/scripts/dev/prepare_local_e2e_run.sh b/scripts/dev/prepare_local_e2e_run.sh index 3f2d7d15c..58d6de19d 100755 --- a/scripts/dev/prepare_local_e2e_run.sh +++ b/scripts/dev/prepare_local_e2e_run.sh @@ -76,7 +76,7 @@ if [[ "${DEPLOY_OPERATOR:-"false"}" == "true" ]]; then fi # shellcheck disable=SC2128 - helm upgrade --install mongodb-enterprise-operator helm_chart --set "$(echo "${helm_values}" | tr ' ' ',')" + helm upgrade --install mongodb-kubernetes-operator helm_chart --set "$(echo "${helm_values}" | tr ' ' ',')" fi if [[ "${KUBE_ENVIRONMENT_NAME}" == "kind" ]]; then From 402201f3db53d005c7eed56118d638c7040fc175 Mon Sep 17 00:00:00 2001 From: Mircea Cosbuc Date: Thu, 15 May 2025 18:19:53 +0200 Subject: [PATCH 8/8] Install multicluster operator on appdb upgrade test --- ...appdb_tls_operator_upgrade_v1_32_to_mck.py | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py b/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py index fdf6d28f1..479284743 100644 --- a/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py +++ b/docker/mongodb-kubernetes-tests/tests/upgrades/appdb_tls_operator_upgrade_v1_32_to_mck.py @@ -13,6 +13,7 @@ MULTI_CLUSTER_OPERATOR_NAME, create_appdb_certs, get_default_operator, + get_multi_cluster_operator, install_official_operator, is_multi_cluster, ) @@ -129,12 +130,29 @@ def test_downscale_latest_official_operator(namespace: str): @mark.e2e_appdb_tls_operator_upgrade_v1_32_to_mck -def test_upgrade_operator(namespace: str, operator_installation_config: dict[str, str]): +def test_upgrade_operator( + namespace: str, + central_cluster_name: str, + multi_cluster_operator_installation_config: dict[str, str], + operator_installation_config: dict[str, str], + central_cluster_client, + member_cluster_clients, + member_cluster_names, +): if is_multi_cluster(): - operator_installation_config["operator.name"] = MULTI_CLUSTER_OPERATOR_NAME - operator = get_default_operator( - namespace, operator_installation_config=operator_installation_config, apply_crds_first=True - ) + operator = get_multi_cluster_operator( + namespace, + central_cluster_name, + multi_cluster_operator_installation_config, + central_cluster_client, + member_cluster_clients, + member_cluster_names, + apply_crds_first=True, + ) + else: + operator = get_default_operator( + namespace, operator_installation_config=operator_installation_config, apply_crds_first=True + ) operator.assert_is_running()