Skip to content

fix: preserve PipelineRun-owned TaskRuns during history pruning - #424

Open
yuzichen12123 wants to merge 2 commits into
tektoncd:mainfrom
yuzichen12123:fix/exclude-pipelinerun-owned-taskruns
Open

yuzichen12123 wants to merge 2 commits into
tektoncd:mainfrom
yuzichen12123:fix/exclude-pipelinerun-owned-taskruns

Conversation

@yuzichen12123

Copy link
Copy Markdown

Summary

History-limit cleanup can delete completed TaskRuns that belong to a still-running PipelineRun. The PipelineRun controller then treats those tasks as unscheduled and recreates them, causing completed pipeline work to run again.

This change excludes PipelineRun-owned resources from the history-limiter candidate set. It recognizes both ownership signals used by Tekton:

  • the tekton.dev/pipelineRun label;
  • a PipelineRun ownerReference.

The ownerReference check protects resources that do not carry the label.

Fixes #381

Testing

  • go test ./...

The regression test verifies that history pruning removes eligible standalone resources while preserving PipelineRun children identified by either ownership mechanism.

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.56%. Comparing base (717a04d) to head (d664de5).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #424      +/-   ##
==========================================
+ Coverage   50.40%   50.56%   +0.16%     
==========================================
  Files          19       19              
  Lines        2113     2120       +7     
==========================================
+ Hits         1065     1072       +7     
  Misses        916      916              
  Partials      132      132              
Flag Coverage Δ
unit-tests 50.56% <ø> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@infernus01 infernus01 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an LGTM from my side

Comment thread pkg/config/history_limiter.go Outdated

// isPipelineRunOwned reports whether a resource belongs to a PipelineRun and
// therefore must be reclaimed with its parent instead of by history limiting.
func isPipelineRunOwned(resource metav1.Object) bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @yuzichen12123!

One nit: Could we have used this fucntion instead of creating another one with similar logic ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. isStandaloneTaskRun is defined in pkg/reconciler/taskrun, while the history limiter is implemented in pkg/config. The taskrun package already imports config, so having config call back into taskrun would create an import cycle.

The existing helper is also unexported and TaskRun-specific, whereas the history limiter is shared by TaskRuns and PipelineRuns. The current implementation therefore keeps the ownership check in pkg/config while preserving the same label and ownerReference logic. We can extract a shared helper into a common package in a follow-up refactor if needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah lets put shared function in pkg/config/helper.go, that's a small change I believe and keeps the ownership logic in one place. Thoughts on just including it here vs follow-up? either way works, but since we're already touching this area, so we can do it in this PR itself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @infernus01, agreed. I've included this refactor in the PR in c4dac9f.

The ownership check now lives in pkg/config/helper.go as IsPipelineRunOwned, shared by the history limiter and the standalone TaskRun check. isStandaloneTaskRun delegates to the shared helper, keeping both the label and ownerReference checks in one place without introducing an import cycle.

I've added table-driven coverage for the ownership signals, empty labels, and unrelated or mixed ownerReferences, and kept the original history-pruning regression test. make test-unit (including the race detector), go vet ./..., and lint checks pass locally. The new PR CI is queued.

@infernus01 infernus01 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 29, 2026
Centralize label and ownerReference detection in config.IsPipelineRunOwned
so history limiting and standalone TaskRun checks use the same logic.

Cover both ownership signals, empty labels, and unrelated or mixed owners.

Signed-off-by: Zichen Yu <1062955096@qq.com>
Assisted-by: GPT-6 (via Codex)
@tekton-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from vdemeester after the PR has been reviewed.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

History-limit pruning deletes TaskRuns owned by a still-running PipelineRun, causing the pipeline task to re-run

4 participants