From d53b910e5a6d585c710bc41d664908563965e81b Mon Sep 17 00:00:00 2001 From: Gabriel Meghnagi Date: Fri, 20 Nov 2026 00:43:43 +0100 Subject: [PATCH 1/3] SRVKP-15665: Fix task status taken from a stale TaskRun record The PipelineRun topology merges the TaskRuns of the run from the Kubernetes API and from Tekton Results. The Results query of the topology was filtered by the `tekton.dev/pipelineRun` label only, so the TaskRun records left in Results by an earlier PipelineRun that used the same name came back too, and `appendPipelineRunStatus()` picked the first match by the `tekton.dev/pipelineTask` label - possibly the stale one. The task then rendered as failed (`pf-m-danger`, `0/1`) although the current TaskRun succeeded. - `PipelineRunVisualization` now passes the PipelineRun UID to `useTaskRuns()`, so the Results query is narrowed to `tekton.dev/pipelineRunUID` as well. - `getTaskRunForPipelineTask()` selects the TaskRun whose `tekton.dev/pipelineRunUID` label matches the displayed PipelineRun, and falls back to the first task-name match when the label is absent (TaskRuns created by older Tekton versions, or no record for this UID). --- .../PipelineRunVisualization.tsx | 2 +- .../utils/__tests__/pipeline-utils.spec.ts | 115 +++++++++++++++++- src/components/utils/pipeline-utils.ts | 44 ++++++- 3 files changed, 156 insertions(+), 5 deletions(-) diff --git a/src/components/pipelineRuns-details/PipelineRunVisualization.tsx b/src/components/pipelineRuns-details/PipelineRunVisualization.tsx index 888222a60..53a182da1 100644 --- a/src/components/pipelineRuns-details/PipelineRunVisualization.tsx +++ b/src/components/pipelineRuns-details/PipelineRunVisualization.tsx @@ -32,7 +32,7 @@ const PipelineRunVisualization: FC = ({ pipelineRun?.metadata?.namespace, pipelineRun?.metadata?.name, undefined, - undefined, + pipelineRun?.metadata?.uid, { pipelineRunFinished, pipelineRunManagedBy: pipelineRun?.spec?.managedBy, diff --git a/src/components/utils/__tests__/pipeline-utils.spec.ts b/src/components/utils/__tests__/pipeline-utils.spec.ts index 0d5a47e37..3154b29ad 100644 --- a/src/components/utils/__tests__/pipeline-utils.spec.ts +++ b/src/components/utils/__tests__/pipeline-utils.spec.ts @@ -21,7 +21,7 @@ import { taskRunWithSBOMResult, taskRunWithSBOMResultExternalLink, } from '../../../test-data/taskrun-test-data'; -import { ComputedStatus, ContainerStatus } from '../../../types'; +import { ComputedStatus, ContainerStatus, TaskRunKind } from '../../../types'; import { LatestPipelineRunStatus, appendPipelineRunStatus, @@ -380,6 +380,119 @@ describe('pipeline-utils ', () => { ).toHaveLength(2); }); + it('should pick the taskrun of the current pipelineRun when a stale taskrun with the same task label is present', () => { + const { pipeline, pipelineRuns } = + pipelineTestData[PipelineExampleNames.SIMPLE_PIPELINE]; + const pipelineRun = _.cloneDeep(pipelineRuns[DataState.SUCCESS]); + pipelineRun.metadata.uid = 'current-plr-uid'; + // Tekton v1 no longer populates status.taskRuns (only childReferences), so + // the task status must be derived from the TaskRun list, as in the console + delete pipelineRun.status.taskRuns; + const pipelineTaskName = pipeline.spec.tasks[0].name; + + const staleTaskRun = { + apiVersion: 'tekton.dev/v1', + kind: 'TaskRun', + metadata: { + name: `${pipelineRun.metadata.name}-${pipelineTaskName}`, + uid: 'stale-tr-uid', + labels: { + [TektonResourceLabel.pipelinerun]: pipelineRun.metadata.name, + [TektonResourceLabel.pipelineRunUid]: 'stale-plr-uid', + [TektonResourceLabel.pipelineTask]: pipelineTaskName, + }, + }, + spec: {}, + status: { + conditions: [ + { + type: 'Succeeded', + status: 'False', + reason: ComputedStatus.Failed, + }, + ], + steps: [{ terminated: { exitCode: 1, name: 'step' } }], + }, + } as unknown as TaskRunKind; + + const currentTaskRun = { + apiVersion: 'tekton.dev/v1', + kind: 'TaskRun', + metadata: { + name: `${pipelineRun.metadata.name}-${pipelineTaskName}`, + uid: 'current-tr-uid', + labels: { + [TektonResourceLabel.pipelinerun]: pipelineRun.metadata.name, + [TektonResourceLabel.pipelineRunUid]: 'current-plr-uid', + [TektonResourceLabel.pipelineTask]: pipelineTaskName, + }, + }, + spec: {}, + status: { + conditions: [ + { + type: 'Succeeded', + status: 'True', + reason: ComputedStatus.Succeeded, + }, + ], + steps: [{ terminated: { exitCode: 0, name: 'step' } }], + }, + } as unknown as TaskRunKind; + + // the stale record comes first: it used to win the `_.find` lookup + const taskList = appendPipelineRunStatus(pipeline, pipelineRun, [ + staleTaskRun, + currentTaskRun, + ]); + const firstTask = taskList.find((t) => t.name === pipelineTaskName); + + expect(firstTask.status.reason).toBe(ComputedStatus.Succeeded); + expect(firstTask.status.steps[0].terminated.exitCode).toBe(0); + }); + + it('should fall back to the first taskrun matching the task label when the pipelineRun uid is not labelled on the taskrun', () => { + const { pipeline, pipelineRuns } = + pipelineTestData[PipelineExampleNames.SIMPLE_PIPELINE]; + const pipelineRun = _.cloneDeep(pipelineRuns[DataState.SUCCESS]); + pipelineRun.metadata.uid = 'current-plr-uid'; + delete pipelineRun.status.taskRuns; + const pipelineTaskName = pipeline.spec.tasks[0].name; + + const taskRunsWithoutUidLabel = [ + { + apiVersion: 'tekton.dev/v1', + kind: 'TaskRun', + metadata: { + name: `${pipelineRun.metadata.name}-${pipelineTaskName}`, + uid: 'legacy-tr-uid', + labels: { + [TektonResourceLabel.pipelineTask]: pipelineTaskName, + }, + }, + spec: {}, + status: { + conditions: [ + { + type: 'Succeeded', + status: 'True', + reason: ComputedStatus.Succeeded, + }, + ], + }, + } as unknown as TaskRunKind, + ]; + + const taskList = appendPipelineRunStatus( + pipeline, + pipelineRun, + taskRunsWithoutUidLabel, + ); + const firstTask = taskList.find((t) => t.name === pipelineTaskName); + + expect(firstTask.status.reason).toBe(ComputedStatus.Succeeded); + }); + it('should append pipelineRun pending status for all the tasks if taskruns are not present and pipelinerun status is PipelineRunPending', () => { const { pipeline, pipelineRuns } = pipelineTestData[PipelineExampleNames.SIMPLE_PIPELINE]; diff --git a/src/components/utils/pipeline-utils.ts b/src/components/utils/pipeline-utils.ts index bd541f784..6972165ae 100644 --- a/src/components/utils/pipeline-utils.ts +++ b/src/components/utils/pipeline-utils.ts @@ -127,6 +127,44 @@ export const PipelineResourceListFilterLabels = { export const INSTANCE_LABEL = 'app.kubernetes.io/instance'; +/** + * Returns the TaskRun that belongs to the given PipelineRun. + * + * Several TaskRuns can carry the same `tekton.dev/pipelineTask` label: Tekton + * Results keeps the records of previous PipelineRuns that used the same name, + * and the merge of the k8s and Results lists only de-duplicates by UID. When + * the PipelineRun UID is known, the TaskRun created by that very PipelineRun + * is preferred, so that the status of a stale record is never displayed. + * + * @param taskRuns the TaskRuns to pick from + * @param pipelineTaskName the `tekton.dev/pipelineTask` label value to match + * @param pipelineRunUid the UID of the PipelineRun being displayed, if known + */ +export const getTaskRunForPipelineTask = ( + taskRuns: TaskRunKind[], + pipelineTaskName: string, + pipelineRunUid?: string, +): TaskRunKind | undefined => { + const candidates = (taskRuns || []).filter( + (tr) => + tr.metadata?.labels?.[TektonResourceLabel.pipelineTask] === + pipelineTaskName, + ); + if (pipelineRunUid) { + const currentTaskRun = candidates.find( + (tr) => + tr.metadata?.labels?.[TektonResourceLabel.pipelineRunUid] === + pipelineRunUid, + ); + if (currentTaskRun) { + return currentTaskRun; + } + } + // Fallback: no UID label (TaskRuns created by older Tekton versions) or no + // record for this UID, keep the previous behaviour. + return candidates[0]; +}; + /** * Appends the pipeline run status to each tasks in the pipeline. * @param pipeline @@ -167,10 +205,10 @@ export const appendPipelineRunStatus = ( return { ...task, status: { reason: ComputedStatus.Pending } }; } - const taskRun = _.find( + const taskRun = getTaskRunForPipelineTask( taskRuns, - (tr) => - tr.metadata.labels[TektonResourceLabel.pipelineTask] === task.name, + task.name, + pipelineRun.metadata?.uid, ); const childPipelineRun = _.find( From a6d946ff1194e23e5cff9f16287eb95626b8bf97 Mon Sep 17 00:00:00 2001 From: Gabriel Meghnagi Date: Fri, 20 Nov 2026 00:55:18 +0100 Subject: [PATCH 2/3] SRVKP-15665: Document why the TaskRun fallback must stay A TaskRun is not always labelled with the UID of the PipelineRun being displayed: on a multi-cluster setup the PipelineRun exists on the hub and on the spoke with different UIDs (see the uniqBy by name in useTaskRuns), and TaskRuns created by older Tekton versions carry no tekton.dev/pipelineRunUID label at all. Returning no TaskRun for those would leave the task without its real status, so keep the fallback and cover it with a test. --- .../utils/__tests__/pipeline-utils.spec.ts | 44 +++++++++++++++++++ src/components/utils/pipeline-utils.ts | 11 ++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/components/utils/__tests__/pipeline-utils.spec.ts b/src/components/utils/__tests__/pipeline-utils.spec.ts index 3154b29ad..7d0cfdc4c 100644 --- a/src/components/utils/__tests__/pipeline-utils.spec.ts +++ b/src/components/utils/__tests__/pipeline-utils.spec.ts @@ -493,6 +493,50 @@ describe('pipeline-utils ', () => { expect(firstTask.status.reason).toBe(ComputedStatus.Succeeded); }); + it('should keep the taskrun status when the taskrun is labelled with a different pipelineRun uid (multi-cluster hub/spoke)', () => { + const { pipeline, pipelineRuns } = + pipelineTestData[PipelineExampleNames.SIMPLE_PIPELINE]; + const pipelineRun = _.cloneDeep(pipelineRuns[DataState.SUCCESS]); + // the PipelineRun is the hub copy + pipelineRun.metadata.uid = 'hub-plr-uid'; + delete pipelineRun.status.taskRuns; + const pipelineTaskName = pipeline.spec.tasks[0].name; + + // the TaskRun comes from the spoke through the multi-cluster proxy, so its + // `tekton.dev/pipelineRunUID` label is the spoke PipelineRun UID + const spokeTaskRun = { + apiVersion: 'tekton.dev/v1', + kind: 'TaskRun', + metadata: { + name: `${pipelineRun.metadata.name}-${pipelineTaskName}`, + uid: 'spoke-tr-uid', + labels: { + [TektonResourceLabel.pipelinerun]: pipelineRun.metadata.name, + [TektonResourceLabel.pipelineRunUid]: 'spoke-plr-uid', + [TektonResourceLabel.pipelineTask]: pipelineTaskName, + }, + }, + spec: {}, + status: { + conditions: [ + { + type: 'Succeeded', + status: 'True', + reason: ComputedStatus.Succeeded, + }, + ], + }, + } as unknown as TaskRunKind; + + const taskList = appendPipelineRunStatus(pipeline, pipelineRun, [ + spokeTaskRun, + ]); + const firstTask = taskList.find((t) => t.name === pipelineTaskName); + + // returning no TaskRun here would leave the task without its real status + expect(firstTask.status.reason).toBe(ComputedStatus.Succeeded); + }); + it('should append pipelineRun pending status for all the tasks if taskruns are not present and pipelinerun status is PipelineRunPending', () => { const { pipeline, pipelineRuns } = pipelineTestData[PipelineExampleNames.SIMPLE_PIPELINE]; diff --git a/src/components/utils/pipeline-utils.ts b/src/components/utils/pipeline-utils.ts index 6972165ae..90535b375 100644 --- a/src/components/utils/pipeline-utils.ts +++ b/src/components/utils/pipeline-utils.ts @@ -136,6 +136,13 @@ export const INSTANCE_LABEL = 'app.kubernetes.io/instance'; * the PipelineRun UID is known, the TaskRun created by that very PipelineRun * is preferred, so that the status of a stale record is never displayed. * + * The fallback to the first match is intentional and must stay: the UID label + * of the TaskRun is not always equal to the UID of the PipelineRun being shown. + * On a multi-cluster setup the PipelineRun exists on the hub and on the spoke + * with different UIDs (see the `uniqBy` by name in `useTaskRuns`), and TaskRuns + * created by older Tekton versions carry no `tekton.dev/pipelineRunUID` label at + * all. Dropping the fallback would leave those tasks without any status. + * * @param taskRuns the TaskRuns to pick from * @param pipelineTaskName the `tekton.dev/pipelineTask` label value to match * @param pipelineRunUid the UID of the PipelineRun being displayed, if known @@ -159,9 +166,9 @@ export const getTaskRunForPipelineTask = ( if (currentTaskRun) { return currentTaskRun; } + // No TaskRun is labelled with this UID. Keep the previous behaviour + // instead of returning nothing, see the note above. } - // Fallback: no UID label (TaskRuns created by older Tekton versions) or no - // record for this UID, keep the previous behaviour. return candidates[0]; }; From 100e13181f4b2d4baab1eedb2d6d8afb27cd60f1 Mon Sep 17 00:00:00 2001 From: Gabriel Meghnagi Date: Fri, 20 Nov 2026 10:17:47 +0100 Subject: [PATCH 3/3] SRVKP-15665: Select the current TaskRun without narrowing the query Revert passing the PipelineRun UID to `useTaskRuns()` from `PipelineRunVisualization`: the UID becomes a required term of both the k8s selector and the Tekton Results filter (`selectorToFilter` turns every matchLabel into a mandatory `EQ`), which would drop TaskRuns whose `tekton.dev/pipelineRunUID` label does not match the displayed PipelineRun - the case of a Kueue-managed hub PipelineRun, whose TaskRuns carry the spoke UID. Picking the current TaskRun in `getTaskRunForPipelineTask` already fixes the stale-record status, and it keeps working on the broader, name-only list. The Results query stays filtered by `tekton.dev/pipelineRun` only, so it can return the records of earlier runs that reused the name; that is accepted in exchange for not filtering out TaskRuns that legitimately carry another UID. --- .../pipelineRuns-details/PipelineRunVisualization.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pipelineRuns-details/PipelineRunVisualization.tsx b/src/components/pipelineRuns-details/PipelineRunVisualization.tsx index 53a182da1..888222a60 100644 --- a/src/components/pipelineRuns-details/PipelineRunVisualization.tsx +++ b/src/components/pipelineRuns-details/PipelineRunVisualization.tsx @@ -32,7 +32,7 @@ const PipelineRunVisualization: FC = ({ pipelineRun?.metadata?.namespace, pipelineRun?.metadata?.name, undefined, - pipelineRun?.metadata?.uid, + undefined, { pipelineRunFinished, pipelineRunManagedBy: pipelineRun?.spec?.managedBy,