Skip to content

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

@mikepii

Description

@mikepii

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

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions