5858 GreenwaveConfig ,
5959 UpdateRequestPayload ,
6060)
61+ from iib .common .pydantic_models import AddPydanticModel , RmPydanticModel
6162
6263__all__ = ['handle_add_request' , 'handle_rm_request' ]
6364
@@ -826,24 +827,10 @@ def inspect_related_images(bundles: List[str], request_id) -> None:
826827@app .task
827828@request_logger
828829def handle_add_request (
829- bundles : List [ str ] ,
830+ payload : AddPydanticModel ,
830831 request_id : int ,
831- binary_image : Optional [str ] = None ,
832- from_index : Optional [str ] = None ,
833- add_arches : Optional [Set [str ]] = None ,
834- cnr_token : Optional [str ] = None ,
835- organization : Optional [str ] = None ,
836- force_backport : bool = False ,
837- overwrite_from_index : bool = False ,
838- overwrite_from_index_token : Optional [str ] = None ,
839- distribution_scope : Optional [str ] = None ,
840832 greenwave_config : Optional [GreenwaveConfig ] = None ,
841833 binary_image_config : Optional [Dict [str , Dict [str , str ]]] = None ,
842- deprecation_list : Optional [List [str ]] = None ,
843- build_tags : Optional [List [str ]] = None ,
844- graph_update_mode : Optional [str ] = None ,
845- check_related_images : bool = False ,
846- traceparent : Optional [str ] = None ,
847834) -> None :
848835 """
849836 Coordinate the the work needed to build the index image with the input bundles.
@@ -887,10 +874,10 @@ def handle_add_request(
887874 # Resolve bundles to their digests
888875 set_request_state (request_id , 'in_progress' , 'Resolving the bundles' )
889876
890- with set_registry_token (overwrite_from_index_token , from_index , append = True ):
891- resolved_bundles = get_resolved_bundles (bundles )
877+ with set_registry_token (payload . overwrite_from_index_token , payload . from_index , append = True ):
878+ resolved_bundles = get_resolved_bundles (payload . bundles )
892879 verify_labels (resolved_bundles )
893- if check_related_images :
880+ if payload . check_related_images :
894881 inspect_related_images (resolved_bundles , request_id )
895882
896883 # Check if Gating passes for all the bundles
@@ -902,23 +889,23 @@ def handle_add_request(
902889 prebuild_info = prepare_request_for_build (
903890 request_id ,
904891 RequestConfigAddRm (
905- _binary_image = binary_image ,
906- from_index = from_index ,
907- overwrite_from_index_token = overwrite_from_index_token ,
908- add_arches = add_arches ,
909- bundles = bundles ,
910- distribution_scope = distribution_scope ,
892+ _binary_image = payload . binary_image ,
893+ from_index = payload . from_index ,
894+ overwrite_from_index_token = payload . overwrite_from_index_token ,
895+ add_arches = payload . add_arches ,
896+ bundles = payload . bundles ,
897+ distribution_scope = payload . distribution_scope ,
911898 binary_image_config = binary_image_config ,
912899 ),
913900 )
914901 from_index_resolved = prebuild_info ['from_index_resolved' ]
915- with set_registry_token (overwrite_from_index_token , from_index_resolved ):
916- is_fbc = is_image_fbc (from_index_resolved ) if from_index else False
902+ with set_registry_token (payload . overwrite_from_index_token , from_index_resolved ):
903+ is_fbc = is_image_fbc (from_index_resolved ) if payload . from_index else False
917904 if is_fbc :
918905 # logging requested by stakeholders do not delete
919906 log .info ("Processing File-Based Catalog image" )
920907
921- if (cnr_token and organization ) or force_backport :
908+ if (payload . cnr_token and payload . organization ) or payload . force_backport :
922909 log .warning (
923910 "Legacy support is deprecated in IIB. "
924911 "cnr_token, organization and force_backport parameters will be ignored."
@@ -928,12 +915,12 @@ def handle_add_request(
928915 present_bundles : List [BundleImage ] = []
929916 present_bundles_pull_spec : List [str ] = []
930917 with tempfile .TemporaryDirectory (prefix = f'iib-{ request_id } -' ) as temp_dir :
931- if from_index :
918+ if payload . from_index :
932919 msg = 'Checking if bundles are already present in index image'
933920 log .info (msg )
934921 set_request_state (request_id , 'in_progress' , msg )
935922
936- with set_registry_token (overwrite_from_index_token , from_index_resolved , append = True ):
923+ with set_registry_token (payload . overwrite_from_index_token , from_index_resolved , append = True ):
937924 present_bundles , present_bundles_pull_spec = _get_present_bundles (
938925 from_index_resolved , temp_dir
939926 )
@@ -956,8 +943,8 @@ def handle_add_request(
956943 bundles = resolved_bundles ,
957944 binary_image = prebuild_info ['binary_image_resolved' ],
958945 from_index = from_index_resolved ,
959- graph_update_mode = graph_update_mode ,
960- overwrite_from_index_token = overwrite_from_index_token ,
946+ graph_update_mode = payload . graph_update_mode ,
947+ overwrite_from_index_token = payload . overwrite_from_index_token ,
961948 overwrite_csv = (prebuild_info ['distribution_scope' ] in ['dev' , 'stage' ]),
962949 )
963950 else :
@@ -966,8 +953,8 @@ def handle_add_request(
966953 bundles = resolved_bundles ,
967954 binary_image = prebuild_info ['binary_image_resolved' ],
968955 from_index = from_index_resolved ,
969- graph_update_mode = graph_update_mode ,
970- overwrite_from_index_token = overwrite_from_index_token ,
956+ graph_update_mode = payload . graph_update_mode ,
957+ overwrite_from_index_token = payload . overwrite_from_index_token ,
971958 overwrite_csv = (prebuild_info ['distribution_scope' ] in ['dev' , 'stage' ]),
972959 )
973960
@@ -979,7 +966,7 @@ def handle_add_request(
979966 add_max_ocp_version_property (resolved_bundles , temp_dir )
980967
981968 deprecation_bundles = get_bundles_from_deprecation_list (
982- present_bundles_pull_spec + resolved_bundles , deprecation_list or []
969+ present_bundles_pull_spec + resolved_bundles , payload . deprecation_list or []
983970 )
984971
985972 arches = prebuild_info ['arches' ]
@@ -1003,7 +990,7 @@ def handle_add_request(
1003990 )
1004991
1005992 with set_registry_token (
1006- overwrite_from_index_token , from_index_resolved , append = True
993+ payload . overwrite_from_index_token , from_index_resolved , append = True
1007994 ):
1008995 deprecate_bundles (
1009996 bundles = deprecation_bundles ,
@@ -1039,7 +1026,7 @@ def handle_add_request(
10391026 )
10401027 # get catalog with opted-in operators
10411028 os .makedirs (os .path .join (temp_dir , 'from_index' ), exist_ok = True )
1042- with set_registry_token (overwrite_from_index_token , from_index_resolved , append = True ):
1029+ with set_registry_token (payload . overwrite_from_index_token , from_index_resolved , append = True ):
10431030 catalog_from_index = get_catalog_dir (
10441031 from_index = from_index_resolved , base_dir = os .path .join (temp_dir , 'from_index' )
10451032 )
@@ -1092,15 +1079,15 @@ def handle_add_request(
10921079 )
10931080
10941081 set_request_state (request_id , 'in_progress' , 'Creating the manifest list' )
1095- output_pull_spec = _create_and_push_manifest_list (request_id , arches , build_tags )
1082+ output_pull_spec = _create_and_push_manifest_list (request_id , arches , payload . build_tags )
10961083
10971084 _update_index_image_pull_spec (
10981085 output_pull_spec ,
10991086 request_id ,
11001087 arches ,
1101- from_index ,
1102- overwrite_from_index ,
1103- overwrite_from_index_token ,
1088+ payload . from_index ,
1089+ payload . overwrite_from_index ,
1090+ payload . overwrite_from_index_token ,
11041091 from_index_resolved ,
11051092 add_or_rm = True ,
11061093 )
@@ -1113,16 +1100,9 @@ def handle_add_request(
11131100@app .task
11141101@request_logger
11151102def handle_rm_request (
1116- operators : List [ str ] ,
1103+ payload : RmPydanticModel ,
11171104 request_id : int ,
1118- from_index : str ,
1119- binary_image : Optional [str ] = None ,
1120- add_arches : Optional [Set [str ]] = None ,
1121- overwrite_from_index : bool = False ,
1122- overwrite_from_index_token : Optional [str ] = None ,
1123- distribution_scope : Optional [str ] = None ,
11241105 binary_image_config : Optional [Dict [str , Dict [str , str ]]] = None ,
1125- build_tags : Optional [List [str ]] = None ,
11261106) -> None :
11271107 """
11281108 Coordinate the work needed to remove the input operators and rebuild the index image.
@@ -1152,11 +1132,11 @@ def handle_rm_request(
11521132 prebuild_info = prepare_request_for_build (
11531133 request_id ,
11541134 RequestConfigAddRm (
1155- _binary_image = binary_image ,
1156- from_index = from_index ,
1157- overwrite_from_index_token = overwrite_from_index_token ,
1158- add_arches = add_arches ,
1159- distribution_scope = distribution_scope ,
1135+ _binary_image = payload . binary_image ,
1136+ from_index = payload . from_index ,
1137+ overwrite_from_index_token = payload . overwrite_from_index_token ,
1138+ add_arches = payload . add_arches ,
1139+ distribution_scope = payload . distribution_scope ,
11601140 binary_image_config = binary_image_config ,
11611141 ),
11621142 )
@@ -1165,17 +1145,17 @@ def handle_rm_request(
11651145 from_index_resolved = prebuild_info ['from_index_resolved' ]
11661146
11671147 with tempfile .TemporaryDirectory (prefix = f'iib-{ request_id } -' ) as temp_dir :
1168- with set_registry_token (overwrite_from_index_token , from_index_resolved , append = True ):
1148+ with set_registry_token (payload . overwrite_from_index_token , from_index_resolved , append = True ):
11691149 image_is_fbc = is_image_fbc (from_index_resolved )
11701150
11711151 if image_is_fbc :
11721152 log .info ("Processing File-Based Catalog image" )
11731153 fbc_dir , _ = opm_registry_rm_fbc (
11741154 base_dir = temp_dir ,
11751155 from_index = from_index_resolved ,
1176- operators = operators ,
1156+ operators = payload . operators ,
11771157 binary_image = prebuild_info ['binary_image' ],
1178- overwrite_from_index_token = overwrite_from_index_token ,
1158+ overwrite_from_index_token = payload . overwrite_from_index_token ,
11791159 generate_cache = False ,
11801160 )
11811161
@@ -1186,12 +1166,12 @@ def handle_rm_request(
11861166
11871167 os .makedirs (os .path .join (temp_dir , 'from_index' ), exist_ok = True )
11881168 # get catalog with opted-in operators
1189- with set_registry_token (overwrite_from_index_token , from_index_resolved , append = True ):
1169+ with set_registry_token (payload . overwrite_from_index_token , from_index_resolved , append = True ):
11901170 catalog_from_index = get_catalog_dir (
11911171 from_index = from_index_resolved , base_dir = os .path .join (temp_dir , 'from_index' )
11921172 )
11931173 # remove operators from from_index file-based catalog
1194- for operator in operators :
1174+ for operator in payload . operators :
11951175 operator_path = os .path .join (catalog_from_index , operator )
11961176 if os .path .exists (operator_path ):
11971177 log .debug ('Removing operator from from_index FBC %s' , operator_path )
@@ -1216,10 +1196,10 @@ def handle_rm_request(
12161196 else :
12171197 _opm_index_rm (
12181198 base_dir = temp_dir ,
1219- operators = operators ,
1199+ operators = payload . operators ,
12201200 binary_image = prebuild_info ['binary_image' ],
12211201 from_index = from_index_resolved ,
1222- overwrite_from_index_token = overwrite_from_index_token ,
1202+ overwrite_from_index_token = payload . overwrite_from_index_token ,
12231203 )
12241204
12251205 _add_label_to_index (
@@ -1242,15 +1222,15 @@ def handle_rm_request(
12421222 _push_image (request_id , arch )
12431223
12441224 set_request_state (request_id , 'in_progress' , 'Creating the manifest list' )
1245- output_pull_spec = _create_and_push_manifest_list (request_id , arches , build_tags )
1225+ output_pull_spec = _create_and_push_manifest_list (request_id , arches , payload . build_tags )
12461226
12471227 _update_index_image_pull_spec (
12481228 output_pull_spec ,
12491229 request_id ,
12501230 arches ,
1251- from_index ,
1252- overwrite_from_index ,
1253- overwrite_from_index_token ,
1231+ payload . from_index ,
1232+ payload . overwrite_from_index ,
1233+ payload . overwrite_from_index_token ,
12541234 from_index_resolved ,
12551235 add_or_rm = True ,
12561236 )
0 commit comments