Skip to content

Watch only the step's own pod in the Kubernetes backend - #7600

Merged
xoxys merged 6 commits into
woodpecker-ci:mainfrom
ivaldibot:fix/k8s-pod-scoped-informers
Nov 25, 2026
Merged

xoxys merged 6 commits into
woodpecker-ci:mainfrom
ivaldibot:fix/k8s-pod-scoped-informers

Conversation

@ivaldibot

Copy link
Copy Markdown
Contributor

WaitStep and TailStep each create a pod informer to follow one pod, but the informer lists and watches every pod in the namespace. Each informer keeps its own cache, so the agent holds one copy of all the namespace's pods for every step it's waiting on or tailing. That includes large environment values of unrelated pods, like CI_SCRIPT and CI_PIPELINE_FILES. With many parallel steps, the agent's memory grows with steps × pods and can exceed its limit.

In a local replay on v3.19.0 that drove the real TailStep with 56 concurrent watchers over 61 pods, the informers retained 111 MiB of extra heap. With the field selector, it was 4.1 MiB.

This adds a metadata.name field selector through WithTweakListOptions, so the API server returns only the step's pod. The selector applies to the initial list, the watch, and streaming lists (sendInitialEvents). The event handlers already ignore every other pod, so behavior is unchanged.

May help with #4228.

Tests: TestStepInformersSelectOnlyTheirPod checks that the list and watch requests from both WaitStep and TailStep select only the step's pod. It fails without the change.

Note: TestAffinityFromCliContext fails on main when run with -count > 1. It's unrelated to this change, and passes in a normal single run.

ivaldibot and others added 4 commits November 19, 2026 16:38
WaitStep and TailStep each start a pod informer for one pod, but the
informer listed and watched every pod in the namespace. Each informer
keeps its own cache, so the agent's memory grew with the number of steps
waited on in parallel times the number of pods in the namespace,
including large environment values such as CI_SCRIPT of unrelated pods.

Select the step's pod with a metadata.name field selector, so the API
server sends only that pod to each informer. The handlers already
ignore every other pod, so behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.00%. Comparing base (a3fb353) to head (c6157a9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7600      +/-   ##
==========================================
+ Coverage   66.87%   67.00%   +0.13%     
==========================================
  Files         451      451              
  Lines       22646    22652       +6     
==========================================
+ Hits        15145    15179      +34     
+ Misses       7501     7473      -28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@6543 6543 added the enhancement improve existing features label Nov 20, 2026
@6543

6543 commented Nov 20, 2026

Copy link
Copy Markdown
Member

@xoxys this looks plausible but you know k8s better :)

@xoxys
xoxys merged commit 65d21e3 into woodpecker-ci:main Nov 25, 2026
9 checks passed
@woodpecker-bot woodpecker-bot mentioned this pull request Nov 25, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/kubernetes enhancement improve existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants