Skip to content

Watch handles resourceVersion wrong #1018

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

Closed
epa095 opened this issue Nov 25, 2019 · 5 comments
Closed

Watch handles resourceVersion wrong #1018

epa095 opened this issue Nov 25, 2019 · 5 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@epa095
Copy link

epa095 commented Nov 25, 2019

Warning: I might have misunderstood something. Feel free to correct.

As described several places (e.g. kubernetes-client/python-base#131 (comment)
#819) one can not just use a ẁatch on a "list-functon", but one has to first do a list, get the resourceVersion from the list-call itself, and then use that in the watch.

The problem is that watch itself reapplies the provided function in an infinite loop, and if func is e.g. list_namespace (as in the example in the readme), then the correct course of action is to get the resourceVersion of that call and use it. But instead only the resourceVersions of the elements in the list is used.

@epa095 epa095 added the kind/bug Categorizes issue or PR as related to a bug. label Nov 25, 2019
@roycaihw
Copy link
Member

/assign

@roycaihw
Copy link
Member

I think we do extract the latest resource version from the apiserver response and use that: https://github.com/kubernetes-client/python-base/blob/a2d1024524de78b62e5f9aa72d34cb9ea9de2b97/watch/watch.py#L96

/close

@k8s-ci-robot
Copy link
Contributor

@roycaihw: Closing this issue.

In response to this:

I think we do extract the latest resource version from the apiserver response and use that: https://github.com/kubernetes-client/python-base/blob/a2d1024524de78b62e5f9aa72d34cb9ea9de2b97/watch/watch.py#L96

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@epa095
Copy link
Author

epa095 commented Nov 26, 2019

I think we do extract the latest resource version from the apiserver response and use that: https://github.com/kubernetes-client/python-base/blob/a2d1024524de78b62e5f9aa72d34cb9ea9de2b97/watch/watch.py#L96

/close

@roycaihw

But that is the resource version for each of the elements in the list, not of the list itself. The resource_version exists in the response of func (at least if func is any of the functions client.list_*_object). So something like

resp = func(*args, **kwargs)
resp.get("metadata", {}).get("resourceVersion", None)

But maybe the semantics is different because watch is set to True , and then K8s does not return a (interesting) resource_version on the list itself?

@roycaihw
Copy link
Member

The semantics is different. The apiserver responds to watch requests with a stream of watch events. See https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes:

GET /api/v1/namespaces/test/pods?watch=1&resourceVersion=10245
---
200 OK
Transfer-Encoding: chunked
Content-Type: application/json
{
  "type": "ADDED",
  "object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "10596", ...}, ...}
}
{
  "type": "MODIFIED",
  "object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "11020", ...}, ...}
}
...

The python client extracts the resource version from each of the watch event. If you print the line, you will see something like:

https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants