diff --git a/kubernetes_asyncio/client/rest.py b/kubernetes_asyncio/client/rest.py index 8914d586..eca41107 100644 --- a/kubernetes_asyncio/client/rest.py +++ b/kubernetes_asyncio/client/rest.py @@ -104,7 +104,8 @@ async def request(self, method, url, query_params=None, headers=None, :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of - (connection, read) timeouts. + (connection, read) timeouts or object + of aiohttp.ClientTimeout. """ method = method.upper() assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', @@ -117,7 +118,18 @@ async def request(self, method, url, query_params=None, headers=None, post_params = post_params or {} headers = headers or {} - timeout = _request_timeout or 5 * 60 + timeout = aiohttp.ClientTimeout() + if _request_timeout: + if isinstance(_request_timeout, (int, float)): + timeout = aiohttp.ClientTimeout(total=_request_timeout) + elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2: + timeout = aiohttp.ClientTimeout( + connect=_request_timeout[0], + sock_connect=_request_timeout[0], + sock_read=_request_timeout[1], + ) + elif isinstance(_request_timeout, aiohttp.ClientTimeout): + timeout = _request_timeout if 'Content-Type' not in headers: headers['Content-Type'] = 'application/json' diff --git a/scripts/rest_client_timeout.diff b/scripts/rest_client_timeout.diff new file mode 100644 index 00000000..95d53070 --- /dev/null +++ b/scripts/rest_client_timeout.diff @@ -0,0 +1,32 @@ +--- /tmp/rest.py 2024-12-17 11:03:15.841466241 +0100 ++++ kubernetes_asyncio/client/rest.py 2024-12-17 11:03:22.851477070 +0100 +@@ -104,8 +104,7 @@ + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of +- (connection, read) timeouts or object +- of aiohttp.ClientTimeout. ++ (connection, read) timeouts. + """ + method = method.upper() + assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', +@@ -118,18 +117,7 @@ + + post_params = post_params or {} + headers = headers or {} +- timeout = aiohttp.ClientTimeout() +- if _request_timeout: +- if isinstance(_request_timeout, (int, float)): +- timeout = aiohttp.ClientTimeout(total=_request_timeout) +- elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2: +- timeout = aiohttp.ClientTimeout( +- connect=_request_timeout[0], +- sock_connect=_request_timeout[0], +- sock_read=_request_timeout[1], +- ) +- elif isinstance(_request_timeout, aiohttp.ClientTimeout): +- timeout = _request_timeout ++ timeout = _request_timeout or 5 * 60 + + if 'Content-Type' not in headers: + headers['Content-Type'] = 'application/json' diff --git a/scripts/update-client.sh b/scripts/update-client.sh index c2d0ea75..a9e68d48 100755 --- a/scripts/update-client.sh +++ b/scripts/update-client.sh @@ -73,6 +73,8 @@ patch "${CLIENT_ROOT}/client/rest.py" "${SCRIPT_ROOT}/rest_client_patch_read_buf echo ">>> fix generated rest client and configuration to support customer server hostname TLS verification..." patch "${CLIENT_ROOT}/client/rest.py" "${SCRIPT_ROOT}/rest_client_server_hostname_patch.diff" patch "${CLIENT_ROOT}/client/configuration.py" "${SCRIPT_ROOT}/client_configuration_tls_server_name_patch.diff" +echo ">>> fix generated rest client by handling timeout correctly..." +patch -R "${CLIENT_ROOT}/client/rest.py" "${SCRIPT_ROOT}/rest_client_timeout.diff" echo ">>> don't deep-copy configuration for local_vars_configuration in models" patch "${CLIENT_ROOT}/client/configuration.py" "${SCRIPT_ROOT}/client_configuration_get_default_patch.diff"