[main] fix(pipeline-augment): scope PipelineRun match to Pipeline namespace#1178
Conversation
augmentRunsToData() matched PipelineRuns to Pipelines by the tekton.dev/pipeline label only, ignoring namespace. In the "All Projects" list view this caused every same-named Pipeline across namespaces to show the same "Last run", even when the PipelineRun only existed in one namespace. Fixes openshift-pipelines#1168
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: anwesha-palit-redhat, openshift-cherrypick-robot The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Code Review by Qodo
1. Name-only PLR dedupe
|
| const prsForPipeline = pipelineruns.filter( | ||
| (pr) => | ||
| pr.metadata.namespace === pipeline.metadata.namespace && | ||
| pr.metadata.labels?.['tekton.dev/pipeline'] === pipeline.metadata.name, |
There was a problem hiding this comment.
1. Name-only plr dedupe 🐞 Bug ≡ Correctness
After this PR, augmentRunsToData only matches PipelineRuns within the same namespace, but the PipelineRuns list feeding it is deduped by metadata.name only. In all-namespaces (or merged) lists where two namespaces contain PipelineRuns with the same name, one can be dropped and the corresponding Pipeline will incorrectly get no latestRun.
Agent Prompt
### Issue description
`augmentRunsToData` now correctly requires `PipelineRun.metadata.namespace` to match `Pipeline.metadata.namespace`, but the PipelineRun list coming from `useRuns` is deduped with `uniqBy(..., r => r.metadata.name)`. Because names are only unique *within* a namespace, this can drop legitimate PipelineRuns from other namespaces; with the new namespace scoping, the affected pipelines will end up with `latestRun = null` even though a run exists.
### Issue Context
Data flow:
- `PipelinesList` passes `pipelineRuns` from `useGetPipelineRuns(namespace)` into `augmentRunsToData`.
- `useGetPipelineRuns` uses `usePipelineRuns`.
- `usePipelineRuns` uses `useRuns`, which dedupes PipelineRuns by `metadata.name` only.
### Fix Focus Areas
- src/components/hooks/useTaskRuns.ts[396-403]
- src/components/pipelines-list/PipelinesList.tsx[38-49]
- src/components/hooks/useTektonResult.ts[117-145]
- src/components/hooks/useTaskRuns.ts[206-217]
### Suggested fix
Change the PipelineRun dedupe key to include namespace (e.g., `${r.metadata.namespace ?? ''}/${r.metadata.name}`) instead of `r.metadata.name` alone, so same-named runs in different namespaces are not collapsed.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
This is an automated cherry-pick of #1170
/assign anwesha-palit-redhat