@@ -219,10 +219,6 @@ async def registry_request(
219219 return response , response_headers
220220
221221
222- async def _is_registry_responsive (app : FastAPI ) -> None :
223- await _basic_auth_registry_request (app , path = "" , method = "HEAD" , timeout = 1.0 )
224-
225-
226222async def _setup_registry (app : FastAPI ) -> None :
227223 @retry (
228224 wait = wait_fixed (1 ),
@@ -231,15 +227,15 @@ async def _setup_registry(app: FastAPI) -> None:
231227 reraise = True ,
232228 )
233229 async def _wait_until_registry_responsive (app : FastAPI ) -> None :
234- await _is_registry_responsive (app )
230+ await _basic_auth_registry_request (app , path = "" , method = "HEAD" , timeout = 1.0 )
235231
236232 with log_context (_logger , logging .INFO , msg = "Connecting to docker registry" ):
237233 await _wait_until_registry_responsive (app )
238234
239235
240- async def _list_all_services_task (app : FastAPI ) -> None :
241- with log_context (_logger , logging .INFO , msg = "Listing all services" ):
242- await list_services (app , ServiceType .ALL )
236+ async def _list_all_services_task (* , app : FastAPI ) -> None :
237+ with log_context (_logger , logging .INFO , msg = "Updating cache with services" ):
238+ await list_services (app , ServiceType .ALL , update_cache = True )
243239
244240
245241def setup (app : FastAPI ) -> None :
@@ -251,10 +247,11 @@ async def on_startup() -> None:
251247 app_settings = get_application_settings (app )
252248 app .state .auto_cache_task = None
253249 if app_settings .DIRECTOR_REGISTRY_CACHING :
254- app .state .auto_cache_task = await start_periodic_task (
250+ app .state .auto_cache_task = start_periodic_task (
255251 _list_all_services_task ,
256252 interval = app_settings .DIRECTOR_REGISTRY_CACHING_TTL / 2 ,
257253 task_name = "director-auto-cache-task" ,
254+ app = app ,
258255 )
259256
260257 async def on_shutdown () -> None :
@@ -280,12 +277,12 @@ def _get_prefix(service_type: ServiceType) -> str:
280277
281278
282279async def _list_repositories_gen (
283- app : FastAPI , service_type : ServiceType
280+ app : FastAPI , service_type : ServiceType , * , update_cache : bool
284281) -> AsyncGenerator [list [str ], None ]:
285282 with log_context (_logger , logging .DEBUG , msg = "listing repositories" ):
286283 path = f"_catalog?n={ get_application_settings (app ).DIRECTOR_REGISTRY_CLIENT_MAX_NUMBER_OF_RETRIEVED_OBJECTS } "
287284 result , headers = await registry_request (
288- app , path = path , method = "GET" , use_cache = True
285+ app , path = path , method = "GET" , use_cache = not update_cache
289286 ) # initial call
290287
291288 while True :
@@ -294,7 +291,9 @@ async def _list_repositories_gen(
294291 str (headers ["Link" ]).split (";" )[0 ].strip ("<>" ).removeprefix ("/v2/" )
295292 )
296293 prefetch_task = asyncio .create_task (
297- registry_request (app , path = next_path , method = "GET" , use_cache = True )
294+ registry_request (
295+ app , path = next_path , method = "GET" , use_cache = not update_cache
296+ )
298297 )
299298 else :
300299 prefetch_task = None
@@ -312,20 +311,22 @@ async def _list_repositories_gen(
312311
313312
314313async def list_image_tags_gen (
315- app : FastAPI , image_key : str
314+ app : FastAPI , image_key : str , * , update_cache = False
316315) -> AsyncGenerator [list [str ], None ]:
317316 with log_context (_logger , logging .DEBUG , msg = f"listing image tags in { image_key } " ):
318317 path = f"{ image_key } /tags/list?n={ get_application_settings (app ).DIRECTOR_REGISTRY_CLIENT_MAX_NUMBER_OF_RETRIEVED_OBJECTS } "
319318 tags , headers = await registry_request (
320- app , path = path , method = "GET" , use_cache = True
319+ app , path = path , method = "GET" , use_cache = not update_cache
321320 ) # initial call
322321 while True :
323322 if "Link" in headers :
324323 next_path = (
325324 str (headers ["Link" ]).split (";" )[0 ].strip ("<>" ).removeprefix ("/v2/" )
326325 )
327326 prefetch_task = asyncio .create_task (
328- registry_request (app , path = next_path , method = "GET" , use_cache = True )
327+ registry_request (
328+ app , path = next_path , method = "GET" , use_cache = not update_cache
329+ )
329330 )
330331 else :
331332 prefetch_task = None
@@ -367,14 +368,14 @@ async def get_image_digest(app: FastAPI, image: str, tag: str) -> str | None:
367368
368369
369370async def get_image_labels (
370- app : FastAPI , image : str , tag : str
371+ app : FastAPI , image : str , tag : str , * , update_cache = False
371372) -> tuple [dict [str , str ], str | None ]:
372373 """Returns image labels and the image manifest digest"""
373374
374375 _logger .debug ("getting image labels of %s:%s" , image , tag )
375376 path = f"{ image } /manifests/{ tag } "
376377 request_result , headers = await registry_request (
377- app , path = path , method = "GET" , use_cache = True
378+ app , path = path , method = "GET" , use_cache = not update_cache
378379 )
379380 v1_compatibility_key = json .loads (request_result ["history" ][0 ]["v1Compatibility" ])
380381 container_config : dict [str , Any ] = v1_compatibility_key .get (
@@ -391,10 +392,12 @@ async def get_image_labels(
391392
392393
393394async def get_image_details (
394- app : FastAPI , image_key : str , image_tag : str
395+ app : FastAPI , image_key : str , image_tag : str , * , update_cache = False
395396) -> dict [str , Any ]:
396397 image_details : dict = {}
397- labels , image_manifest_digest = await get_image_labels (app , image_key , image_tag )
398+ labels , image_manifest_digest = await get_image_labels (
399+ app , image_key , image_tag , update_cache = update_cache
400+ )
398401
399402 if image_manifest_digest :
400403 # Adds manifest as extra key in the response similar to org.opencontainers.image.base.digest
@@ -422,11 +425,18 @@ async def get_image_details(
422425 return image_details
423426
424427
425- async def get_repo_details (app : FastAPI , image_key : str ) -> list [dict [str , Any ]]:
428+ async def get_repo_details (
429+ app : FastAPI , image_key : str , * , update_cache = False
430+ ) -> list [dict [str , Any ]]:
426431 repo_details = []
427- async for image_tags in list_image_tags_gen (app , image_key ):
432+ async for image_tags in list_image_tags_gen (
433+ app , image_key , update_cache = update_cache
434+ ):
428435 async for image_details_future in limited_as_completed (
429- (get_image_details (app , image_key , tag ) for tag in image_tags ),
436+ (
437+ get_image_details (app , image_key , tag , update_cache = update_cache )
438+ for tag in image_tags
439+ ),
430440 limit = get_application_settings (
431441 app
432442 ).DIRECTOR_REGISTRY_CLIENT_MAX_CONCURRENT_CALLS ,
@@ -437,16 +447,23 @@ async def get_repo_details(app: FastAPI, image_key: str) -> list[dict[str, Any]]
437447 return repo_details
438448
439449
440- async def list_services (app : FastAPI , service_type : ServiceType ) -> list [dict ]:
450+ async def list_services (
451+ app : FastAPI , service_type : ServiceType , * , update_cache = False
452+ ) -> list [dict ]:
441453 with log_context (_logger , logging .DEBUG , msg = "listing services" ):
442454 services = []
443455 concurrency_limit = get_application_settings (
444456 app
445457 ).DIRECTOR_REGISTRY_CLIENT_MAX_CONCURRENT_CALLS
446- async for repos in _list_repositories_gen (app , service_type ):
458+ async for repos in _list_repositories_gen (
459+ app , service_type , update_cache = update_cache
460+ ):
447461 # only list as service if it actually contains the necessary labels
448462 async for repo_details_future in limited_as_completed (
449- (get_repo_details (app , repo ) for repo in repos ),
463+ (
464+ get_repo_details (app , repo , update_cache = update_cache )
465+ for repo in repos
466+ ),
450467 limit = concurrency_limit ,
451468 ):
452469 with log_catch (_logger , reraise = False ):
0 commit comments