11import argparse
22import os
3+ import shutil
34
45from botocore .exceptions import ClientError
56
67from lib .base_logger import logger
7- from scripts .release .argparse_utils import get_platforms_from_arg , get_scenario_from_arg
8+ from scripts .release .argparse_utils import get_scenario_from_arg
89from scripts .release .build .build_info import (
910 KUBECTL_PLUGIN_BINARY ,
1011 load_build_info ,
1112)
1213from scripts .release .build .build_scenario import SUPPORTED_SCENARIOS , BuildScenario
14+ from scripts .release .build .image_build_configuration import SUPPORTED_PLATFORMS
1315from scripts .release .kubectl_mongodb .build_kubectl_plugin import (
1416 kubectl_plugin_name ,
1517 parse_platform ,
1618 s3_path ,
1719)
1820from scripts .release .kubectl_mongodb .utils import create_s3_client
1921
22+ KUBECTL_MONGODB_PLUGIN_BIN_PATH = "bin/kubectl-mongodb"
23+
2024
2125def local_tests_plugin_path (arch_name : str ) -> str :
2226 return f"docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_{ arch_name } "
2327
2428
25- def download_kubectl_plugin_from_s3 (s3_bucket : str , s3_plugin_path : str , local_path : str ):
29+ def download_kubectl_plugin_from_s3 (
30+ s3_bucket : str , s3_plugin_path : str , local_path : str , copy_to_bin_path : bool = False
31+ ) -> None :
2632 """
2733 Downloads the plugin for provided platform and puts it in the path expected by the tests image
2834 """
@@ -35,7 +41,12 @@ def download_kubectl_plugin_from_s3(s3_bucket: str, s3_plugin_path: str, local_p
3541 # change the file's permissions to make file executable
3642 os .chmod (local_path , 0o755 )
3743
38- logger .info (f"Successfully downloaded artifact to { local_path } " )
44+ if copy_to_bin_path :
45+ shutil .copyfile (local_path , KUBECTL_MONGODB_PLUGIN_BIN_PATH )
46+
47+ logger .info (
48+ f"Successfully downloaded artifact to { local_path } { f" and { KUBECTL_MONGODB_PLUGIN_BIN_PATH } " if copy_to_bin_path else "" } "
49+ )
3950 except ClientError as e :
4051 if e .response ["Error" ]["Code" ] == "404" :
4152 raise Exception (f"Artifact not found at s3://{ s3_bucket } /{ s3_plugin_path } : { e } " )
@@ -74,28 +85,25 @@ def main():
7485 "--platform" ,
7586 metavar = "" ,
7687 action = "store" ,
88+ required = True ,
7789 type = str ,
78- help = "Override the platforms instead of resolving from build scenario. Multi-arch builds are comma-separated. Example: linux/amd64,linux/arm64" ,
90+ choices = SUPPORTED_PLATFORMS ,
91+ help = f"Specify kubectl-mongodb plugin platform to download. Options: { ", " .join (SUPPORTED_PLATFORMS )} ." ,
7992 )
8093 args = parser .parse_args ()
8194
8295 build_scenario = get_scenario_from_arg (args .build_scenario )
8396 build_info = load_build_info (build_scenario ).binaries [KUBECTL_PLUGIN_BINARY ]
8497
85- platforms = get_platforms_from_arg ( args .platform ) or build_info . platforms
98+ platform = args .platform
8699 version = args .version
87100
88- for platform in platforms :
89- os_name , arch_name = parse_platform (platform )
90- if os_name != "linux" :
91- logger .debug (f"Skipping non-linux platform { platform } , not used in e2e tests in Evergreen CI" )
92- continue
93-
94- filename = kubectl_plugin_name (os_name , arch_name )
95- s3_plugin_path = s3_path (filename , version )
96- local_path = local_tests_plugin_path (arch_name )
101+ os_name , arch_name = parse_platform (platform )
102+ filename = kubectl_plugin_name (os_name , arch_name )
103+ s3_plugin_path = s3_path (filename , version )
104+ local_path = local_tests_plugin_path (arch_name )
97105
98- download_kubectl_plugin_from_s3 (build_info .s3_store , s3_plugin_path , local_path )
106+ download_kubectl_plugin_from_s3 (build_info .s3_store , s3_plugin_path , local_path , copy_to_bin_path = True )
99107
100108
101109if __name__ == "__main__" :
0 commit comments