Skip to content

Commit 1068518

Browse files
committed
Review fixes
1 parent 8f50012 commit 1068518

File tree

6 files changed

+47
-52
lines changed

6 files changed

+47
-52
lines changed

docker/mongodb-kubernetes-tests/Dockerfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ RUN apt-get -qq update \
1616

1717
COPY requirements.txt requirements.txt
1818

19-
RUN python3 -m venv /venv && . /venv/bin/activate && pip install --upgrade pip && GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 pip install -r requirements.txt
19+
RUN python3 -m venv /venv \
20+
&& . /venv/bin/activate \
21+
&& pip install --upgrade pip \
22+
&& GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 pip install -r requirements.txt \
23+
&& pip install awscli # install aws, required to run helm registry login while running the tests
2024

2125
FROM scratch AS tools_downloader
2226

@@ -44,9 +48,7 @@ RUN apt-get -qq update \
4448
curl \
4549
libldap2-dev \
4650
libsasl2-dev \
47-
git \
48-
openssl \
49-
unzip
51+
git
5052

5153
RUN mkdir -p /tmp/mongodb-tools && \
5254
tar xfz /tmp/mongodb-tools.tgz -C /tmp/mongodb-tools && \
@@ -67,11 +69,6 @@ RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -
6769
&& chmod +x ./kubectl \
6870
&& mv ./kubectl /usr/local/bin/kubectl
6971

70-
# install aws, required to run helm registry login while running the tests
71-
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
72-
&& unzip -q awscliv2.zip \
73-
&& ./aws/install
74-
7572
COPY --from=builder /venv /venv
7673

7774
ENV PATH="/venv/bin:${PATH}"

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def process_run_and_check(args, **kwargs):
149149
raise
150150

151151

152-
def oci_helm_registry_login(helm_registry: str, region: str):
152+
def helm_registry_login_to_ecr(helm_registry: str, region: str):
153153
logger.info(f"Attempting to log into ECR registry: {helm_registry}, using helm registry login.")
154154

155155
aws_command = ["aws", "ecr", "get-login-password", "--region", region]
@@ -303,17 +303,17 @@ def _helm_chart_dir(default: Optional[str] = "helm_chart") -> str:
303303

304304

305305
# helm_chart_path_and_version returns the chart path and version that we would like to install to run the E2E tests.
306-
# for local tests it returns early with local helm chart dir and for other scenarios it figure out the chart and version
306+
# for local tests it returns early with local helm chart dir and for other scenarios it figures out the chart and version
307307
# based on the caller. In most of the cases we will install chart from OCI registry but for the tests where we would like
308-
# to install MEKO's specific version or MCK's specific version, we would expec `helm_chart_path` to set already.
308+
# to install MEKO's specific version or MCK's specific version, we would expect `helm_chart_path` to set already.
309309
def helm_chart_path_and_version(helm_chart_path: str, operator_version: str) -> tuple[str, str]:
310310
# these are imported here to resolve import cycle issue
311311
from tests.conftest import LOCAL_HELM_CHART_DIR, local_operator
312312

313313
if local_operator():
314314
return LOCAL_HELM_CHART_DIR, ""
315315

