Repository navigation
Description
Under which category would you file this issue?
Providers
Apache Airflow version
Observed on Apache Airflow 2.11.0. The bug is also present on main in the synchronous PodManager.watch_pod_events code path prior to the attached fix.
What happened and how to reproduce it?
The synchronous KubernetesPodOperator event polling path can keep issuing unversioned list_namespaced_event calls when the first event poll returns an empty list.
The current sync implementation in PodManager.watch_pod_events updates resource_version only from individual event items. If the first response is an empty V1EventList, but the list metadata already contains a valid resource_version, that value is discarded and the next poll still uses resource_version=None.
That means worker-side startup polling can repeatedly do full event LISTs until at least one event item is returned.
Minimal reproduction:
- Use the synchronous KPO path (
deferrable=False) soPodManager.watch_pod_eventsis used from the worker. - Have the first
read_pod_events(...)call return:items=[]metadata.resource_version="100"
- Let the next loop iteration run.
- The next
read_pod_events(...)call is still made withresource_version=Noneinstead ofresource_version="100".
A minimal test looks like this:
mock_events_1.items = []
mock_events_1.metadata.resource_version = "100"
mock_events_2.items = [mock_event_2]
mock_events_2.metadata.resource_version = "101"
self.mock_kube_client.list_namespaced_event.side_effect = [mock_events_1, mock_events_2]
await self.pod_manager.watch_pod_events(mock_pod, check_interval=1)
calls = self.mock_kube_client.list_namespaced_event.call_args_list
assert calls[0][1]["resource_version"] is None
assert calls[1][1]["resource_version"] == "100"I verified locally that the current code on main does not preserve the list-level resource_version in this case.
Why this matters:
- the expensive calls come from workers in the sync KPO path
- the API server keeps receiving unversioned event LISTs during pod startup
- this can create avoidable load when many synchronous KPO tasks start at once
This appears to be a separate gap from the recent K8s event-watch optimizations: provider 10.14.0 still has this sync empty-first-response case even after #59080 and #60532.
What you think should happen instead?
The synchronous event polling loop should seed resource_version from events.metadata.resource_version immediately after each list response, even when events.items is empty.
That would allow the next poll to use the existing optimized path with:
resource_version=<last seen list resource version>resource_version_match="NotOlderThan"
instead of falling back to repeated unversioned LIST requests.
Operating System
Any
Deployment
Astronomer
Apache Airflow Provider(s)
cncf-kubernetes
Versions of Apache Airflow Providers
Observed on apache-airflow-providers-cncf-kubernetes==10.14.0.
The behavior appears to affect the sync event polling implementation introduced in provider 10.10.0+, where this code path started relying on event list resource versions.
Official Helm Chart version
Not Applicable
Kubernetes Version
Not Applicable
Activity
fix(providers-cncf-kubernetes): preserve event resource version after…
fix(providers-cncf-kubernetes): preserve event resource version after…