Description
Description of the problem
In the code that watches for events, all events with a type are parsed before bookmarks are handled. This behaves poorly with bookmarks, because bookmarks contain nulled-out objects for the type that they watch. (For exact examples see associate MR #364). For example, a job will have an empty pod spec with no containers. Because we try to parse the object before handling bookmarks, this triggers parsing errors. This is a regression, as prior versions of kubernetes-asyncio
used to handle bookmarks differently. The synchronous client gets around this problem by just not handling bookmarks.
Reproduction script
import asyncio
import kubernetes_asyncio as k8s
async def bookmark_bug() -> None:
await k8s.config.load_kube_config()
async with k8s.client.ApiClient() as api:
watcher = k8s.watch.Watch()
batch_v1 = k8s.client.BatchV1Api(api)
async for event in watcher.stream(
batch_v1.list_namespaced_job,
namespace="<your_namespace_here>",
allow_watch_bookmarks=True,
):
print(event["type"])
asyncio.run(bookmark_bug())
Expected behaviour
(This was tested with kubernetes-asyncio==28.2.1
and works)
$ python bookmark_bug.py
ADDED
BOOKMARK
...
Actual behaviour
(This was tested with kubernetes-asyncio==31.1.1
and fails)
$ python bookmark_bug.py
ADDED
Traceback (most recent call last):
File "<snip>/bookmark_bug.py", line 19, in <module>
asyncio.run(bookmark_bug())
<snip>
File "<snip>/site-packages/kubernetes_asyncio/client/models/v1_pod_spec.py", line 335, in containers
raise ValueError("Invalid value for `containers`, must not be `None`") # noqa: E501
ValueError: Invalid value for `containers`, must not be `None`
Environment
Python 3.12.6
Kubernetes: 1.31
Expected behaviour: kubernetes-asyncio==28.2.1
Actual behaviour:
kubernetes-asyncio==31.1.1
kubernetes-asyncio==32.3.2