316-
# if operator_version is not specified and we are not installing the MCK or MEKO chart
316+
# if operator_version is not specified, and we are not installing the MCK or MEKO chart
317317
# it would mean we want to install OCI published helm chart. Figure out respective version,
318318
# it is set in env var `OPERATOR_VERSION` based on build_scenario.
319319
if not operator_version and helm_chart_path not in (
@@ -328,12 +328,13 @@ def helm_chart_path_and_version(helm_chart_path: str, operator_version: str) ->
328328
# helm_chart_path not being passed would mean we are on evg env and would like to
329329
# install helm chart from OCI registry.
330330
if not helm_chart_path:
331-
# login to the OCI container registry
332331
registry, repository, region = oci_chart_info()
333-
try:
334-
oci_helm_registry_login(registry, region)
335-
except Exception as e:
336-
raise e
332+
# If ECR we need to login first to the OCI container registry
333+
if registry == "268558157000.dkr.ecr.us-east-1.amazonaws.com":
334+
try:
335+
helm_registry_login_to_ecr(registry, region)
336+
except Exception as e:
337+
raise Exception(f"Failed to login to ECR helm registry {registry}. Error: {e}")
337338

338339
# figure out the registry URI, based on dev/staging scenario
339340
chart_uri = f"oci://{registry}/{repository}"

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
import logging
4-
import os
53
import time
64
from typing import Dict, List, Optional
75

@@ -10,7 +8,6 @@
108
from kubernetes.client import V1CustomResourceDefinition, V1Deployment, V1Pod
119
from kubernetes.client.rest import ApiException
1210
from kubetester import wait_for_webhook
13-
from kubetester.consts import *
1411
from kubetester.create_or_replace_from_yaml import create_or_replace_from_yaml
1512
from kubetester.helm import (
1613
helm_chart_path_and_version,
@@ -19,8 +16,6 @@
1916
helm_template,
2017
helm_uninstall,
2118
helm_upgrade,
22-
oci_chart_info,
23-
oci_helm_registry_login,
2419
)
2520
from tests import test_logger
2621

docker/mongodb-kubernetes-tests/tests/conftest.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
from kubetester.awss3client import AwsS3Client
2323
from kubetester.consts import *
2424
from kubetester.helm import (
25-
helm_chart_path_and_version,
2625
helm_install_from_chart,
2726
helm_repo_add,
28-
oci_chart_info,
29-
oci_helm_registry_login,
3027
)
3128
from kubetester.kubetester import KubernetesTester
3229
from kubetester.kubetester import fixture as _fixture
@@ -840,8 +837,6 @@ def _install_multi_cluster_operator(
840837
# The Operator will be installed from the following repo, so adding it first
841838
helm_repo_add("mongodb", "https://mongodb.github.io/helm-charts")
842839

843-
helm_chart_path, custom_operator_version = helm_chart_path_and_version(helm_chart_path, custom_operator_version)
844-
845840
prepare_multi_cluster_namespaces(
846841
namespace,
847842
multi_cluster_operator_installation_config,
@@ -857,6 +852,7 @@ def _install_multi_cluster_operator(
857852
helm_args=multi_cluster_operator_installation_config,
858853
api_client=central_cluster_client,
859854
helm_chart_path=helm_chart_path,
855+
operator_version=custom_operator_version,
860856
).upgrade(multi_cluster=True, custom_operator_version=custom_operator_version, apply_crds_first=apply_crds_first)
861857

862858
# If we're running locally, then immediately after installing the deployment, we scale it to zero.

scripts/evergreen/e2e/single_e2e.sh

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ deploy_test_app() {
4848
BUILD_ID="${BUILD_ID:-default_build_id}"
4949
BUILD_VARIANT="${BUILD_VARIANT:-default_build_variant}"
5050

51-
chart_info=$(scripts/dev/run_python.sh scripts/release/oci_chart_info.py)
52-
helm_oci_regisry=$(echo "${chart_info}" | jq -r '.registry' )
51+
chart_info=$(scripts/dev/run_python.sh scripts/release/oci_chart_info.py --build_scenario "${BUILD_SCENARIO}")
52+
helm_oci_registry=$(echo "${chart_info}" | jq -r '.registry' )
5353
helm_oci_repository=$(echo "${chart_info}" | jq -r '.repository' )
5454
helm_oci_registry_region=$(echo "${chart_info}" | jq -r '.region' )
5555

5656
# note, that the 4 last parameters are used only for Mongodb resource testing - not for Ops Manager
5757
helm_params=(
5858
"--set" "taskId=${task_id:-'not-specified'}"
59+
"--set" "operator.version=${OPERATOR_VERSION}"
5960
"--set" "namespace=${NAMESPACE}"
6061
"--set" "taskName=${task_name}"
6162
"--set" "mekoTestsRegistry=${MEKO_TESTS_REGISTRY}"
@@ -81,6 +82,9 @@ deploy_test_app() {
8182
"--set" "cognito_user_password=${cognito_user_password}"
8283
"--set" "cognito_workload_url=${cognito_workload_url}"
8384
"--set" "cognito_workload_user_id=${cognito_workload_user_id}"
85+
"--set" "helm.oci.registry=${helm_oci_registry}"
86+
"--set" "helm.oci.repository=${helm_oci_repository}"
87+
"--set" "helm.oci.region=${helm_oci_registry_region}"
8488
)
8589

8690
# shellcheck disable=SC2154
@@ -147,22 +151,6 @@ deploy_test_app() {
147151
helm_params+=("--set" "omDebugHttp=true")
148152
fi
149153

150-
if [[ -n "${helm_oci_regisry:-}" ]]; then
151-
helm_params+=("--set" "helm.oci.registry=${helm_oci_regisry}")
152-
fi
153-
154-
if [[ -n "${helm_oci_repository:-}" ]]; then
155-
helm_params+=("--set" "helm.oci.repository=${helm_oci_repository}")
156-
fi
157-
158-
if [[ -n "${helm_oci_registry_region:-}" ]]; then
159-
helm_params+=("--set" "helm.oci.region=${helm_oci_registry_region}")
160-
fi
161-
162-
if [[ -n "${OPERATOR_VERSION:-}" ]]; then
163-
helm_params+=("--set" "operator.version=${OPERATOR_VERSION}")
164-
fi
165-
166154
helm_params+=("--set" "opsManagerVersion=${ops_manager_version}")
167155

168156
helm template "scripts/evergreen/deployments/test-app" "${helm_params[@]}" > "${helm_template_file}" || exit 1

scripts/release/oci_chart_info.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
import argparse
12
import json
2-
import os
3-
import sys
43
from dataclasses import asdict
54

6-
from lib.base_logger import logger
5+
from release.build.build_scenario import BuildScenario
6+
77
from scripts.release.build.build_info import load_build_info
88

99

1010
def main():
11-
build_scenario = os.environ.get("BUILD_SCENARIO")
11+
supported_scenarios = list(BuildScenario)
12+
13+
parser = argparse.ArgumentParser(
14+
description="""Dump the Helm chart information for the 'mongodb-kubernetes' chart as JSON.""",
15+
formatter_class=argparse.RawTextHelpFormatter,
16+
)
17+
parser.add_argument(
18+
"-b",
19+
"--build-scenario",
20+
metavar="",
21+
action="store",
22+
required=True,
23+
type=str,
24+
choices=supported_scenarios,
25+
help=f"""Build scenario when reading configuration from 'build_info.json'.
26+
Options: {", ".join(supported_scenarios)}. For '{BuildScenario.DEVELOPMENT}' the '{BuildScenario.PATCH}' scenario is used to read values from 'build_info.json'""",
27+
)
28+
args = parser.parse_args()
29+
30+
build_scenario = BuildScenario(args.build_scenario)
1231
build_info = load_build_info(build_scenario)
1332
chart_info = build_info.helm_charts["mongodb-kubernetes"]
1433

@@ -20,5 +39,4 @@ def main():
2039
try:
2140
main()
2241
except Exception as e:
23-
logger.error(f"Failed while dumping the chart_info as json. Error: {e}")
24-
sys.exit(1)
42+
raise Exception(f"Failed while dumping the chart_info as json. Error: {e}")

0 commit comments

Comments
 (0)