From 636419138567d24ccb4bc4d77bc76cbd006a698d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=85=8B=E4=BC=9F?= Date: Mon, 18 Sep 2023 10:06:51 +0800 Subject: [PATCH] fix: clean results when taskrun retries --- docs/taskruns.md | 2 +- pkg/reconciler/taskrun/taskrun.go | 1 + pkg/reconciler/taskrun/taskrun_test.go | 53 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/taskruns.md b/docs/taskruns.md index d622637b2be..c8f2c51908e 100644 --- a/docs/taskruns.md +++ b/docs/taskruns.md @@ -739,7 +739,7 @@ Type: Succeeded Status: Unknown Reason: ToBeRetried ``` -- `status.StartTime` and `status.PodName` are unset to trigger another retry attempt. +- `status.StartTime`, `status.PodName` and `status.Results` are unset to trigger another retry attempt. ### Configuring the failure timeout diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index aa8becd044d..76c0338e3cd 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -980,6 +980,7 @@ func retryTaskRun(tr *v1.TaskRun, message string) { tr.Status.StartTime = nil tr.Status.CompletionTime = nil tr.Status.PodName = "" + tr.Status.Results = nil taskRunCondSet := apis.NewBatchConditionSet() taskRunCondSet.Manage(&tr.Status).MarkUnknown(apis.ConditionSucceeded, v1.TaskRunReasonToBeRetried.String(), message) } diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index b3f7fc77b43..fcda8c5974f 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -1747,6 +1747,50 @@ status: ResultExtractionMethod: "termination-message" MaxResultSize: 4096 Coschedule: "workspaces" +`) + toBeRetriedWithResultsTaskRun = parse.MustParseV1TaskRun(t, ` +metadata: + name: test-taskrun-with-results-to-be-retried + namespace: foo +spec: + retries: 1 + taskRef: + name: test-results-task +status: + startTime: "2021-12-31T23:59:59Z" + results: + - name: aResult + type: string + value: aResultValue + conditions: + - reason: Failed + status: "False" + type: Succeeded +`) + retriedWithResultsTaskRun = parse.MustParseV1TaskRun(t, ` +metadata: + name: test-taskrun-with-results-to-be-retried + namespace: foo +spec: + retries: 1 + taskRef: + name: test-results-task +status: + podName: "" + conditions: + - reason: ToBeRetried + status: Unknown + type: Succeeded + retriesStatus: + - conditions: + - reason: Failed + status: "False" + type: Succeeded + results: + - name: aResult + type: string + value: aResultValue + startTime: "2021-12-31T23:59:59Z" `) ) @@ -1823,6 +1867,15 @@ status: tr: toBeRetriedTaskRun, wantTr: retriedTaskRun, wantStartTime: true, + }, { + name: "TaskRun retry and clear the results", + testData: test.Data{ + TaskRuns: []*v1.TaskRun{toBeRetriedWithResultsTaskRun}, + Tasks: []*v1.Task{resultsTask}, + }, + tr: toBeRetriedWithResultsTaskRun, + wantTr: retriedWithResultsTaskRun, + wantStartTime: false, }} { t.Run(tc.name, func(t *testing.T) { testAssets, cancel := getTaskRunController(t, tc.testData)