Skip to content

Commit e1700ca

Browse files
committed
Fixes
1 parent 084b8f2 commit e1700ca

File tree

3 files changed

+48
-30
lines changed

3 files changed

+48
-30
lines changed

scripts/evergreen/deployments/test-app/templates/mongodb-enterprise-tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ spec:
174174
- name: OM_DEBUG_HTTP
175175
value: "{{ .Values.omDebugHttp }}"
176176
{{ end }}
177+
{{ if .Values.helm.oci.version }}
178+
- name: OCI_HELM_VERSION
179+
value: "{{ .Values.helm.oci.version }}"
180+
{{ end }}
177181
{{ if .Values.helm.oci.registry }}
178182
- name: OCI_HELM_REGISTRY
179183
value: "{{ .Values.helm.oci.registry }}"
180184
{{ end }}
181-
{{ if .Values.operator.version }}
182-
- name: OPERATOR_VERSION
183-
value: "{{ .Values.operator.version }}"
184-
{{ end }}
185185
{{ if .Values.helm.oci.repository }}
186186
- name: OCI_HELM_REPOSITORY
187187
value: "{{ .Values.helm.oci.repository }}"

scripts/release/publish_helm_chart.py

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44

55
import yaml
6+
from release.build.build_scenario import SUPPORTED_SCENARIOS
67

78
from lib.base_logger import logger
89
from scripts.release.build.build_info import *
@@ -25,15 +26,11 @@ def run_command(command: list[str]):
2526
)
2627

2728

28-
# update_chart_and_get_metadata updates the helm chart's Chart.yaml and sets the version
29-
# to either evg patch id or commit which is set in OPERATOR_VERSION.
30-
def update_chart_and_get_metadata(chart_dir: str, version_prefix: str = None) -> tuple[str, str]:
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]:
3133
chart_path = os.path.join(chart_dir, "Chart.yaml")
32-
version = os.environ.get("OPERATOR_VERSION")
33-
if not version:
34-
raise ValueError(
35-
"Error: Environment variable 'OPERATOR_VERSION' must be set to determine the chart version to publish."
36-
)
3734

3835
if not os.path.exists(chart_path):
3936
raise FileNotFoundError(
@@ -51,23 +48,18 @@ def update_chart_and_get_metadata(chart_dir: str, version_prefix: str = None) ->
5148
except Exception as e:
5249
raise Exception(f"Unable to load Chart.yaml from dir {chart_path}: {e}")
5350

54-
# If version_prefix is not specified, the chart.yaml would already have correct chart version
55-
if version_prefix is None:
51+
if data["version"] == version:
52+
logger.info(f"Chart '{chart_name}' already has version '{version}'. No update needed.")
5653
return chart_name, version
5754

58-
# When we publish the helm chart to dev and staging we append `0.0.0+` in the chart version, details are
59-
# here https://docs.google.com/document/d/1eJ8iKsI0libbpcJakGjxcPfbrTn8lmcZDbQH1UqMR_g/edit?tab=t.gg5ble8qlesq
60-
new_version = f"{version_prefix}{version}"
61-
logger.info(f"New helm chart version will be: {new_version}")
62-
6355
try:
64-
data["version"] = new_version
56+
data["version"] = version
6557

6658
with open(chart_path, "w") as f:
6759
yaml.safe_dump(data, f, sort_keys=False)
6860

69-
logger.info(f"Successfully updated version for chart '{chart_name}' to '{new_version}'.")
70-
return chart_name, new_version
61+
logger.info(f"Successfully updated version for chart '{chart_name}' to '{version}'.")
62+
return chart_name, version
7163
except Exception as e:
7264
raise RuntimeError(f"Failed to read or update Chart.yaml: {e}")
7365

@@ -87,16 +79,22 @@ def get_oci_registry(chart_info: HelmChartInfo) -> str:
8779
return oci_registry
8880

8981

90-
def publish_helm_chart(chart_info: HelmChartInfo, build_scenario):
82+
def publish_helm_chart(chart_info: HelmChartInfo, operator_version: str):
9183
try:
92-
oci_registry = get_oci_registry(chart_info)
93-
chart_name, chart_version = update_chart_and_get_metadata(CHART_DIR, chart_info.version_prefix)
84+
# If version_prefix is not specified, the chart.yaml would already have correct chart version
85+
if chart_info.version_prefix is not None:
86+
helm_version = f"{chart_info.version_prefix}{operator_version}"
87+
else:
88+
helm_version = operator_version
89+
90+
chart_name, chart_version = update_chart_and_get_metadata(CHART_DIR, helm_version)
9491
tgz_filename = f"{chart_name}-{chart_version}.tgz"
9592

9693
logger.info(f"Packaging chart: {chart_name} with Version: {chart_version}")
9794
package_command = ["helm", "package", CHART_DIR]
9895
run_command(package_command)
9996

97+
oci_registry = get_oci_registry(chart_info)
10098
logger.info(f"Pushing chart to registry: {oci_registry}")
10199
push_command = ["helm", "push", tgz_filename, oci_registry]
102100
run_command(push_command)
@@ -108,15 +106,35 @@ def publish_helm_chart(chart_info: HelmChartInfo, build_scenario):
108106

109107
def main():
110108
parser = argparse.ArgumentParser(
111-
description="Script to publish helm chart to the OCI container registry, based on the build scenario."
109+
description="Script to publish helm chart to the OCI container registry, based on the build scenario.",
110+
formatter_class=argparse.RawDescriptionHelpFormatter,
111+
)
112+
parser.add_argument(
113+
"-b",
114+
"--build-scenario",
115+
metavar="",
116+
action="store",
117+
required=True,
118+
type=str,
119+
choices=SUPPORTED_SCENARIOS,
120+
help=f"""Build scenario when reading configuration from 'build_info.json'.
121+
Options: {", ".join(SUPPORTED_SCENARIOS)}. For '{BuildScenario.DEVELOPMENT}' the '{BuildScenario.PATCH}' scenario is used to read values from 'build_info.json'""",
122+
)
123+
parser.add_argument(
124+
"-v",
125+
"--version",
126+
metavar="",
127+
action="store",
128+
required=True,
129+
type=str,
130+
help="Operator version to use when publishing helm chart",
112131
)
113-
parser.add_argument("--build_scenario", type=str, help="Build scenario (e.g., patch, staging etc).")
114132
args = parser.parse_args()
115133

116134
build_scenario = args.build_scenario
117135
build_info = load_build_info(build_scenario)
118136

119-
return publish_helm_chart(build_info.helm_charts["mongodb-kubernetes"], build_scenario)
137+
return publish_helm_chart(build_info.helm_charts["mongodb-kubernetes"], args.version)
120138

121139

122140
if __name__ == "__main__":

scripts/release/publish_helm_chart.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# Instead of calling the publish_helm_chart.py directly from .evergreen-functions.yaml
44
# we are calling that via this .sh so that we can easily pass build_scenario from env var that
5-
# is set via context files. Using the env vars, set via context files, in .evergreen configuraiton
5+
# is set via context files. Using the env vars, set via context files, in .evergreen configuration
66
# is not that straightforward.
77
set -Eeou pipefail
88

99
source scripts/dev/set_env_context.sh
1010

11-
scripts/dev/run_python.sh scripts/release/publish_helm_chart.py --build_scenario "${BUILD_SCENARIO}"
11+
scripts/dev/run_python.sh scripts/release/publish_helm_chart.py --build_scenario "${BUILD_SCENARIO}" --version "${OPERATOR_VERSION}"

0 commit comments

Comments
 (0)