Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .evergreen-functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,18 @@ functions:
GH_TOKEN: ${GH_TOKEN}
binary: scripts/dev/run_python.sh scripts/release/create_chart_release_pr.py --chart_version ${OPERATOR_VERSION|*triggered_by_git_tag}

add_releaseinfo_to_github_assets:
- command: github.generate_token
params:
expansion_name: GH_TOKEN
- command: subprocess.exec
type: setup
params:
working_dir: src/github.com/mongodb/mongodb-kubernetes
env:
GH_TOKEN: ${GH_TOKEN}
binary: scripts/dev/run_python.sh scripts/release/release_info.py --version 1.0.1

release_kubectl_mongodb_plugin:
- command: github.generate_token
params:
Expand Down
18 changes: 18 additions & 0 deletions .evergreen-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ tasks:
- func: install_macos_notarization_service
- func: release_kubectl_mongodb_plugin

- name: add_releaseinfo_to_github_assets
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we add this to the image release? Right now its only manually run, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes to both? So you will make a change in this PR to make it run automatically, right?

commands:
- func: clone
- func: python_venv
- func: add_releaseinfo_to_github_assets

- name: create_chart_release_pr
tags: [ "helm_chart_release_pr" ]
commands:
Expand Down Expand Up @@ -151,6 +157,18 @@ buildvariants:
- name: release_readiness_probe
- name: release_version_upgrade_hook

- name: add_releaseinfo_to_github_assets
display_name: add_releaseinfo_to_github_assets
tags: ["release"]
run_on:
- ubuntu2404-small
allowed_requesters: ["patch", "github_tag"]
# depends_on:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be uncommented, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

# - name: "*"
# variant: release_images
tasks:
- name: add_releaseinfo_to_github_assets

- name: preflight_release_images
display_name: preflight_release_images
tags: [ "release" ]
Expand Down
105 changes: 69 additions & 36 deletions scripts/release/release_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import json
import pathlib
import os

from scripts.release.build.build_info import (
DATABASE_IMAGE,
Expand All @@ -10,81 +10,114 @@
OPERATOR_IMAGE,
READINESS_PROBE_IMAGE,
UPGRADE_HOOK_IMAGE,
OPS_MANAGER_IMAGE,
AGENT_IMAGE,
BuildInfo,
load_build_info,
)
from scripts.release.kubectl_mongodb.promote_kubectl_plugin import upload_assets_to_github_release
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: upload_assets_to_github_release will not be relevant only to promote_kubectl_plugin so it should be placed somewhere else

from scripts.release.build.build_scenario import BuildScenario
from scripts.release.constants import (
DEFAULT_CHANGELOG_PATH,
DEFAULT_RELEASE_INITIAL_VERSION,
DEFAULT_REPOSITORY_PATH,
)

SEARCH_IMAGE = "search"
SEARCH_IMAGE_REPOSITORY = "quay.io/mongodb/mongodb-search"

RELEASE_INFO_IMAGES_ORDERED = [
OPERATOR_IMAGE,
INIT_DATABASE_IMAGE,
INIT_APPDB_IMAGE,
INIT_OPS_MANAGER_IMAGE,
DATABASE_IMAGE,
READINESS_PROBE_IMAGE,
UPGRADE_HOOK_IMAGE,
OPERATOR_IMAGE, # mongodb-kubernetes
INIT_DATABASE_IMAGE, # mongodb-kubernetes-init-database
INIT_APPDB_IMAGE, # mongodb-kubernetes-init-appdb
INIT_OPS_MANAGER_IMAGE, # mongodb-kubernetes-init-ops-manager
DATABASE_IMAGE, # mongodb-kubernetes-database
READINESS_PROBE_IMAGE, # mongodb-kubernetes-readinessprobe
UPGRADE_HOOK_IMAGE, # mongodb-kubernetes-operator-version-upgrade-post-start-hook
]

# TODO: this is dummy version, to be replaced with actual versioning logic https://docs.google.com/document/d/1eJ8iKsI0libbpcJakGjxcPfbrTn8lmcZDbQH1UqMR_g/edit?tab=t.45ig7xr3e3w4#bookmark=id.748ik8snxcyl
DUMMY_VERSION = "dummy_version"

EXTERNAL_INFO_IMAGES = [
OPS_MANAGER_IMAGE,
AGENT_IMAGE
]

def create_release_info_json() -> str:
def create_release_info_json(version: str) -> str:
build_info = load_build_info(scenario=BuildScenario.RELEASE)

