From 1aa3ea99ca3251492ae06e15089a806fd06dc909 Mon Sep 17 00:00:00 2001 From: Sergey Vasilyev Date: Thu, 11 Jul 2019 21:04:29 +0200 Subject: [PATCH 1/2] Switch back to no-timeouts by default for Kopf's internal requests --- kopf/clients/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kopf/clients/auth.py b/kopf/clients/auth.py index aab51483..aad9e640 100644 --- a/kopf/clients/auth.py +++ b/kopf/clients/auth.py @@ -134,5 +134,5 @@ def get_pykube_cfg() -> pykube.KubeConfig: # TODO: add some caching, but keep kwargs in mind. Maybe add a key= for purpose/use-place? def get_pykube_api(timeout=None) -> pykube.HTTPClient: - kwargs = dict(timeout=timeout) if timeout is not None else dict() + kwargs = dict(timeout=timeout) return pykube.HTTPClient(get_pykube_cfg(), **kwargs) From a72dbad4ffbe8d3501481c22f32cf503372d8047 Mon Sep 17 00:00:00 2001 From: Sergey Vasilyev Date: Thu, 11 Jul 2019 21:05:33 +0200 Subject: [PATCH 2/2] Use server-side timeouts for watching, disable socket timeouts --- kopf/clients/fetching.py | 9 +++++++-- setup.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/kopf/clients/fetching.py b/kopf/clients/fetching.py index 57b6b313..7d2fb697 100644 --- a/kopf/clients/fetching.py +++ b/kopf/clients/fetching.py @@ -74,9 +74,14 @@ def watch_objs(*, resource, namespace=None, timeout=None, since=None): * The resource is namespace-scoped AND operator is namespaced-restricted. """ - api = auth.get_pykube_api(timeout=timeout) + + params = {} + if timeout is not None: + params['timeoutSeconds'] = timeout + + api = auth.get_pykube_api(timeout=None) cls = classes._make_cls(resource=resource) namespace = namespace if issubclass(cls, pykube.objects.NamespacedAPIObject) else None lst = cls.objects(api, namespace=pykube.all if namespace is None else namespace) - src = lst.watch(since=since) + src = lst.watch(since=since, params=params) return iter({'type': event.type, 'object': event.object.obj} for event in src) diff --git a/setup.py b/setup.py index 8aac822c..51cf1775 100644 --- a/setup.py +++ b/setup.py @@ -43,6 +43,6 @@ 'click', 'iso8601', 'aiojobs', - 'pykube-ng>=0.25', + 'pykube-ng>=0.27', ], )