Skip to content

Commit e2a0c99

Browse files
Refactor a little, make consts etc
1 parent e81238f commit e2a0c99

File tree

4 files changed

+53
-29
lines changed

4 files changed

+53
-29
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
OPERATOR_VERSION_ENV_VAR_NAME = "OPERATOR_VERSION"
2+
3+
OCI_HELM_REGISTRY_ENV_VAR_NAME = "OCI_HELM_REGISTRY"
4+
OCI_HELM_REPOSITORY_ENV_VAR_NAME = "OCI_HELM_REPOSITORY"
5+
OCI_HELM_REGION_ENV_VAR_NAME = "OCI_HELM_REGION"
6+
7+
LEGACY_OPERATOR_CHART = "mongodb/enterprise-operator"
8+
MCK_HELM_CHART = "mongodb/mongodb-kubernetes"

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import uuid
77
from typing import Dict, List, Optional, Tuple
88

9+
from kubetester.consts import *
910
from tests import test_logger
1011

1112
logger = test_logger.get_test_logger(__name__)
1213

14+
# LOCAL_CRDs_DIR is the dir where local helm chart's CRDs are copied in tests image
15+
LOCAL_CRDs_DIR = "helm_chart/crds"
16+
1317

1418
def helm_template(
1519
helm_args: Dict,
@@ -211,8 +215,7 @@ def helm_upgrade(
211215
chart_dir = helm_chart_path if helm_override_path else _helm_chart_dir(helm_chart_path)
212216

213217
if apply_crds_first:
214-
local_helm_chart_dir = "helm_chart"
215-
apply_crds_from_chart(local_helm_chart_dir)
218+
apply_crds_from_chart(LOCAL_CRDs_DIR)
216219

217220
command_args = _create_helm_args(helm_args, helm_options)
218221
args = [
@@ -233,21 +236,24 @@ def helm_upgrade(
233236
process_run_and_check(command, check=True, capture_output=True, shell=True)
234237

235238

239+
# oci_chart_info returns the respective registry/repo and region information
240+
# based on the build scenario (dev/staging) tests are being run in. These are
241+
# read from build_info.json and then set to the tests image as env vars.
236242
def oci_chart_info():
237-
registry = os.environ.get("OCI_HELM_REGISTRY")
238-
repository = os.environ.get("OCI_HELM_REPOSITORY")
239-
region = os.environ.get("OCI_HELM_REGION")
243+
registry = os.environ.get(OCI_HELM_REGISTRY_ENV_VAR_NAME)
244+
repository = os.environ.get(OCI_HELM_REPOSITORY_ENV_VAR_NAME)
245+
region = os.environ.get(OCI_HELM_REGION_ENV_VAR_NAME)
240246

241-
print(f"oci chart details in test image is registry {registry}, repo {repository}, region {region}")
247+
logger.info(f"oci chart details in test image is registry {registry}, repo {repository}, region {region}")
242248

243249
return registry, f"{repository}/mongodb-kubernetes", region
244250

245251

246-
def apply_crds_from_chart(chart_dir: str):
247-
crd_files = glob.glob(os.path.join(chart_dir, "crds", "*.yaml"))
252+
def apply_crds_from_chart(crds_dir: str):
253+
crd_files = glob.glob(os.path.join(crds_dir, "*.yaml"))
248254

249255
if not crd_files:
250-
raise Exception(f"No CRD files found in chart directory: {chart_dir}")
256+
raise Exception(f"No CRD files found in chart directory: {crds_dir}")
251257

252258
logger.info(f"Found {len(crd_files)} CRD files to apply:")
253259

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from kubernetes.client import V1CustomResourceDefinition, V1Deployment, V1Pod
1111
from kubernetes.client.rest import ApiException
1212
from kubetester import wait_for_webhook
13+
from kubetester.consts import *
1314
from kubetester.create_or_replace_from_yaml import create_or_replace_from_yaml
1415
from kubetester.helm import (
1516
helm_install,
@@ -28,6 +29,7 @@
2829
"opsmanagers.mongodb.com",
2930
)
3031

32+
3133
logger = test_logger.get_test_logger(__name__)
3234

3335

@@ -54,6 +56,8 @@ def __init__(
5456
# The Operator will be installed from the following repo, so adding it first
5557
helm_repo_add("mongodb", "https://mongodb.github.io/helm-charts")
5658

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.
5761
if not helm_chart_path:
5862
# login to the OCI container registry
5963
registry, repository, region = oci_chart_info()
@@ -66,13 +70,16 @@ def __init__(
6670
chart_uri = f"oci://{registry}/{repository}"
6771
helm_chart_path = chart_uri
6872

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.
6976
if not operator_version and helm_chart_path not in (
70-
"mongodb/mongodb-kubernetes",
71-
"mongodb/enterprise-operator",
77+
MCK_HELM_CHART,
78+
LEGACY_OPERATOR_CHART,
7279
):
73-
# most probably we are trying to install current operator which will be installed
74-
# from OCI registry. The version (dev/staging) is set in `OPERATOR_VERSION`
75-
non_semver_operator_version = os.environ.get("OPERATOR_VERSION")
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
7683
operator_version = f"0.0.0+{non_semver_operator_version}"
7784

7885
if helm_args is None:

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
update_configmap,
2121
)
2222
from kubetester.awss3client import AwsS3Client
23+
from kubetester.consts import *
2324
from kubetester.helm import (
2425
helm_install_from_chart,
2526
helm_repo_add,
@@ -60,9 +61,6 @@
6061
LEGACY_CENTRAL_CLUSTER_NAME: str = "__default"
6162
LEGACY_DEPLOYMENT_STATE_VERSION: str = "1.27.0"
6263

63-
# Helm charts
64-
LEGACY_OPERATOR_CHART = "mongodb/enterprise-operator"
65-
MCK_HELM_CHART = "mongodb/mongodb-kubernetes"
6664
LOCAL_HELM_CHART_DIR = "helm_chart"
6765

6866
OFFICIAL_OPERATOR_IMAGE_NAME = "mongodb-kubernetes"
@@ -841,22 +839,27 @@ def _install_multi_cluster_operator(
841839
# The Operator will be installed from the following repo, so adding it first
842840
helm_repo_add("mongodb", "https://mongodb.github.io/helm-charts")
843841

844-
# login to the OCI container registry
845-
registry, repository, region = oci_chart_info()
846-
try:
847-
oci_helm_registry_login(registry, region)
848-
except Exception as e:
849-
raise e
850-
851-
# figure out the registry URI, based on dev/staging scenario
852-
chart_uri = f"oci://{registry}/{repository}"
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.
853844
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+
854855
helm_chart_path = chart_uri
855856

856857
if not custom_operator_version and helm_chart_path not in (MCK_HELM_CHART, LEGACY_OPERATOR_CHART):
857-
# most probably we are trying to install current operator which will be installed
858-
# from OCI registry. The version (dev/staging) is set in `OPERATOR_VERSION`
859-
non_semver_custom_operator_version = os.environ.get("OPERATOR_VERSION")
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
860863
custom_operator_version = f"0.0.0+{non_semver_custom_operator_version}"
861864

862865
prepare_multi_cluster_namespaces(

0 commit comments

Comments
 (0)