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

Watch bookmarks don't work for job resources (deserialization error) #1404

Closed
mikepii opened this issue Mar 30, 2021 · 1 comment · Fixed by kubernetes-client/python-base#234
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@mikepii
Copy link

mikepii commented Mar 30, 2021

What happened (please include outputs or screenshots):

Iterating the return value of Watch().stream() raises an exception when a bookmark event is received. It successfully iterates events prior to the bookmark being received.

Stack trace:

(iterator = Watch().stream(..., allow_watch_bookmarks=True))

File ". . .", line 43, in . . .
  value = next(iterator)
File "/usr/local/lib/python3.8/site-packages/kubernetes/watch/watch.py", line 163, in stream
  event = self.unmarshal_event(line, return_type)
File "/usr/local/lib/python3.8/site-packages/kubernetes/watch/watch.py", line 101, in unmarshal_event
  js['object'] = self._api_client.deserialize(obj, return_type)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 264, in deserialize
  return self.__deserialize(data, response_type)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 303, in __deserialize
  return self.__deserialize_model(data, klass)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 639, in __deserialize_model
  kwargs[attr] = self.__deserialize(value, attr_type)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 303, in __deserialize
  return self.__deserialize_model(data, klass)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 639, in __deserialize_model
  kwargs[attr] = self.__deserialize(value, attr_type)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 303, in __deserialize
  return self.__deserialize_model(data, klass)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 639, in __deserialize_model
  kwargs[attr] = self.__deserialize(value, attr_type)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 303, in __deserialize
  return self.__deserialize_model(data, klass)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 641, in __deserialize_model
  instance = klass(**kwargs)
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/models/v1_pod_spec.py", line 157, in __init__
  self.containers = containers
File "/usr/local/lib/python3.8/site-packages/kubernetes/client/models/v1_pod_spec.py", line 307, in containers
  raise ValueError("Invalid value for `containers`, must not be `None`")  # noqa: E501

What you expected to happen:

The iterator should yield an event like {'type': 'BOOKMARK'} and the Watch instance should note the updated resource version internally.

How to reproduce it (as minimally and precisely as possible):

  1. Start an iterator on a Watch:
    from kubernetes.client import BatchV1Api
    from kubernetes.watch import Watch
    for event in Watch().stream(BatchV1Api().list_namespaced_job, namespace='default', allow_watch_bookmarks=True):
        print('received', event['type'])
  2. Wait for a bookmark event to come through. I've been able to get a bookmark event fairly reliably by creating and deleting a job resource.

Anything else we need to know?:

Here's the data argument passed to Watch.unmarshal_event() (via debugger):

{"type":"BOOKMARK","object":{"kind":"Job","apiVersion":"batch/v1","metadata":{"resourceVersion":"45398385","creationTimestamp":null},"spec":{"template":{"metadata":{"creationTimestamp":null},"spec":{"containers":null}}},"status":{}}}

#1136 has a similar title but it's a different bug which I haven't observed (Watch() does work for me until a bookmark event comes through).

It seems likely that this affects other types of resources, but I've only tried it with jobs.

Environment:

  • Kubernetes version (kubectl version): Server Version: version.Info{Major:"1", Minor:"18+", GitVersion:"v1.18.9-eks-d1db3c", GitCommit:"d1db3c46e55f95d6a7d3e5578689371318f95ff9", GitTreeState:"clean", BuildDate:"2020-10-20T22:18:07Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
  • OS (e.g., MacOS 10.13.6): Linux 4.14
  • Python version (python --version): Python 3.8.8
  • Python client version (pip list | grep kubernetes): kubernetes==12.0.1
@mikepii mikepii added the kind/bug Categorizes issue or PR as related to a bug. label Mar 30, 2021
@roycaihw
Copy link
Member

/assign @yliaog

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

Successfully merging a pull request may close this issue.

3 participants