-
Notifications
You must be signed in to change notification settings - Fork 25
[CLOUDP-352383] Add a build variant to release chart to OCI registry #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d0ae384
9459e3c
8011687
e6f7e34
f09afa8
b863e04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| from lib.base_logger import logger | ||
| from scripts.release.build.build_info import * | ||
| from scripts.release.helm_registry_login import BUILD_SCENARIO_RELEASE | ||
|
|
||
| CHART_DIR = "helm_chart" | ||
|
|
||
|
|
@@ -28,17 +29,14 @@ def run_command(command: list[str]): | |
|
|
||
| # update_chart_and_get_metadata updates the helm chart's Chart.yaml and sets the version | ||
| # to either evg patch id or commit which is set in OPERATOR_VERSION. | ||
| def update_chart_and_get_metadata(chart_dir: str) -> tuple[str, str]: | ||
| def update_chart_and_get_metadata(chart_dir: str, build_scenario) -> tuple[str, str]: | ||
| chart_path = os.path.join(chart_dir, "Chart.yaml") | ||
| version_id = os.environ.get("OPERATOR_VERSION") | ||
| if not version_id: | ||
| version = os.environ.get("OPERATOR_VERSION") | ||
| if not version: | ||
| raise ValueError( | ||
| "Error: Environment variable 'OPERATOR_VERSION' must be set to determine the chart version to publish." | ||
| ) | ||
|
|
||
| new_version = f"0.0.0+{version_id}" | ||
| logger.info(f"New helm chart version will be: {new_version}") | ||
|
|
||
| if not os.path.exists(chart_path): | ||
| raise FileNotFoundError( | ||
| f"Error: Chart.yaml not found in directory '{chart_dir}'. " | ||
|
|
@@ -52,7 +50,17 @@ def update_chart_and_get_metadata(chart_dir: str) -> tuple[str, str]: | |
| chart_name = data.get("name") | ||
| if not chart_name: | ||
| raise ValueError("Chart.yaml is missing required 'name' field.") | ||
| except Exception as e: | ||
| raise Exception(f"Unable to load Chart.yaml from dir {chart_path}") | ||
|
|
||
| # if build_scenario is release, the chart.yaml would already have correct chart version | ||
| if build_scenario == BUILD_SCENARIO_RELEASE: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not hide this logic in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, there are quite a few things here. First is, this change of figuring out the version of dev/staging is not really part of this PR, it was merged as part of the change in this PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or in other words, does it make sense to make something configurable, which doesn't need to be. We know that we are not going to change 0.0.0 to something else.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If we follow this logic trail, we could just have the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we can still add comment about this in
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's true, to build configuration will rarely change, but it doesn't mean this is the only benefit of having it - to change the configuration. The biggest gain in my opinion is to move abstract conditional logic from the code and make it simple, readable and testable.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I can make the change. Is it ok if I do it in the new PR?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, it can be done separately. |
||
| return chart_name, version | ||
|
|
||
| new_version = f"0.0.0+{version}" | ||
| logger.info(f"New helm chart version will be: {new_version}") | ||
|
|
||
| try: | ||
| data["version"] = new_version | ||
|
|
||
| with open(chart_path, "w") as f: | ||
|
|
@@ -79,10 +87,10 @@ def get_oci_registry(chart_info: HelmChartInfo) -> str: | |
| return oci_registry | ||
|
|
||
|
|
||
| def publish_helm_chart(chart_info: HelmChartInfo): | ||
| def publish_helm_chart(chart_info: HelmChartInfo, build_scenario): | ||
| try: | ||
| oci_registry = get_oci_registry(chart_info) | ||
| chart_name, chart_version = update_chart_and_get_metadata(CHART_DIR) | ||
| chart_name, chart_version = update_chart_and_get_metadata(CHART_DIR, build_scenario) | ||
| tgz_filename = f"{chart_name}-{chart_version}.tgz" | ||
|
|
||
| logger.info(f"Packaging chart: {chart_name} with Version: {chart_version}") | ||
|
|
@@ -108,7 +116,7 @@ def main(): | |
| build_scenario = args.build_scenario | ||
| build_info = load_build_info(build_scenario) | ||
|
|
||
| return publish_helm_chart(build_info.helm_charts["mongodb-kubernetes"]) | ||
| return publish_helm_chart(build_info.helm_charts["mongodb-kubernetes"], build_scenario) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.