Skip to content

Commit

Permalink
Merge pull request #81 from minrk/race-watch
Browse files Browse the repository at this point in the history
use resource_version to avoid missing events
  • Loading branch information
yuvipanda committed Oct 2, 2017
2 parents 5ffee41 + 38f4369 commit fdef0ef
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions kubespawner/reflector.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def _list_and_update(self):
)
# This is an atomic operation on the dictionary!
self.pods = {p.metadata.name: p for p in initial_pods.items}
# return the resource version so we can hook up a watch
return initial_pods.metadata.resource_version

def _watch_and_update(self):
"""
Expand Down Expand Up @@ -92,13 +94,14 @@ def _watch_and_update(self):
cur_delay = 0.1
while True:
self.log.info("watching for pods with label selector %s in namespace %s", self.label_selector, self.namespace)
w = watch.Watch()
try:
self._list_and_update()
w = watch.Watch()
resource_version = self._list_and_update()
for ev in w.stream(
self.api.list_namespaced_pod,
self.namespace,
label_selector=self.label_selector
label_selector=self.label_selector,
resource_version=resource_version,
):
cur_delay = 0.1
pod = ev['object']
Expand Down

0 comments on commit fdef0ef

Please sign in to comment.