Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

resource version reset default when event object resource version inv… #199

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions watch/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def unmarshal_event(self, data, return_type):
and 'resourceVersion' in js['object']['metadata']):
self.resource_version = js['object']['metadata'][
'resourceVersion']
if self.resource_version is None:
# In some case like 'too old resource version',
# the event type would be ERROR, resource version will be None
self.resource_version = 0
Copy link
Member

Choose a reason for hiding this comment

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

Watching with resourceVersion=0 doesn't guarantee the client to continue watching from the last seen state, and therefore may cause missing watch events. The right way to handle a 410 Gone response is to perform a LIST request, and start the watch from the resourceVersion returned by that new list operation (see https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes for more details).

This is part of the problems kubernetes-client/python#868 was trying to address

Copy link
Author

@DrAuYueng DrAuYueng Jun 24, 2020

Choose a reason for hiding this comment

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

If catch event type of Error and continue like #133 ,will cause endless loop, current resourceVersion never change, always get Error of message:"too old resource version"

Copy link
Author

Choose a reason for hiding this comment

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

If catch event type of Error and continue like #133 ,will cause endless loop, current resourceVersion never change, always get Error of message:"too old resource version"

Make resourceVersion=0 make sure the watch stream still work even if the wrong init resource version set

Copy link
Member

Choose a reason for hiding this comment

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

will cause endless loop, current resourceVersion never change, always get Error of message:"too old resource version"

I don't think that's what we want and it should not happen

perform a LIST request, and start the watch from the resourceVersion returned by that new list operation

the resourceVersion returned by a LIST request will be the latest resourceVersion, it won't be stale

return js

def stream(self, func, *args, **kwargs):
Expand Down