Skip to content

Commit 1ee164a

Browse files
committed
Fix multicluster tests
1 parent c482251 commit 1ee164a

File tree

3 files changed

+15
-51
lines changed

3 files changed

+15
-51
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import glob
2-
import logging
32
import os
43
import re
54
import subprocess
@@ -30,7 +29,7 @@ def helm_template(
3029
command_args.append("--show-only")
3130
command_args.append(templates)
3231

33-
args = ("helm", "template", *(command_args), _helm_chart_dir(helm_chart_path))
32+
args = ("helm", "template", *command_args, _helm_chart_dir(helm_chart_path))
3433
logger.info(" ".join(args))
3534

3635
yaml_file_name = "{}.yaml".format(str(uuid.uuid4()))
@@ -316,7 +315,10 @@ def helm_chart_path_and_version(helm_chart_path: str, operator_version: str) ->
316315

317316
# helm_chart_path not being passed would mean we would like to install helm chart from OCI registry.
318317
if not helm_chart_path:
319-
operator_version = os.environ.get(OCI_HELM_VERSION)
318+
# If operator_version is not passed, we want to install the current version.
319+
if not operator_version:
320+
operator_version = os.environ.get(OCI_HELM_VERSION)
321+
320322
registry, repository, region = oci_chart_info()
321323
# If ECR we need to login first to the OCI container registry
322324
if registry == OCI_HELM_REGISTRY_ECR:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from kubetester.awss3client import AwsS3Client
2323
from kubetester.consts import *
2424
from kubetester.helm import (
25+
helm_chart_path_and_version,
2526
helm_install_from_chart,
2627
helm_repo_add,
2728
)
@@ -837,6 +838,8 @@ def _install_multi_cluster_operator(
837838
# The Operator will be installed from the following repo, so adding it first
838839
helm_repo_add("mongodb", "https://mongodb.github.io/helm-charts")
839840

841+
helm_chart_path, operator_version = helm_chart_path_and_version(helm_chart_path, custom_operator_version)
842+
840843
prepare_multi_cluster_namespaces(
841844
namespace,
842845
multi_cluster_operator_installation_config,

scripts/release/publish_helm_chart.py

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import argparse
2-
import os
32
import subprocess
43

5-
import yaml
6-
74
from lib.base_logger import logger
85
from scripts.release.build.build_info import *
96
from scripts.release.build.build_scenario import SUPPORTED_SCENARIOS
107

118
CHART_DIR = "helm_chart"
9+
MONGODB_KUBERNETES_CHART = "mongodb-kubernetes"
1210

1311

1412
def run_command(command: list[str]):
@@ -26,44 +24,6 @@ def run_command(command: list[str]):
2624
)
2725

2826

29-
# update_chart_and_get_metadata updates the helm chart's Chart.yaml and sets the proper version
30-
# When we publish the helm chart to dev and staging we append `0.0.0+` in the chart version, details are
31-
# here https://docs.google.com/document/d/1eJ8iKsI0libbpcJakGjxcPfbrTn8lmcZDbQH1UqMR_g/edit?tab=t.gg5ble8qlesq
32-
def update_chart_and_get_metadata(chart_dir: str, version: str) -> tuple[str, str]:
33-
chart_path = os.path.join(chart_dir, "Chart.yaml")
34-
35-
if not os.path.exists(chart_path):
36-
raise FileNotFoundError(
37-
f"Error: Chart.yaml not found in directory '{chart_dir}'. "
38-
"Please ensure the directory exists and contains a valid Chart.yaml."
39-
)
40-
41-
try:
42-
with open(chart_path, "r") as f:
43-
data = yaml.safe_load(f)
44-
45-
chart_name = data.get("name")
46-
if not chart_name:
47-
raise ValueError("Chart.yaml is missing required 'name' field.")
48-
except Exception as e:
49-
raise Exception(f"Unable to load Chart.yaml from dir {chart_path}: {e}")
50-
51-
if data["version"] == version:
52-
logger.info(f"Chart '{chart_name}' already has version '{version}'. No update needed.")
53-
return chart_name, version
54-
55-
try:
56-
data["version"] = version
57-
58-
with open(chart_path, "w") as f:
59-
yaml.safe_dump(data, f, sort_keys=False)
60-
61-
logger.info(f"Successfully updated version for chart '{chart_name}' to '{version}'.")
62-
return chart_name, version
63-
except Exception as e:
64-
raise RuntimeError(f"Failed to read or update Chart.yaml: {e}")
65-
66-
6727
def get_oci_registry(chart_info: HelmChartInfo) -> str:
6828
registry = chart_info.registry
6929
repo = chart_info.repository
@@ -79,19 +39,18 @@ def get_oci_registry(chart_info: HelmChartInfo) -> str:
7939
return oci_registry
8040

8141

82-
def publish_helm_chart(chart_info: HelmChartInfo, operator_version: str):
42+
def publish_helm_chart(chart_name: str, chart_info: HelmChartInfo, operator_version: str):
8343
try:
84-
# If version_prefix is not specified, the chart.yaml would already have correct chart version
44+
# If version_prefix is not specified, use the operator_version as is.
8545
if chart_info.version_prefix is not None:
86-
helm_version = f"{chart_info.version_prefix}{operator_version}"
46+
chart_version = f"{chart_info.version_prefix}{operator_version}"
8747
else:
88-
helm_version = operator_version
48+
chart_version = operator_version
8949

90-
chart_name, chart_version = update_chart_and_get_metadata(CHART_DIR, helm_version)
9150
tgz_filename = f"{chart_name}-{chart_version}.tgz"
9251

9352
logger.info(f"Packaging chart: {chart_name} with Version: {chart_version}")
94-
package_command = ["helm", "package", CHART_DIR]
53+
package_command = ["helm", "package", "--version", chart_version, CHART_DIR]
9554
run_command(package_command)
9655

9756
oci_registry = get_oci_registry(chart_info)
@@ -134,7 +93,7 @@ def main():
13493
build_scenario = args.build_scenario
13594
build_info = load_build_info(build_scenario)
13695

137-
return publish_helm_chart(build_info.helm_charts["mongodb-kubernetes"], args.version)
96+
return publish_helm_chart(MONGODB_KUBERNETES_CHART, build_info.helm_charts[MONGODB_KUBERNETES_CHART], args.version)
13897

13998

14099
if __name__ == "__main__":

0 commit comments

Comments
 (0)