Skip to content

Commit eb65be5

Browse files
Make sure local e2es use local helm chart
1 parent 93f3e12 commit eb65be5

File tree

3 files changed

+46
-47
lines changed

3 files changed

+46
-47
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,45 @@ def _create_helm_args(helm_args: Dict[str, str], helm_options: Optional[List[str
300300

301301
def _helm_chart_dir(default: Optional[str] = "helm_chart") -> str:
302302
return os.environ.get("HELM_CHART_DIR", default)
303+
304+
305+
# 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
307+
# 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.
309+
def helm_chart_path_and_version(helm_chart_path: str, operator_version: str) -> tuple[str, str]:
310+
# these are imported here to resolve import cycle issue
311+
from tests.conftest import local_operator
312+
from tests.conftest import LOCAL_HELM_CHART_DIR
313+
314+
if local_operator():
315+
return LOCAL_HELM_CHART_DIR, ""
316+
317+
# if operator_version is not specified and we are not installing the MCK or MEKO chart
318+
# it would mean we want to install OCI published helm chart. Figure out respective version,
319+
# it is set in env var `OPERATOR_VERSION` based on build_scenario.
320+
if not operator_version and helm_chart_path not in (
321+
MCK_HELM_CHART,
322+
LEGACY_OPERATOR_CHART,
323+
):
324+
non_semver_operator_version = os.environ.get(OPERATOR_VERSION_ENV_VAR_NAME)
325+
# when we publish the helm chart we append `0.0.0+` in the chart version, details are
326+
# here https://docs.google.com/document/d/1eJ8iKsI0libbpcJakGjxcPfbrTn8lmcZDbQH1UqMR_g/edit?tab=t.gg5ble8qlesq
327+
operator_version = f"0.0.0+{non_semver_operator_version}"
328+
329+
330+
# helm_chart_path not being passed would mean we are on evg env and would like to
331+
# install helm chart from OCI registry.
332+
if not helm_chart_path:
333+
# login to the OCI container registry
334+
registry, repository, region = oci_chart_info()
335+
try:
336+
oci_helm_registry_login(registry, region)
337+
except Exception as e:
338+
raise e
339+
340+
# figure out the registry URI, based on dev/staging scenario
341+
chart_uri = f"oci://{registry}/{repository}"
342+
helm_chart_path = chart_uri
343+
344+
return helm_chart_path, operator_version

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
helm_upgrade,
2121
oci_chart_info,
2222
oci_helm_registry_login,
23+
helm_chart_path_and_version,
2324
)
2425
from tests import test_logger
2526

@@ -56,31 +57,7 @@ def __init__(
5657
# The Operator will be installed from the following repo, so adding it first
5758
helm_repo_add("mongodb", "https://mongodb.github.io/helm-charts")
5859

59-
# helm_chart_path not being passed would mean we are on evg env and would like to
60-
# install helm chart from OCI registry.
61-
if not helm_chart_path:
62-
# login to the OCI container registry
63-
registry, repository, region = oci_chart_info()
64-
try:
65-
oci_helm_registry_login(registry, region)
66-
except Exception as e:
67-
raise e
68-
69-
# figure out the registry URI, based on dev/staging scenario
70-
chart_uri = f"oci://{registry}/{repository}"
71-
helm_chart_path = chart_uri
72-
73-
# if operator_version is not specified and we are not installing the MCK or MEKO chart
74-
# it would mean we want to install OCI published helm chart. Figure out respective version,
75-
# it is set in env var `OPERATOR_VERSION` based on build_scenario.
76-
if not operator_version and helm_chart_path not in (
77-
MCK_HELM_CHART,
78-
LEGACY_OPERATOR_CHART,
79-
):
80-
non_semver_operator_version = os.environ.get(OPERATOR_VERSION_ENV_VAR_NAME)
81-
# when we publish the helm chart we append `0.0.0+` in the chart version, details are
82-
# here https://docs.google.com/document/d/1eJ8iKsI0libbpcJakGjxcPfbrTn8lmcZDbQH1UqMR_g/edit?tab=t.gg5ble8qlesq
83-
operator_version = f"0.0.0+{non_semver_operator_version}"
60+
helm_chart_path, operator_version = helm_chart_path_and_version(helm_chart_path, operator_version)
8461

8562
if helm_args is None:
8663
helm_args = {}

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
helm_repo_add,
2727
oci_chart_info,
2828
oci_helm_registry_login,
29+
helm_chart_path_and_version,
2930
)
3031
from kubetester.kubetester import KubernetesTester
3132
from kubetester.kubetester import fixture as _fixture
@@ -839,28 +840,7 @@ def _install_multi_cluster_operator(
839840
# The Operator will be installed from the following repo, so adding it first
840841
helm_repo_add("mongodb", "https://mongodb.github.io/helm-charts")
841842

842-
# helm_chart_path not being passed would mean we are on evg env and would like to
843-
# install helm chart from OCI registry.
844-
if not helm_chart_path:
845-
# login to the OCI container registry
846-
registry, repository, region = oci_chart_info()
847-
try:
848-
oci_helm_registry_login(registry, region)
849-
except Exception as e:
850-
raise e
851-
852-
# figure out the registry URI, based on dev/staging scenario
853-
chart_uri = f"oci://{registry}/{repository}"
854-
855-
helm_chart_path = chart_uri
856-
857-
if not custom_operator_version and helm_chart_path not in (MCK_HELM_CHART, LEGACY_OPERATOR_CHART):
858-
# custom_operator_version is not set and chart is also neither MCK nor MEKO would mean we are trying to install
859-
# the operator from OCI registry. The version based on build scenario (dev/staging) is set in `OPERATOR_VERSION` env var.
860-
non_semver_custom_operator_version = os.environ.get(OPERATOR_VERSION_ENV_VAR_NAME)
861-
# when we publish the helm chart we append `0.0.0+` in the chart version, details are
862-
# here https://docs.google.com/document/d/1eJ8iKsI0libbpcJakGjxcPfbrTn8lmcZDbQH1UqMR_g/edit?tab=t.gg5ble8qlesq
863-
custom_operator_version = f"0.0.0+{non_semver_custom_operator_version}"
843+
helm_chart_path, custom_operator_version = helm_chart_path_and_version(helm_chart_path, custom_operator_version)
864844

865845
prepare_multi_cluster_namespaces(
866846
namespace,

0 commit comments

Comments
 (0)