diff --git a/.evergreen-functions.yml b/.evergreen-functions.yml index 0917c1de8..0a24c6e1c 100644 --- a/.evergreen-functions.yml +++ b/.evergreen-functions.yml @@ -525,6 +525,8 @@ functions: params: working_dir: src/github.com/mongodb/mongodb-kubernetes binary: scripts/release/kubectl_mongodb/download_kubectl_plugin.sh + env: + PLATFORM: ${platform} pipeline: - command: subprocess.exec diff --git a/.evergreen-snippets.yml b/.evergreen-snippets.yml index 2446d08b8..b41f82d64 100644 --- a/.evergreen-snippets.yml +++ b/.evergreen-snippets.yml @@ -7,7 +7,10 @@ variables: - func: setup_mongosh - func: download_kube_tools - func: switch_context + - func: python_venv - func: download_multi_cluster_binary + vars: + platform: linux/amd64 teardown_task: - func: upload_e2e_logs - func: upload_code_snippets_logs diff --git a/.evergreen.yml b/.evergreen.yml index 5989073a6..d247f3b3b 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -358,6 +358,8 @@ tasks: - func: clone - func: setup_building_host - func: download_multi_cluster_binary + vars: + platform: linux/amd64 - func: pipeline vars: image_name: meko-tests @@ -367,6 +369,8 @@ tasks: - func: clone - func: setup_building_host - func: download_multi_cluster_binary + vars: + platform: linux/arm64 - func: pipeline vars: image_name: meko-tests-arm64 @@ -379,6 +383,8 @@ tasks: skip_minikube_setup: true skip_install_python_requirements: false - func: download_multi_cluster_binary + vars: + platform: linux/s390x - func: pipeline vars: image_name: meko-tests-ibm-z @@ -391,6 +397,8 @@ tasks: skip_minikube_setup: true skip_install_python_requirements: false - func: download_multi_cluster_binary + vars: + platform: linux/ppc64le - func: pipeline vars: image_name: meko-tests-ibm-power diff --git a/scripts/release/kubectl_mongodb/download_kubectl_plugin.py b/scripts/release/kubectl_mongodb/download_kubectl_plugin.py index 8d78f5d07..53e5853a3 100755 --- a/scripts/release/kubectl_mongodb/download_kubectl_plugin.py +++ b/scripts/release/kubectl_mongodb/download_kubectl_plugin.py @@ -1,15 +1,17 @@ import argparse import os +import shutil from botocore.exceptions import ClientError from lib.base_logger import logger -from scripts.release.argparse_utils import get_platforms_from_arg, get_scenario_from_arg +from scripts.release.argparse_utils import get_scenario_from_arg from scripts.release.build.build_info import ( KUBECTL_PLUGIN_BINARY, load_build_info, ) from scripts.release.build.build_scenario import SUPPORTED_SCENARIOS, BuildScenario +from scripts.release.build.image_build_configuration import SUPPORTED_PLATFORMS from scripts.release.kubectl_mongodb.build_kubectl_plugin import ( kubectl_plugin_name, parse_platform, @@ -17,12 +19,16 @@ ) from scripts.release.kubectl_mongodb.utils import create_s3_client +KUBECTL_MONGODB_PLUGIN_BIN_PATH = "bin/kubectl-mongodb" + def local_tests_plugin_path(arch_name: str) -> str: return f"docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_{arch_name}" -def download_kubectl_plugin_from_s3(s3_bucket: str, s3_plugin_path: str, local_path: str): +def download_kubectl_plugin_from_s3( + s3_bucket: str, s3_plugin_path: str, local_path: str, copy_to_bin_path: bool = False +) -> None: """ Downloads the plugin for provided platform and puts it in the path expected by the tests image """ @@ -35,7 +41,12 @@ def download_kubectl_plugin_from_s3(s3_bucket: str, s3_plugin_path: str, local_p # change the file's permissions to make file executable os.chmod(local_path, 0o755) - logger.info(f"Successfully downloaded artifact to {local_path}") + if copy_to_bin_path: + shutil.copyfile(local_path, KUBECTL_MONGODB_PLUGIN_BIN_PATH) + + logger.info( + f"Successfully downloaded artifact to {local_path}{f" and {KUBECTL_MONGODB_PLUGIN_BIN_PATH}" if copy_to_bin_path else ""}" + ) except ClientError as e: if e.response["Error"]["Code"] == "404": raise Exception(f"Artifact not found at s3://{s3_bucket}/{s3_plugin_path}: {e}") @@ -74,28 +85,25 @@ def main(): "--platform", metavar="", action="store", + required=True, type=str, - help="Override the platforms instead of resolving from build scenario. Multi-arch builds are comma-separated. Example: linux/amd64,linux/arm64", + choices=SUPPORTED_PLATFORMS, + help=f"Specify kubectl-mongodb plugin platform to download. Options: {", ".join(SUPPORTED_PLATFORMS)}.", ) args = parser.parse_args() build_scenario = get_scenario_from_arg(args.build_scenario) build_info = load_build_info(build_scenario).binaries[KUBECTL_PLUGIN_BINARY] - platforms = get_platforms_from_arg(args.platform) or build_info.platforms + platform = args.platform version = args.version - for platform in platforms: - os_name, arch_name = parse_platform(platform) - if os_name != "linux": - logger.debug(f"Skipping non-linux platform {platform}, not used in e2e tests in Evergreen CI") - continue - - filename = kubectl_plugin_name(os_name, arch_name) - s3_plugin_path = s3_path(filename, version) - local_path = local_tests_plugin_path(arch_name) + os_name, arch_name = parse_platform(platform) + filename = kubectl_plugin_name(os_name, arch_name) + s3_plugin_path = s3_path(filename, version) + local_path = local_tests_plugin_path(arch_name) - download_kubectl_plugin_from_s3(build_info.s3_store, s3_plugin_path, local_path) + download_kubectl_plugin_from_s3(build_info.s3_store, s3_plugin_path, local_path, copy_to_bin_path=True) if __name__ == "__main__": diff --git a/scripts/release/kubectl_mongodb/download_kubectl_plugin.sh b/scripts/release/kubectl_mongodb/download_kubectl_plugin.sh index 2aaf5c5cb..546b2078c 100755 --- a/scripts/release/kubectl_mongodb/download_kubectl_plugin.sh +++ b/scripts/release/kubectl_mongodb/download_kubectl_plugin.sh @@ -4,4 +4,4 @@ set -Eeou pipefail source scripts/dev/set_env_context.sh -scripts/dev/run_python.sh scripts/release/kubectl_mongodb/download_kubectl_plugin.py --build-scenario "${BUILD_SCENARIO}" --version "${OPERATOR_VERSION}" +scripts/dev/run_python.sh scripts/release/kubectl_mongodb/download_kubectl_plugin.py --build-scenario "${BUILD_SCENARIO}" --version "${OPERATOR_VERSION}" --platform "${PLATFORM}"