Steps to reproduce:
"""Watch multiple K8s event streams without threads."""
import asyncio
from kubernetes_asyncio import client, config, watch
from wrapt import partial
async def watch_pods():
last_version: str | None = None
while True:
async with client.ApiClient() as api:
v1 = client.CoreV1Api(api)
w = watch.Watch()
# w._api_client.configuration.client_side_validation = False
async for event in w.stream(
v1.list_pod_for_all_namespaces,
allow_watch_bookmarks=True,
resource_version=last_version,
):
last_version = w.resource_version
print(f"Event: {event['type']} {event['object'].metadata.name}")
async def main():
# Load the kubeconfig file specified in the KUBECONFIG environment
# variable, or fall back to `~/.kube/config`.
await config.load_kube_config()
# Define the tasks to watch namespaces and pods.
tasks = [
asyncio.ensure_future(watch_pods()),
]
# Push tasks into event loop.
await asyncio.wait(tasks)
if __name__ == "__main__":
asyncio.run(main())
Actual behavior:
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<watch_pods() done, defined at /Users/a_kaltovich/projects/odysseos/sample.py:9> exception=TypeError("'V1Pod' object is not subscriptable")>
Traceback (most recent call last):
File "/Users/a_kaltovich/projects/odysseos/sample.py", line 16, in watch_pods
async for event in w.stream(
...<5 lines>...
print(f"Event: {event['type']} {event['object'].metadata.name}")
File "/Users/a_kaltovich/projects/odysseos/.venv/lib/python3.14/site-packages/kubernetes_asyncio/watch/watch.py", line 135, in __anext__
return await self.next()
^^^^^^^^^^^^^^^^^
File "/Users/a_kaltovich/projects/odysseos/.venv/lib/python3.14/site-packages/kubernetes_asyncio/watch/watch.py", line 191, in next
return self.unmarshal_event(line, self.return_type)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a_kaltovich/projects/odysseos/.venv/lib/python3.14/site-packages/kubernetes_asyncio/watch/watch.py", line 126, in unmarshal_event
self.resource_version = js['object']['metadata']['resourceVersion']
~~~~~~~~~~~~^^^^^^^^^^^^
TypeError: 'V1Pod' object is not subscriptable
Expected:
No error
Steps to reproduce:
Actual behavior:
Expected:
No error