Skip to content

Commit fc95388

Browse files
add documentation for the server & client side timeout
Signed-off-by: Priyanka Saggu <[email protected]>
1 parent 44b2325 commit fc95388

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

Diff for: examples/pod_namespace_watch.py renamed to examples/watch/pod_namespace_watch.py

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
The script will wait for 10 events related to namespaces to occur within
1818
the `timeout_seconds` threshold and then move on to wait for another 10 events
1919
related to pods to occur within the `timeout_seconds` threshold.
20+
21+
22+
Refer to the document below to understand the server-side & client-side
23+
timeout settings for the watch request handler: ~
24+
25+
https://github.com/github.com/kubernetes-client/python/blob/master/examples/watch/timeout-settings.md
2026
"""
2127

2228
from kubernetes import client, config, watch

Diff for: examples/watch/timeout-settings.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
**This documentation briefly provides information about the `server side` & `client side` connection timeout settings, in the watch request handler.**
3+
4+
---
5+
6+
There are two inputs available in the client, that could be used to set connection timeouts:
7+
8+
- `timeout_seconds`
9+
- `_request_timeout`
10+
11+
---
12+
13+
#### Sever-side timeout (`kwargs['timeout_seconds'] = n`)
14+
15+
- The value of the argument `timeout_seconds`, **n**, (which is time duration in seconds) is consumed at the server side. It is included in the request URL to the server.
16+
17+
*For eg.* ~ `https://localhost:6443/api/v1/namespaces/default/pods?labelSelector=app%3Ddemo&timeoutSeconds=100&watch=True`
18+
19+
- In case, if the `timeout_seconds` value is set, the value `n` would determine the server-side connection timeout duration.
20+
21+
*For eg.* ~ if `kwargs['timeout_seconds'] = 3600`, then the server-side connection timeout will be equal to 1 hour.
22+
23+
This timeout duration is determined by the expression ~ `timeout = time.Duration(3600) * time.seconds`, *i.e.* `timeout = 1 hour`
24+
25+
***Refer:***
26+
- *[https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L254](https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L254)*
27+
28+
- In case, if the `timeout_seconds` value is not set, then the connection timeout will be a randomized value (in seconds) between `minRequestTimeout` and 2*`minRequestTimeout`, to spread out the load.
29+
30+
It is determined using the expression ~ `timeout = time.Duration(float64(minRequestTimeout) * (rand.Float64() + 1.0))`
31+
32+
Where `minRequestTimeout` indicates the minimum number of seconds a handler must keep a request open before timing it out.
33+
34+
The default value of `minRequestTimeout` is 1800 seconds.
35+
36+
***Refer:***
37+
- *[https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L257](https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L257)*
38+
- *[https://github.com/kubernetes/kubernetes/blob/release-1.20/staging/src/k8s.io/apiserver/pkg/server/config.go#L320](https://github.com/kubernetes/kubernetes/blob/release-1.20/staging/src/k8s.io/apiserver/pkg/server/config.go#L320)*
39+
40+
- In case of a network outage, this timeout value will have no effect & the client will hang indefinitely without raising any exception.
41+
42+
- It is recommended to set this timeout value to a higher number such as 3600 seconds (1 hour).
43+
44+
---
45+
46+
#### Client-side timeout (`kwargs['_request_timeout'] = n`)
47+
48+
- The value of the argument `_request_timeout`, **n** (which is time duration in seconds) is set to the socket used for the connection.
49+
50+
- In case, if the `_request_timeout` value is set, this argument can accept 2 types of input values ~
51+
- float,
52+
- a tuple (with a length of 2)
53+
54+
***Refer***
55+
- *[https://github.com/kubernetes-client/python/blob/v17.17.0/kubernetes/client/api_client.py#L336-L339](https://github.com/kubernetes-client/python/blob/v17.17.0/kubernetes/client/api_client.py#L336-L339)*
56+
57+
If it is tuple input type i.e. a pair of values like (connection, read), then the first value will be ignored.
58+
59+
- In case of network outage, leading to dropping all packets with no RST/FIN, the timeout value (in seconds) determined by the `request_timeout` argument, would be the time duration for how long the client will wait before realizing & dropping the connection.
60+
61+
- When the timeout happens, an exception will be raised, for eg. ~
62+
63+
`urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='localhost', port=6443): Read timed out.`
64+
65+
- In case, if the `_request_timeout` value is not set, then the default value is **`None`** & socket will have no timeout.
66+
67+
***Refer:***
68+
- *[https://docs.python.org/3/library/socket.html#socket.getdefaulttimeout](https://docs.python.org/3/library/socket.html#socket.getdefaulttimeout)*
69+
70+
- It is recommended to set this timeout value to a lower number (for eg. ~ maybe 60 seconds).
71+

0 commit comments

Comments
 (0)