From da0f97193a054363377280da900490a1613457fa Mon Sep 17 00:00:00 2001 From: Vasyl Saienko Date: Wed, 30 Oct 2024 13:16:36 +0200 Subject: [PATCH] Retry requests on APIForbiddenError During k8s upgrade it may return APIForbiddenError, add this as valid exception for retry request. Signed-off-by: Vasyl Saienko --- kopf/_cogs/clients/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kopf/_cogs/clients/api.py b/kopf/_cogs/clients/api.py index 351f1213..5b8bf2c0 100644 --- a/kopf/_cogs/clients/api.py +++ b/kopf/_cogs/clients/api.py @@ -84,7 +84,8 @@ async def request( ) await errors.check_response(response) # but do not parse it! - except (aiohttp.ClientConnectionError, errors.APIServerError, asyncio.TimeoutError) as e: + # NOTE(vsaienko): during k8s upgrade API might throw 403 forbiden. Use retries for this exception as well. + except (aiohttp.ClientConnectionError, errors.APIServerError, asyncio.TimeoutError, errors.APIForbiddenError) as e: if backoff is None: # i.e. the last or the only attempt. logger.error(f"Request attempt {idx} failed; escalating: {what} -> {e!r}") raise