release_info_json = convert_to_release_info_json(build_info)
release_info_json = convert_to_release_info_json(build_info, version)

return json.dumps(release_info_json, indent=2)


def convert_to_release_info_json(build_info: BuildInfo) -> dict:
output = {
def convert_to_release_info_json(build_info: BuildInfo, version: str) -> dict:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b: version can only be used by operator related images. READINESS_PROBE_IMAGE and UPGRADE_HOOK_IMAGE have their own versions in release.json.

nit: version -> operator_version

release_json_data = os.path.join(os.getcwd(), "release.json")
with open(release_json_data, "r") as fd:
release_data = json.load(fd)

release_info_output = {
"images": {},
"binaries": {},
"helm-charts": {},
}
# Filter (and order) images to include only those relevant for release info
images = {name: build_info.images[name] for name in RELEASE_INFO_IMAGES_ORDERED}
images = {name: build_info.images[name] for name in RELEASE_INFO_IMAGES_ORDERED + EXTERNAL_INFO_IMAGES}

for name, image in images.items():
output["images"][name] = {
release_info_output["images"][name] = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be simpler to just iterate over images = {name: build_info.images[name] for name in RELEASE_INFO_IMAGES_ORDERED

and then go manually with OPS_MANAGER_IMAGE and AGENT_IMAGE:

# add operator related images
images = {name: build_info.images[name] for name in RELEASE_INFO_IMAGES_ORDERED
for name, image in images.items():
  add_image(name, image.repositories, image.platforms, version)

# add Ops Manager image
om_image = build_info.images[OPS_MANAGER_IMAGE]
om_version = latest_om_version(release_data)
add_image(OPS_MANAGER_IMAGE, om_image.repositories, om_image.platforms, om_version)

# add Agent image
agent_image = build_info.images[AGENT_IMAGE]
agent_version = latest_agent_version(release_data)
add_image(AGENT_IMAGE, agent_image.repositories, agent_image.platforms, agent_version)

"repositories": image.repositories,
"platforms": image.platforms,
"version": DUMMY_VERSION,
}

if name == OPS_MANAGER_IMAGE:
release_info_output["images"][name]["version"] = latest_om_version(release_data)
continue

for name, binary in build_info.binaries.items():
output["binaries"][name] = {
"platforms": binary.platforms,
"version": DUMMY_VERSION,
}
if name == AGENT_IMAGE:
release_info_output["images"][name]["version"] = latest_agent_version(release_data)
continue

for name, chart in build_info.helm_charts.items():
output["helm-charts"][name] = {
"registry": chart.registry,
"repository": chart.repository,
"version": DUMMY_VERSION,
}
release_info_output["images"][name]["version"] = version

# add search image detail
release_info_output["images"][SEARCH_IMAGE] = {
"repositories": SEARCH_IMAGE_REPOSITORY,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather move this information to release.json and create a proper object under supportedImages, something like:

"supportedImages": {
  "mongodb-search": {
    "repository": "quay.io/mongodb/mongodb-search",
    "platforms": [
       "linux/arm64", 
       "linux/amd64"
    ],
    "version": "0.55.0"
  }
}

"platforms": ["linux/arm64", "linux/amd64"],
"version": latest_search_version(release_data)
}

release_info_output = add_om_agent_mappings(release_data, release_info_output)

return release_info_output

def add_om_agent_mappings(release_data, output):
om_agent_mapping = release_data["supportedImages"]["latestOpsManagerAgentMapping"]
output["latestOpsManagerAgentMapping"] = om_agent_mapping

return output

def latest_om_version(release_data):
return release_data["supportedImages"]["ops-manager"]["versions"][-1]

def latest_agent_version(release_data):
newest_om_version = release_data["supportedImages"]["ops-manager"]["versions"][-1]
newest_om_mapping = release_data["supportedImages"]["mongodb-agent"]["opsManagerMapping"]["ops_manager"][newest_om_version]
return newest_om_mapping["agent_version"]

def latest_search_version(release_data):
return release_data["search"]["version"]

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Create relevant release artifacts information in JSON format.",
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument("--version", help="released MCK version", required=True)
args = parser.parse_args()

release_info = create_release_info_json()
release_info_filename = f"release_info_{args.version}.json"

if args.output is not None:
with open(args.output, "w") as file:
release_info = create_release_info_json(args.version)

if release_info_filename is not None:
with open(release_info_filename, "w") as file:
file.write(release_info)
else:
print(release_info)

upload_assets_to_github_release([release_info_filename], args.version)