58
58
GreenwaveConfig ,
59
59
UpdateRequestPayload ,
60
60
)
61
+ from iib .common .pydantic_models import AddPydanticModel , RmPydanticModel
61
62
62
63
__all__ = ['handle_add_request' , 'handle_rm_request' ]
63
64
@@ -826,24 +827,10 @@ def inspect_related_images(bundles: List[str], request_id) -> None:
826
827
@app .task
827
828
@request_logger
828
829
def handle_add_request (
829
- bundles : List [ str ] ,
830
+ payload : AddPydanticModel ,
830
831
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 ,
840
832
greenwave_config : Optional [GreenwaveConfig ] = None ,
841
833
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 ,
847
834
) -> None :
848
835
"""
849
836
Coordinate the the work needed to build the index image with the input bundles.
@@ -887,10 +874,10 @@ def handle_add_request(
887
874
# Resolve bundles to their digests
888
875
set_request_state (request_id , 'in_progress' , 'Resolving the bundles' )
889
876
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 )
892
879
verify_labels (resolved_bundles )
893
- if check_related_images :
880
+ if payload . check_related_images :
894
881
inspect_related_images (resolved_bundles , request_id )
895
882
896
883
# Check if Gating passes for all the bundles
@@ -902,23 +889,23 @@ def handle_add_request(
902
889
prebuild_info = prepare_request_for_build (
903
890
request_id ,
904
891
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 ,
911
898
binary_image_config = binary_image_config ,
912
899
),
913
900
)
914
901
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
917
904
if is_fbc :
918
905
# logging requested by stakeholders do not delete
919
906
log .info ("Processing File-Based Catalog image" )
920
907
921
- if (cnr_token and organization ) or force_backport :
908
+ if (payload . cnr_token and payload . organization ) or payload . force_backport :
922
909
log .warning (
923
910
"Legacy support is deprecated in IIB. "
924
911
"cnr_token, organization and force_backport parameters will be ignored."
@@ -928,12 +915,12 @@ def handle_add_request(
928
915
present_bundles : List [BundleImage ] = []
929
916
present_bundles_pull_spec : List [str ] = []
930
917
with tempfile .TemporaryDirectory (prefix = f'iib-{ request_id } -' ) as temp_dir :
931
- if from_index :
918
+ if payload . from_index :
932
919
msg = 'Checking if bundles are already present in index image'
933
920
log .info (msg )
934
921
set_request_state (request_id , 'in_progress' , msg )
935
922
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 ):
937
924
present_bundles , present_bundles_pull_spec = _get_present_bundles (
938
925
from_index_resolved , temp_dir
939
926
)
@@ -956,8 +943,8 @@ def handle_add_request(
956
943
bundles = resolved_bundles ,
957
944
binary_image = prebuild_info ['binary_image_resolved' ],
958
945
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 ,
961
948
overwrite_csv = (prebuild_info ['distribution_scope' ] in ['dev' , 'stage' ]),
962
949
)
963
950
else :
@@ -966,8 +953,8 @@ def handle_add_request(
966
953
bundles = resolved_bundles ,
967
954
binary_image = prebuild_info ['binary_image_resolved' ],
968
955
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 ,
971
958
overwrite_csv = (prebuild_info ['distribution_scope' ] in ['dev' , 'stage' ]),
972
959
)
973
960
@@ -979,7 +966,7 @@ def handle_add_request(
979
966
add_max_ocp_version_property (resolved_bundles , temp_dir )
980
967
981
968
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 []
983
970
)
984
971
985
972
arches = prebuild_info ['arches' ]
@@ -1003,7 +990,7 @@ def handle_add_request(
1003
990
)
1004
991
1005
992
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
1007
994
):
1008
995
deprecate_bundles (
1009
996
bundles = deprecation_bundles ,
@@ -1039,7 +1026,7 @@ def handle_add_request(
1039
1026
)
1040
1027
# get catalog with opted-in operators
1041
1028
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 ):
1043
1030
catalog_from_index = get_catalog_dir (
1044
1031
from_index = from_index_resolved , base_dir = os .path .join (temp_dir , 'from_index' )
1045
1032
)
@@ -1092,15 +1079,15 @@ def handle_add_request(
1092
1079
)
1093
1080
1094
1081
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 )
1096
1083
1097
1084
_update_index_image_pull_spec (
1098
1085
output_pull_spec ,
1099
1086
request_id ,
1100
1087
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 ,
1104
1091
from_index_resolved ,
1105
1092
add_or_rm = True ,
1106
1093
)
@@ -1113,16 +1100,9 @@ def handle_add_request(
1113
1100
@app .task
1114
1101
@request_logger
1115
1102
def handle_rm_request (
1116
- operators : List [ str ] ,
1103
+ payload : RmPydanticModel ,
1117
1104
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 ,
1124
1105
binary_image_config : Optional [Dict [str , Dict [str , str ]]] = None ,
1125
- build_tags : Optional [List [str ]] = None ,
1126
1106
) -> None :
1127
1107
"""
1128
1108
Coordinate the work needed to remove the input operators and rebuild the index image.
@@ -1152,11 +1132,11 @@ def handle_rm_request(
1152
1132
prebuild_info = prepare_request_for_build (
1153
1133
request_id ,
1154
1134
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 ,
1160
1140
binary_image_config = binary_image_config ,
1161
1141
),
1162
1142
)
@@ -1165,17 +1145,17 @@ def handle_rm_request(
1165
1145
from_index_resolved = prebuild_info ['from_index_resolved' ]
1166
1146
1167
1147
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 ):
1169
1149
image_is_fbc = is_image_fbc (from_index_resolved )
1170
1150
1171
1151
if image_is_fbc :
1172
1152
log .info ("Processing File-Based Catalog image" )
1173
1153
fbc_dir , _ = opm_registry_rm_fbc (
1174
1154
base_dir = temp_dir ,
1175
1155
from_index = from_index_resolved ,
1176
- operators = operators ,
1156
+ operators = payload . operators ,
1177
1157
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 ,
1179
1159
generate_cache = False ,
1180
1160
)
1181
1161
@@ -1186,12 +1166,12 @@ def handle_rm_request(
1186
1166
1187
1167
os .makedirs (os .path .join (temp_dir , 'from_index' ), exist_ok = True )
1188
1168
# 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 ):
1190
1170
catalog_from_index = get_catalog_dir (
1191
1171
from_index = from_index_resolved , base_dir = os .path .join (temp_dir , 'from_index' )
1192
1172
)
1193
1173
# remove operators from from_index file-based catalog
1194
- for operator in operators :
1174
+ for operator in payload . operators :
1195
1175
operator_path = os .path .join (catalog_from_index , operator )
1196
1176
if os .path .exists (operator_path ):
1197
1177
log .debug ('Removing operator from from_index FBC %s' , operator_path )
@@ -1216,10 +1196,10 @@ def handle_rm_request(
1216
1196
else :
1217
1197
_opm_index_rm (
1218
1198
base_dir = temp_dir ,
1219
- operators = operators ,
1199
+ operators = payload . operators ,
1220
1200
binary_image = prebuild_info ['binary_image' ],
1221
1201
from_index = from_index_resolved ,
1222
- overwrite_from_index_token = overwrite_from_index_token ,
1202
+ overwrite_from_index_token = payload . overwrite_from_index_token ,
1223
1203
)
1224
1204
1225
1205
_add_label_to_index (
@@ -1242,15 +1222,15 @@ def handle_rm_request(
1242
1222
_push_image (request_id , arch )
1243
1223
1244
1224
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 )
1246
1226
1247
1227
_update_index_image_pull_spec (
1248
1228
output_pull_spec ,
1249
1229
request_id ,
1250
1230
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 ,
1254
1234
from_index_resolved ,
1255
1235
add_or_rm = True ,
1256
1236
)
0 commit comments