integ/python/python-kubernetes/centos/patches/0011-Fix-Watch-retries-with...

47 lines
1.8 KiB
Diff

From ebea7e343046d7afbbdc0e199294d5c79ae87362 Mon Sep 17 00:00:00 2001
From: Chris Ayoub <chris.ayoubtexas@gmail.com>
Date: Thu, 25 Feb 2021 00:27:33 -0500
Subject: [PATCH 11/13] Fix Watch retries with 410 errors
---
watch/watch.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/watch/watch.py b/watch/watch.py
index 3058ed9..b432778 100644
--- a/watch/watch.py
+++ b/watch/watch.py
@@ -151,7 +151,9 @@ class Watch(object):
if 'resource_version' in kwargs:
self.resource_version = kwargs['resource_version']
- timeouts = ('timeout_seconds' in kwargs)
+ # Do not attempt retries if user specifies a timeout.
+ # We want to ensure we are returning within that timeout.
+ disable_retries = ('timeout_seconds' in kwargs)
retry_after_410 = False
while True:
resp = func(*args, **kwargs)
@@ -164,9 +166,9 @@ class Watch(object):
if isinstance(event, dict) \
and event['type'] == 'ERROR':
obj = event['raw_object']
- # Current request expired, let's retry,
+ # Current request expired, let's retry, (if enabled)
# but only if we have not already retried.
- if not retry_after_410 and \
+ if not disable_retries and not retry_after_410 and \
obj['code'] == HTTP_STATUS_GONE:
retry_after_410 = True
break
@@ -190,5 +192,5 @@ class Watch(object):
else:
self._stop = True
- if timeouts or self._stop:
+ if self._stop or disable_retries:
break
--
2.25.1