Skip to content

KubernetesPodOperator sync event polling does not seed resource_version when the first event list is empty #66470

Closed

Description

@hkc-8010

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:

  1. Use the synchronous KPO path (deferrable=False) so PodManager.watch_pod_events is used from the worker.
  2. Have the first read_pod_events(...) call return:
    • items=[]
    • metadata.resource_version="100"
  3. Let the next loop iteration run.
  4. The next read_pod_events(...) call is still made with resource_version=None instead of resource_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

  1. added
    kind:bug
    priority:medium
    provider:cncf-kubernetes
    on May 6, 2026
  2. added a commit that references this issue on May 6, 2026
    da82928
  3. added a commit that references this issue on May 6, 2026
    7ca4c75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerskind:bugpriority:mediumprovider:cncf-kubernetes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions