4141 process_fragment_imports ,
4242 process_mounts ,
4343 process_mounts_from_config ,
44- readable_diff ,
45- find_value_in_params_and_vars )
46- from azext_confcom .lib .images import get_image_platform
44+ readable_diff )
45+ from azext_confcom .lib .images import get_image_platform # pylint: disable=unused-import
4746from azext_confcom .lib .defaults import get_debug_mode_exec_procs
4847from knack .log import get_logger
4948from tqdm import tqdm
@@ -281,7 +280,7 @@ def validate_sidecars(self) -> Tuple[bool, Dict]:
281280 if len (policy_ids ) == 0 :
282281 eprint ("No sidecar images found in the policy." )
283282
284- policy = load_policy_from_image_name (policy_ids )
283+ policy = load_policy_from_image_name (policy_ids , platform = self . _platform or "linux/amd64" )
285284
286285 policy .populate_policy_content_for_all_images (individual_image = True )
287286 policy_str = self .get_serialized_output (
@@ -678,6 +677,7 @@ def load_policy_from_arm_template_str(
678677 rego_imports : Any = None ,
679678 fragment_contents : Any = None ,
680679 exclude_default_fragments : bool = False ,
680+ platform : str = "linux/amd64" ,
681681) -> List [AciPolicy ]:
682682 """Function that converts ARM template string to an ACI Policy"""
683683 input_arm_json = os_util .load_json_from_str (template_data )
@@ -737,6 +737,18 @@ def load_policy_from_arm_template_str(
737737 container_group_properties = case_insensitive_dict_get (
738738 resource , config .ACI_FIELD_TEMPLATE_PROPERTIES
739739 )
740+
741+ # Validate that osType in the ARM template matches the specified platform
742+ os_type = case_insensitive_dict_get (container_group_properties , "osType" )
743+ if os_type :
744+ expected_os = "linux" if platform .startswith ("linux" ) else "windows"
745+ if os_type .lower () != expected_os :
746+ eprint (
747+ f'ARM template osType "{ os_type } " does not match '
748+ f'the supplied platform "{ platform } ". '
749+ f'Please use --platform to specify a consistent platform.'
750+ )
751+
740752 container_list = case_insensitive_dict_get (
741753 container_group_properties , config .ACI_FIELD_TEMPLATE_CONTAINERS
742754 )
@@ -818,16 +830,6 @@ def load_policy_from_arm_template_str(
818830 extract_probe (exec_processes , image_properties , config .ACI_FIELD_CONTAINERS_READINESS_PROBE )
819831 extract_probe (exec_processes , image_properties , config .ACI_FIELD_CONTAINERS_LIVENESS_PROBE )
820832
821- # Use platform from template if specified, otherwise try to auto-detect from image
822- platform = case_insensitive_dict_get (image_properties , "platform" )
823- if not platform :
824- # By this point, we have not substituted any parameters or
825- # variables yet, but in order to get the image we have to know
826- # the final image name. So resolve it here temporarily (later
827- # on, the constructor of AciPolicy will resolve it again)
828- image_name_with_param_substituted = find_value_in_params_and_vars (all_params , all_vars , image_name )
829- platform = get_image_platform (image_name_with_param_substituted )
830-
831833 containers .append (
832834 {
833835 config .ACI_FIELD_CONTAINERS_ID : image_name ,
@@ -882,6 +884,7 @@ def load_policy_from_arm_template_file(
882884 rego_imports : list = None ,
883885 fragment_contents : list = None ,
884886 exclude_default_fragments : bool = False ,
887+ platform : str = "linux/amd64" ,
885888) -> List [AciPolicy ]:
886889 """Utility function: generate policy object from given arm template and parameter file paths"""
887890 input_arm_json = os_util .load_str_from_file (template_path )
@@ -899,11 +902,13 @@ def load_policy_from_arm_template_file(
899902 diff_mode = diff_mode ,
900903 fragment_contents = fragment_contents ,
901904 exclude_default_fragments = exclude_default_fragments ,
905+ platform = platform ,
902906 )
903907
904908
905909def load_policy_from_image_name (
906- image_names : Union [List [str ], str ], debug_mode : bool = False , disable_stdio : bool = False
910+ image_names : Union [List [str ], str ], debug_mode : bool = False , disable_stdio : bool = False ,
911+ platform : str = "linux/amd64" ,
907912) -> AciPolicy :
908913 # can either take a list of image names or a single image name
909914 if isinstance (image_names , str ):
@@ -925,7 +930,7 @@ def load_policy_from_image_name(
925930 container [config .ACI_FIELD_CONTAINERS_CONTAINERIMAGE ] = image_name
926931 container [config .ACI_FIELD_CONTAINERS_ALLOW_STDIO_ACCESS ] = not disable_stdio
927932
928- container ["platform" ] = get_image_platform ( image_name )
933+ container ["platform" ] = platform
929934
930935 containers .append (container )
931936
@@ -945,14 +950,16 @@ def load_policy_from_json_file(
945950 disable_stdio : bool = False ,
946951 infrastructure_svn : str = None ,
947952 exclude_default_fragments : bool = False ,
953+ platform : str = "linux/amd64" ,
948954) -> AciPolicy :
949955 json_content = os_util .load_str_from_file (data )
950956 return load_policy_from_json (
951957 json_content ,
952958 debug_mode = debug_mode ,
953959 disable_stdio = disable_stdio ,
954960 infrastructure_svn = infrastructure_svn ,
955- exclude_default_fragments = exclude_default_fragments
961+ exclude_default_fragments = exclude_default_fragments ,
962+ platform = platform ,
956963 )
957964
958965
@@ -962,6 +969,7 @@ def load_policy_from_json(
962969 disable_stdio : bool = False ,
963970 infrastructure_svn : str = None ,
964971 exclude_default_fragments : bool = False ,
972+ platform : str = "linux/amd64" ,
965973) -> AciPolicy :
966974 output_containers = []
967975 # 1) Parse incoming string as JSON
@@ -1070,8 +1078,6 @@ def load_policy_from_json(
10701078
10711079 envs += process_env_vars_from_config (container_properties )
10721080
1073- platform = get_image_platform (image_name )
1074-
10751081 output_containers .append (
10761082 {
10771083 config .ACI_FIELD_CONTAINERS_ID : image_name ,
@@ -1129,6 +1135,7 @@ def load_policy_from_virtual_node_yaml_file(
11291135 exclude_default_fragments : bool = False ,
11301136 fragment_contents : list = None ,
11311137 infrastructure_svn : str = None ,
1138+ platform : str = "linux/amd64" ,
11321139) -> List [AciPolicy ]:
11331140 yaml_contents_str = os_util .load_str_from_file (virtual_node_yaml_path )
11341141 return load_policy_from_virtual_node_yaml_str (
@@ -1141,6 +1148,7 @@ def load_policy_from_virtual_node_yaml_file(
11411148 exclude_default_fragments = exclude_default_fragments ,
11421149 fragment_contents = fragment_contents ,
11431150 infrastructure_svn = infrastructure_svn ,
1151+ platform = platform ,
11441152 )
11451153
11461154
@@ -1155,6 +1163,7 @@ def load_policy_from_virtual_node_yaml_str(
11551163 exclude_default_fragments : bool = False ,
11561164 fragment_contents : Any = None ,
11571165 infrastructure_svn : str = None ,
1166+ platform : str = "linux/amd64" ,
11581167) -> List [AciPolicy ]:
11591168 """
11601169 Load a virtual node yaml file and generate a policy object
@@ -1343,8 +1352,6 @@ def load_policy_from_virtual_node_yaml_str(
13431352 extract_lifecycle_hook (exec_processes , container , config .VIRTUAL_NODE_YAML_LIFECYCLE_POST_START )
13441353 extract_lifecycle_hook (exec_processes , container , config .VIRTUAL_NODE_YAML_LIFECYCLE_PRE_STOP )
13451354
1346- platform = get_image_platform (image )
1347-
13481355 policy_containers .append (
13491356 {
13501357 config .ACI_FIELD_CONTAINERS_ID : image ,
0 commit comments