Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Watcher to use Bookmark events and restart watch from last observed event #94

Closed

Conversation

MichelCarroll
Copy link

@MichelCarroll MichelCarroll commented Oct 3, 2020

This PR is in response to #70 and #71.

I modified the k8s.watcher module to:

  • observe Bookmark events without forwarding them to the listener
  • restart the watch from the last observed event's resource version
  • remove the old cache logic, which is no longer required since we don't replay watch event history from the beginning
  • add the ability to start a watch from a particular resource version onwards (through the start_at_resource_version parameter)

Please let me know what you think.

@MichelCarroll MichelCarroll requested a review from a team as a code owner October 3, 2020 19:54
@gregjones
Copy link
Contributor

I think it looks good, thanks for the contribution. I did a bit of testing locally, and then some reading of the API docs, and it seems it's expected that clients handle a "410 Gone" status from the API when sending the resourceVersion constraint in a query, as the server doesn't guarantee to know about old events:

{"type":"ERROR","object":{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"too old resource version: 1312242788 (1474332294)","reason":"Gone","code":410}}

Catching that error and setting the last_seen_version back to None should work for this. I think it would be more friendly if the library took care of this, rather than leaving it up to clients

@mortenlj
Copy link
Member

/sem-approve

@mortenlj
Copy link
Member

☝️ Trying to get semaphore to build the PR...

Copy link
Member

@mortenlj mortenlj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing. I have a few comments, nothing major. I also think the comments from @gregjones makes sense. Probably a good thing if the build goes green. 🙂

PS. Out of curiosity, how did you hear about this library, and what are you using it for? 🙂

@@ -19,6 +19,7 @@

import json
import logging
from urllib.parse import urlencode, urlsplit, urlunsplit, parse_qs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still support Python 2.7, so this fails. You can use six.moves to solve it: https://six.readthedocs.io/index.html?highlight=moves#module-six.moves

@@ -73,11 +75,11 @@ def test_handle_changes(self, api_watch_list):
watcher._run_forever = False
assert list(gen) == []

def test_complicated(self, api_watch_list):
def test_many_reconnections(self, api_watch_list):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good rename, easier to understand what we are actually testing here. 👍

@@ -117,20 +118,38 @@ def list(cls, namespace="default"):
return [cls.from_dict(item) for item in resp.json()[u"items"]]

@classmethod
def watch_list(cls, namespace=None):
def _watch_url_from_base_resource_url(cls, base_resource_url, start_at_resource_version=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the client.get call goes to requests.request in the end, passing any keyword arguments it gets, I think this whole thing could be replaced by simply passing a suitable params dictionary to the client.get call.
That would be much easier to work with, and easier to read than this method.

@MichelCarroll
Copy link
Author

@gregjones Good point. I'll add handling for the "too old resource version" case.

@mortenlj Indeed, I'll look at Semaphore and make the adjustments you suggested.

I found your "hacktoberfest" tagged issues. I figured this was a good opportunity to learn more about the k8s API, as well as levelling up my Python skills.

@mortenlj
Copy link
Member

@MichelCarroll : Any movement on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants