11import argparse
2- import os
32import subprocess
43
5- import yaml
6-
74from lib .base_logger import logger
85from scripts .release .build .build_info import *
96from scripts .release .build .build_scenario import SUPPORTED_SCENARIOS
107
118CHART_DIR = "helm_chart"
9+ MONGODB_KUBERNETES_CHART = "mongodb-kubernetes"
1210
1311
1412def 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-
6727def 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
14099if __name__ == "__main__" :
0 commit comments