kubernetes_asyncio icon indicating copy to clipboard operation
kubernetes_asyncio copied to clipboard

Reconnect watcher if Kubernetes sends an empty response

Open JacobHenner opened this issue 4 years ago • 0 comments

In watch.py, next() is set to stop iteration if the k8s server provides an empty response (i.e. when the server timeout expires). I believe this is undesirable.

https://github.com/tomplus/kubernetes_asyncio/blob/91b2c41eedd282d9ebc059377fb7f207e220133d/kubernetes_asyncio/watch/watch.py#L145-L150

Instead, the logic should be similar to the logic in the previous except block, which handles asyncio.TimeoutError:

https://github.com/tomplus/kubernetes_asyncio/blob/91b2c41eedd282d9ebc059377fb7f207e220133d/kubernetes_asyncio/watch/watch.py#L136-L141

From the perspective of kubernetes_asyncio, it should not matter if the client or if the server has timed out; the watcher should attempt to reconnect unless the user-specified timeout (timeout_seconds) has elapsed.

I believe this is how the standard Python client handles it:

https://github.com/kubernetes-client/python-base/blob/d30f1e6fd4e2725aae04fa2f4982a4cfec7c682b/watch/watch.py#L141-L157

When iter_resp_lines(resp) returns a value which evaluates to False (e.g. the k8s api returns an empty response), iteration stops. Unless _stop has been set to True, the client will attempt to reconnect.

JacobHenner avatar Feb 29 '20 20:02 JacobHenner