Skip to content

Commit

Permalink
fix: add missing patch for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
tomplus committed Dec 17, 2024
1 parent 15996e5 commit d6e72b2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
16 changes: 14 additions & 2 deletions kubernetes_asyncio/client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
Expand Down
32 changes: 32 additions & 0 deletions scripts/rest_client_timeout.diff
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 2 additions & 0 deletions scripts/update-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d6e72b2

Please sign in to comment.