Skip to content

kubernetes: filter event poller fetch by field_selector#6728

Open
geojaz wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
onix-net:geojaz/k8s-event-field-selector
Open

kubernetes: filter event poller fetch by field_selector#6728
geojaz wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
onix-net:geojaz/k8s-event-field-selector

Conversation

@geojaz
Copy link
Copy Markdown
Collaborator

@geojaz geojaz commented Jun 3, 2026

What

Add an optional field_selector to the Kubernetes event poller (GetEvents) so callers can have the API server filter events server-side, and use it on the node-change watcher so it polls only Node events.

Why

Some benchmarks generate a tremendous volume of Kubernetes events, and collecting them after a run can take several minutes. The node-change tracker is only interested in Node events, but it was fetching and parsing the entire event stream on every poll. Scoping that fetch to involvedObject.kind=Node returns just the events that path consumes and recovers almost all of that collection time.

The new field_selector parameter defaults to None (no filtering), so it does not change behavior for callers that do not set it. The behavior that does change is the node-change watcher, which now polls only Node events instead of the full stream.

Changes

  • kubernetes_commands.py, kubernetes_cluster.py, kubernetes_events.py: add an optional field_selector to GetEvents. When unset (the default), the request is unchanged and no --field-selector flag is added.
  • kubernetes_tracker.py: the node-change watcher now passes field_selector="involvedObject.kind=Node", so it polls only Node events.
  • kubernetes_tracker_test.py: coverage for the filtered fetch.

Threads a field_selector through KubernetesCluster, KubernetesEventPoller, and kubernetes_commands so the tracker fetches only node events (involvedObject.kind=Node). On runs with >100k events the unfiltered fetch plus yaml.safe_load took minutes; this brings it under a second.
@geojaz geojaz force-pushed the geojaz/k8s-event-field-selector branch from bf5d58b to 29d0c93 Compare June 5, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant