Skip to content

Commit d6e72b2

Browse files
committed
fix: add missing patch for timeouts
1 parent 15996e5 commit d6e72b2

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

kubernetes_asyncio/client/rest.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ async def request(self, method, url, query_params=None, headers=None,
104104
:param _request_timeout: timeout setting for this request. If one
105105
number provided, it will be total request
106106
timeout. It can also be a pair (tuple) of
107-
(connection, read) timeouts.
107+
(connection, read) timeouts or object
108+
of aiohttp.ClientTimeout.
108109
"""
109110
method = method.upper()
110111
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT',
@@ -117,7 +118,18 @@ async def request(self, method, url, query_params=None, headers=None,
117118

118119
post_params = post_params or {}
119120
headers = headers or {}
120-
timeout = _request_timeout or 5 * 60
121+
timeout = aiohttp.ClientTimeout()
122+
if _request_timeout:
123+
if isinstance(_request_timeout, (int, float)):
124+
timeout = aiohttp.ClientTimeout(total=_request_timeout)
125+
elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
126+
timeout = aiohttp.ClientTimeout(
127+
connect=_request_timeout[0],
128+
sock_connect=_request_timeout[0],
129+
sock_read=_request_timeout[1],
130+
)
131+
elif isinstance(_request_timeout, aiohttp.ClientTimeout):
132+
timeout = _request_timeout
121133

122134
if 'Content-Type' not in headers:
123135
headers['Content-Type'] = 'application/json'

scripts/rest_client_timeout.diff

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--- /tmp/rest.py 2024-12-17 11:03:15.841466241 +0100
2+
+++ kubernetes_asyncio/client/rest.py 2024-12-17 11:03:22.851477070 +0100
3+
@@ -104,8 +104,7 @@
4+
:param _request_timeout: timeout setting for this request. If one
5+
number provided, it will be total request
6+
timeout. It can also be a pair (tuple) of
7+
- (connection, read) timeouts or object
8+
- of aiohttp.ClientTimeout.
9+
+ (connection, read) timeouts.
10+
"""
11+
method = method.upper()
12+
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT',
13+
@@ -118,18 +117,7 @@
14+
15+
post_params = post_params or {}
16+
headers = headers or {}
17+
- timeout = aiohttp.ClientTimeout()
18+
- if _request_timeout:
19+
- if isinstance(_request_timeout, (int, float)):
20+
- timeout = aiohttp.ClientTimeout(total=_request_timeout)
21+
- elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
22+
- timeout = aiohttp.ClientTimeout(
23+
- connect=_request_timeout[0],
24+
- sock_connect=_request_timeout[0],
25+
- sock_read=_request_timeout[1],
26+
- )
27+
- elif isinstance(_request_timeout, aiohttp.ClientTimeout):
28+
- timeout = _request_timeout
29+
+ timeout = _request_timeout or 5 * 60
30+
31+
if 'Content-Type' not in headers:
32+
headers['Content-Type'] = 'application/json'

scripts/update-client.sh

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ patch "${CLIENT_ROOT}/client/rest.py" "${SCRIPT_ROOT}/rest_client_patch_read_buf
7373
echo ">>> fix generated rest client and configuration to support customer server hostname TLS verification..."
7474
patch "${CLIENT_ROOT}/client/rest.py" "${SCRIPT_ROOT}/rest_client_server_hostname_patch.diff"
7575
patch "${CLIENT_ROOT}/client/configuration.py" "${SCRIPT_ROOT}/client_configuration_tls_server_name_patch.diff"
76+
echo ">>> fix generated rest client by handling timeout correctly..."
77+
patch -R "${CLIENT_ROOT}/client/rest.py" "${SCRIPT_ROOT}/rest_client_timeout.diff"
7678

7779
echo ">>> don't deep-copy configuration for local_vars_configuration in models"
7880
patch "${CLIENT_ROOT}/client/configuration.py" "${SCRIPT_ROOT}/client_configuration_get_default_patch.diff"

0 commit comments

Comments
 (0)