From 1d27ad71802247033b24d35da2bebc1bea37df99 Mon Sep 17 00:00:00 2001 From: Jerome Ju Date: Fri, 3 Feb 2023 22:50:53 +0000 Subject: [PATCH] Remove TaskRuns and Runs Fields of PipelineRunStatus This commit removes `status.taskruns` and `status.runs` for PipelineRunStatus since they have been deprecated. The corresponding usage in the test cases are replaced with `childReferences`. --- docs/pipeline-api.md | 36 -- docs/pipelineruns.md | 236 +++---------- .../pipeline/v1beta1/openapi_generated.go | 60 +--- .../pipeline/v1beta1/pipelinerun_types.go | 16 - .../v1beta1/pipelinerun_types_test.go | 16 - pkg/apis/pipeline/v1beta1/swagger.json | 28 -- .../pipeline/v1beta1/zz_generated.deepcopy.go | 30 -- pkg/reconciler/pipelinerun/pipelinerun.go | 66 +--- .../pipelinerun/pipelinerun_test.go | 98 +++--- .../pipelinerun_updatestatus_test.go | 323 ------------------ .../resources/pipelinerunresolution.go | 21 +- .../resources/pipelinerunresolution_test.go | 37 +- .../pipelinerun/resources/pipelinerunstate.go | 75 ---- .../resources/pipelinerunstate_test.go | 193 ----------- pkg/reconciler/pipelinerun/timeout_test.go | 7 - test/propagated_params_test.go | 2 +- 16 files changed, 106 insertions(+), 1138 deletions(-) diff --git a/docs/pipeline-api.md b/docs/pipeline-api.md index a948c68336f..1d8b681187d 100644 --- a/docs/pipeline-api.md +++ b/docs/pipeline-api.md @@ -9612,9 +9612,6 @@ ParamValue

PipelineRunRunStatus

-

-(Appears on:PipelineRunStatusFields) -

PipelineRunRunStatus contains the name of the PipelineTask for this CustomRun or Run and the CustomRun or Run’s Status

@@ -9942,36 +9939,6 @@ Kubernetes meta/v1.Time -taskRuns
- - -map[string]*github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunTaskRunStatus - - - - -(Optional) -

Deprecated - use ChildReferences instead. -map of PipelineRunTaskRunStatus with the taskRun name as the key

- - - - -runs
- - -map[string]*github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunRunStatus - - - - -(Optional) -

Deprecated - use ChildReferences instead. -map of PipelineRunRunStatus with the run name as the key

- - - - pipelineResults
@@ -10068,9 +10035,6 @@ map[string]string

PipelineRunTaskRunStatus

-

-(Appears on:PipelineRunStatusFields) -

PipelineRunTaskRunStatus contains the name of the PipelineTask for this TaskRun and the TaskRun’s Status

diff --git a/docs/pipelineruns.md b/docs/pipelineruns.md index 6556869afe5..b73d089d843 100644 --- a/docs/pipelineruns.md +++ b/docs/pipelineruns.md @@ -403,31 +403,13 @@ status: type: Succeeded pipelineSpec: ... - taskRuns: - pr-echo-szzs9-echo-hello: - pipelineTaskName: echo-hello - status: - ... - taskSpec: - steps: - - image: ubuntu - name: echo - resources: {} - script: | - #!/usr/bin/env bash - echo "Hello World!" - pr-echo-szzs9-echo-bye: - pipelineTaskName: echo-bye - status: - ... - taskSpec: - steps: - - image: ubuntu - name: echo - resources: {} - script: | - #!/usr/bin/env bash - echo "Bye World!" + childReferences: + - name: pr-echo-szzs9-echo-hello + pipelineTaskName: echo-hello + kind: TaskRun + - name: pr-echo-szzs9-echo-bye + pipelineTaskName: echo-bye + kind: TaskRun ``` ##### Scope and Precedence @@ -483,25 +465,11 @@ status: status: "True" type: Succeeded ... - taskRuns: - pr-echo-szzs9-echo-hello: - pipelineTaskName: echo-hello - status: - conditions: - - lastTransitionTime: "2022-04-07T12:34:57Z" - message: All Steps have completed executing - reason: Succeeded - status: "True" - type: Succeeded - taskSpec: - steps: - - image: ubuntu - name: echo - resources: {} - script: | - #!/usr/bin/env bash - echo "Sasa World!" - ... + childReferences: + - name: pr-echo-szzs9-echo-hello + pipelineTaskName: echo-hello + kind: TaskRun + ... ``` ##### Default Values @@ -555,25 +523,11 @@ status: status: "True" type: Succeeded ... - taskRuns: - pr-echo-szzs9-echo-hello: - pipelineTaskName: echo-hello - status: - conditions: - - lastTransitionTime: "2022-04-07T12:34:57Z" - message: All Steps have completed executing - reason: Succeeded - status: "True" - type: Succeeded - taskSpec: - steps: - - image: ubuntu - name: echo - resources: {} - script: | - #!/usr/bin/env bash - echo "Hello World!" - ... + childReferences: + - name: pr-echo-szzs9-echo-hello + pipelineTaskName: echo-hello + kind: TaskRun + ... ``` ##### Referenced Resources @@ -766,21 +720,10 @@ status: name: write-result resources: {} startTime: "2022-09-08T17:21:57Z" - taskRuns: - pipelinerun-object-param-resultpxp59-task1: - pipelineTaskName: task1 - status: - completionTime: "2022-09-08T17:22:01Z" - conditions: - - lastTransitionTime: "2022-09-08T17:22:01Z" - message: All Steps have completed executing - reason: Succeeded - status: "True" - type: Succeeded - podName: pipelinerun-object-param-resultpxp59-task1-pod - startTime: "2022-09-08T17:21:57Z" - steps: - - container: step-write-result + childReferences: + - name: pipelinerun-object-param-resultpxp59-task1 + pipelineTaskName: task1 + kind: TaskRun ... taskSpec: steps: @@ -1054,32 +997,13 @@ status: type: Succeeded pipelineSpec: ... - taskRuns: - recipe-time-lslt9-fetch-secure-data: - pipelineTaskName: fetch-secure-data - status: - ... - taskSpec: - steps: - - image: ubuntu - name: fetch-and-write-secure - resources: {} - script: | - echo hi >> cat /workspace/shared-data/recipe.txt - workspaces: - - name: shared-data - recipe-time-lslt9-print-the-recipe: - pipelineTaskName: print-the-recipe - status: - ... - taskSpec: - steps: - - image: ubuntu - name: print-secrets - resources: {} - script: cat /workspace/shared-data/recipe.txt - workspaces: - - name: shared-data + childReferences: + - name: recipe-time-lslt9-fetch-secure-data + pipelineTaskName: fetch-secure-data + kind: TaskRun + - name: recipe-time-lslt9-print-the-recipe + pipelineTaskName: print-the-recipe + kind: TaskRun ``` ##### Workspace Referenced Resources @@ -1155,26 +1079,10 @@ status: type: Succeeded pipelineSpec: ... - taskRuns: - recipe-time-v5scg-fetch-the-recipe: - pipelineTaskName: fetch-the-recipe - status: - completionTime: "2022-06-02T19:02:58Z" - conditions: - - lastTransitionTime: "2022-06-02T19:02:58Z" - message: | - "step-fetch-and-write" exited with code 1 (image: "docker.io/library/ubuntu@sha256:26c68657ccce2cb0a31b330cb0be2b5e108d467f641c62e13ab40cbec258c68d"); for logs run: kubectl -n default logs recipe-time-v5scg-fetch-the-recipe-pod -c step-fetch-and-write - reason: Failed - status: "False" - type: Succeeded - ... - taskSpec: - steps: - - image: ubuntu - name: fetch-and-write - resources: {} - script: | # See below: Replacements do not happen. - echo hi >> $(workspaces.shared-data.path)/recipe.txt + childReferences: + - name: recipe-time-v5scg-fetch-the-recipe + pipelineTaskName: fetch-the-recipe + kind: TaskRun ``` #### Referenced TaskRuns within Embedded PipelineRuns @@ -1253,32 +1161,13 @@ status: type: Succeeded pipelineSpec: ... - taskRuns: - recipe-time-pj6l7-fetch-the-recipe: - pipelineTaskName: fetch-the-recipe - status: - ... - taskSpec: - steps: - - image: ubuntu - name: fetch-and-write - resources: {} - script: | - echo /workspace/shared-data - workspaces: - - name: shared-data - recipe-time-pj6l7-print-the-recipe: - pipelineTaskName: print-the-recipe - status: - ... - taskSpec: - steps: - - image: ubuntu - name: print-secrets - resources: {} - script: cat /workspace/shared-data/recipe.txt - workspaces: - - name: shared-data + childReferences: + - name: recipe-time-pj6l7-fetch-the-recipe + pipelineTaskName: fetch-the-recipe + kind: TaskRun + - name: recipe-time-pj6l7-print-the-recipe + pipelineTaskName: print-the-recipe + kind: TaskRun ``` ### Specifying `LimitRange` values @@ -1376,8 +1265,6 @@ Your `PipelineRun`'s `status` field can contain the following fields: - `completionTime` - The time at which the `PipelineRun` finished executing, in [RFC3339](https://tools.ietf.org/html/rfc3339) format. - [`pipelineSpec`](pipelines.md#configuring-a-pipeline) - The exact `PipelineSpec` used when starting the `PipelineRun`. - Optional: - - `taskRuns` - A map of `TaskRun` names to detailed information about the status of that `TaskRun`. This is deprecated and will be removed in favor of using `childReferences`. - - `runs` - A map of custom task `Run` names to detailed information about the status of that `Run`. This is deprecated and will be removed in favor of using `childReferences`. - [`pipelineResults`](pipelines.md#emitting-results-from-a-pipeline) - Results emitted by this `PipelineRun`. - `skippedTasks` - A list of `Task`s which were skipped when running this `PipelineRun` due to [when expressions](pipelines.md#guard-task-execution-using-when-expressions), including the when expressions applying to the skipped task. - `childReferences` - A list of references to each `TaskRun` or `Run` in this `PipelineRun`, which can be used to look up the status of the underlying `TaskRun` or `Run`. Each entry contains the following: @@ -1406,33 +1293,10 @@ conditions: status: "True" type: Succeeded startTime: "2020-05-04T02:00:11Z" -taskRuns: - triggers-release-nightly-frwmw-build: - pipelineTaskName: build - status: - completionTime: "2020-05-04T02:10:49Z" - conditions: - - lastTransitionTime: "2020-05-04T02:10:49Z" - message: All Steps have completed executing - reason: Succeeded - status: "True" - type: Succeeded - podName: triggers-release-nightly-frwmw-build-pod - resourcesResult: - - key: commit - resourceName: git-source-triggers-frwmw - value: 9ab5a1234166a89db352afa28f499d596ebb48db - startTime: "2020-05-04T02:05:07Z" - steps: - - container: step-build - imageID: docker-pullable://golang@sha256:a90f2671330831830e229c3554ce118009681ef88af659cd98bfafd13d5594f9 - name: build - terminated: - containerID: docker://6b6471f501f59dbb7849f5cdde200f4eeb64302b862a27af68821a7fb2c25860 - exitCode: 0 - finishedAt: "2020-05-04T02:10:45Z" - reason: Completed - startedAt: "2020-05-04T02:06:24Z" +childReferences: +- name: triggers-release-nightly-frwmw-build + pipelineTaskName: build + kind: TaskRun ``` The following tables shows how to read the overall status of a `PipelineRun`. @@ -1477,16 +1341,10 @@ Skipped Tasks: Operator: notin Values: foo -Task Runs: - pipelinerun-to-skip-task-run-this-task: - Pipeline Task Name: run-this-task - Status: - ... - When Expressions: - Input: foo - Operator: in - Values: - foo +ChildReferences: +- Name: pipelinerun-to-skip-task-run-this-task + Pipeline Task Name: run-this-task + Kind: TaskRun ``` The name of the `TaskRuns` and `Runs` owned by a `PipelineRun` are univocally associated to the owning resource. diff --git a/pkg/apis/pipeline/v1beta1/openapi_generated.go b/pkg/apis/pipeline/v1beta1/openapi_generated.go index e940f3465ee..9af26e3322e 100644 --- a/pkg/apis/pipeline/v1beta1/openapi_generated.go +++ b/pkg/apis/pipeline/v1beta1/openapi_generated.go @@ -2015,34 +2015,6 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineRunStatus(ref common.ReferenceCall Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), }, }, - "taskRuns": { - SchemaProps: spec.SchemaProps{ - Description: "Deprecated - use ChildReferences instead. map of PipelineRunTaskRunStatus with the taskRun name as the key", - Type: []string{"object"}, - AdditionalProperties: &spec.SchemaOrBool{ - Allows: true, - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunTaskRunStatus"), - }, - }, - }, - }, - }, - "runs": { - SchemaProps: spec.SchemaProps{ - Description: "Deprecated - use ChildReferences instead. map of PipelineRunRunStatus with the run name as the key", - Type: []string{"object"}, - AdditionalProperties: &spec.SchemaOrBool{ - Allows: true, - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunRunStatus"), - }, - }, - }, - }, - }, "pipelineResults": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -2138,7 +2110,7 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineRunStatus(ref common.ReferenceCall }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ChildStatusReference", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunRunStatus", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunTaskRunStatus", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Provenance", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.SkippedTask", "k8s.io/apimachinery/pkg/apis/meta/v1.Time", "knative.dev/pkg/apis.Condition"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ChildStatusReference", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Provenance", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.SkippedTask", "k8s.io/apimachinery/pkg/apis/meta/v1.Time", "knative.dev/pkg/apis.Condition"}, } } @@ -2161,34 +2133,6 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineRunStatusFields(ref common.Referen Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), }, }, - "taskRuns": { - SchemaProps: spec.SchemaProps{ - Description: "Deprecated - use ChildReferences instead. map of PipelineRunTaskRunStatus with the taskRun name as the key", - Type: []string{"object"}, - AdditionalProperties: &spec.SchemaOrBool{ - Allows: true, - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunTaskRunStatus"), - }, - }, - }, - }, - }, - "runs": { - SchemaProps: spec.SchemaProps{ - Description: "Deprecated - use ChildReferences instead. map of PipelineRunRunStatus with the run name as the key", - Type: []string{"object"}, - AdditionalProperties: &spec.SchemaOrBool{ - Allows: true, - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunRunStatus"), - }, - }, - }, - }, - }, "pipelineResults": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -2284,7 +2228,7 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineRunStatusFields(ref common.Referen }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ChildStatusReference", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunRunStatus", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunTaskRunStatus", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Provenance", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.SkippedTask", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ChildStatusReference", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineRunResult", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Provenance", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.SkippedTask", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, } } diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_types.go b/pkg/apis/pipeline/v1beta1/pipelinerun_types.go index e67f25f0f4a..abfb42d4760 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_types.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_types.go @@ -351,12 +351,6 @@ func (pr *PipelineRunStatus) GetCondition(t apis.ConditionType) *apis.Condition // and set the started time to the current time func (pr *PipelineRunStatus) InitializeConditions(c clock.PassiveClock) { started := false - if pr.TaskRuns == nil { - pr.TaskRuns = make(map[string]*PipelineRunTaskRunStatus) - } - if pr.Runs == nil { - pr.Runs = make(map[string]*PipelineRunRunStatus) - } if pr.StartTime.IsZero() { pr.StartTime = &metav1.Time{Time: c.Now()} started = true @@ -422,16 +416,6 @@ type PipelineRunStatusFields struct { // CompletionTime is the time the PipelineRun completed. CompletionTime *metav1.Time `json:"completionTime,omitempty"` - // Deprecated - use ChildReferences instead. - // map of PipelineRunTaskRunStatus with the taskRun name as the key - // +optional - TaskRuns map[string]*PipelineRunTaskRunStatus `json:"taskRuns,omitempty"` - - // Deprecated - use ChildReferences instead. - // map of PipelineRunRunStatus with the run name as the key - // +optional - Runs map[string]*PipelineRunRunStatus `json:"runs,omitempty"` - // PipelineResults are the list of results written out by the pipeline task's containers // +optional // +listType=atomic diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go b/pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go index 1fe11282dea..8d76ec0bf2c 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go @@ -76,14 +76,6 @@ func TestInitializePipelineRunConditions(t *testing.T) { } p.Status.InitializeConditions(testClock) - if p.Status.TaskRuns == nil { - t.Fatalf("PipelineRun TaskRun status not initialized correctly") - } - - if p.Status.Runs == nil { - t.Fatalf("PipelineRun Run status not initialized correctly") - } - if p.Status.StartTime.IsZero() { t.Fatalf("PipelineRun StartTime not initialized correctly") } @@ -92,8 +84,6 @@ func TestInitializePipelineRunConditions(t *testing.T) { if condition.Reason != v1beta1.PipelineRunReasonStarted.String() { t.Fatalf("PipelineRun initialize reason should be %s, got %s instead", v1beta1.PipelineRunReasonStarted.String(), condition.Reason) } - p.Status.TaskRuns["fooTask"] = &v1beta1.PipelineRunTaskRunStatus{} - p.Status.Runs["bahTask"] = &v1beta1.PipelineRunRunStatus{} // Change the reason before we initialize again p.Status.SetCondition(&apis.Condition{ @@ -104,12 +94,6 @@ func TestInitializePipelineRunConditions(t *testing.T) { }) p.Status.InitializeConditions(testClock) - if len(p.Status.TaskRuns) != 1 { - t.Fatalf("PipelineRun TaskRun status getting reset") - } - if len(p.Status.Runs) != 1 { - t.Fatalf("PipelineRun Run status getting reset") - } newCondition := p.Status.GetCondition(apis.ConditionSucceeded) if newCondition.Reason != "not just started" { diff --git a/pkg/apis/pipeline/v1beta1/swagger.json b/pkg/apis/pipeline/v1beta1/swagger.json index 9c7742a0909..60b204db412 100644 --- a/pkg/apis/pipeline/v1beta1/swagger.json +++ b/pkg/apis/pipeline/v1beta1/swagger.json @@ -1215,13 +1215,6 @@ "description": "Provenance contains some key authenticated metadata about how a software artifact was built (what sources, what inputs/outputs, etc.).", "$ref": "#/definitions/v1beta1.Provenance" }, - "runs": { - "description": "Deprecated - use ChildReferences instead. map of PipelineRunRunStatus with the run name as the key", - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/v1beta1.PipelineRunRunStatus" - } - }, "skippedTasks": { "description": "list of tasks that were skipped due to when expressions evaluating to false", "type": "array", @@ -1242,13 +1235,6 @@ "startTime": { "description": "StartTime is the time the PipelineRun is actually started.", "$ref": "#/definitions/v1.Time" - }, - "taskRuns": { - "description": "Deprecated - use ChildReferences instead. map of PipelineRunTaskRunStatus with the taskRun name as the key", - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/v1beta1.PipelineRunTaskRunStatus" - } } } }, @@ -1290,13 +1276,6 @@ "description": "Provenance contains some key authenticated metadata about how a software artifact was built (what sources, what inputs/outputs, etc.).", "$ref": "#/definitions/v1beta1.Provenance" }, - "runs": { - "description": "Deprecated - use ChildReferences instead. map of PipelineRunRunStatus with the run name as the key", - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/v1beta1.PipelineRunRunStatus" - } - }, "skippedTasks": { "description": "list of tasks that were skipped due to when expressions evaluating to false", "type": "array", @@ -1317,13 +1296,6 @@ "startTime": { "description": "StartTime is the time the PipelineRun is actually started.", "$ref": "#/definitions/v1.Time" - }, - "taskRuns": { - "description": "Deprecated - use ChildReferences instead. map of PipelineRunTaskRunStatus with the taskRun name as the key", - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/v1beta1.PipelineRunTaskRunStatus" - } } } }, diff --git a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go index 72c04ccbf0d..3aaefbab440 100644 --- a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go @@ -824,36 +824,6 @@ func (in *PipelineRunStatusFields) DeepCopyInto(out *PipelineRunStatusFields) { in, out := &in.CompletionTime, &out.CompletionTime *out = (*in).DeepCopy() } - if in.TaskRuns != nil { - in, out := &in.TaskRuns, &out.TaskRuns - *out = make(map[string]*PipelineRunTaskRunStatus, len(*in)) - for key, val := range *in { - var outVal *PipelineRunTaskRunStatus - if val == nil { - (*out)[key] = nil - } else { - in, out := &val, &outVal - *out = new(PipelineRunTaskRunStatus) - (*in).DeepCopyInto(*out) - } - (*out)[key] = outVal - } - } - if in.Runs != nil { - in, out := &in.Runs, &out.Runs - *out = make(map[string]*PipelineRunRunStatus, len(*in)) - for key, val := range *in { - var outVal *PipelineRunRunStatus - if val == nil { - (*out)[key] = nil - } else { - in, out := &val, &outVal - *out = new(PipelineRunRunStatus) - (*in).DeepCopyInto(*out) - } - (*out)[key] = outVal - } - } if in.PipelineResults != nil { in, out := &in.PipelineResults, &out.PipelineResults *out = make([]PipelineRunResult, len(*in)) diff --git a/pkg/reconciler/pipelinerun/pipelinerun.go b/pkg/reconciler/pipelinerun/pipelinerun.go index 799d2abd37d..08835722881 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/pipelinerun/pipelinerun.go @@ -310,7 +310,7 @@ func (c *Reconciler) resolvePipelineState( for _, task := range tasks { // We need the TaskRun name to ensure that we don't perform an additional remote resolution request for a PipelineTask // in the TaskRun reconciler. - trName := resources.GetTaskRunName(pr.Status.TaskRuns, pr.Status.ChildReferences, task.Name, pr.Name) + trName := resources.GetTaskRunName(pr.Status.ChildReferences, task.Name, pr.Name) vp, err := getVerificationPolicies(ctx, c.verificationPolicyLister, pr.Namespace) if err != nil { @@ -1317,12 +1317,6 @@ func (c *Reconciler) updatePipelineRunStatusFromInformer(ctx context.Context, pr } func updatePipelineRunStatusFromChildObjects(ctx context.Context, logger *zap.SugaredLogger, pr *v1beta1.PipelineRun, taskRuns []*v1beta1.TaskRun, runObjects []v1beta1.RunObject) error { - // Clear any TaskRuns and Runs present in the status. - // This can occur if the value of "embedded-status" flag was modified during PipelineRun execution prior to its removal. - // TODO: https://github.com/tektoncd/pipeline/issues/6090 cleanup the checks for `status.taskruns` and - // `status.runs` and refactor the helper functions to be combined - pr.Status.Runs = nil - pr.Status.TaskRuns = nil updatePipelineRunStatusFromChildRefs(logger, pr, taskRuns, runObjects) return validateChildObjectsInPipelineRunStatus(ctx, pr.Status) @@ -1395,64 +1389,6 @@ func filterRunsForPipelineRunStatus(logger *zap.SugaredLogger, pr *v1beta1.Pipel return names, taskLabels, gvks, statuses } -// updatePipelineRunStatusFromTaskRuns takes a PipelineRun and a list of TaskRuns within that PipelineRun, and updates -// the PipelineRun's .Status.TaskRuns. -func updatePipelineRunStatusFromTaskRuns(logger *zap.SugaredLogger, pr *v1beta1.PipelineRun, trs []*v1beta1.TaskRun) { - // If no TaskRun was found, nothing to be done. We never remove taskruns from the status - if len(trs) == 0 { - return - } - - if pr.Status.TaskRuns == nil { - pr.Status.TaskRuns = make(map[string]*v1beta1.PipelineRunTaskRunStatus) - } - - taskRuns := filterTaskRunsForPipelineRunStatus(logger, pr, trs) - - // Loop over all the TaskRuns associated to Tasks - for _, taskrun := range taskRuns { - lbls := taskrun.GetLabels() - pipelineTaskName := lbls[pipeline.PipelineTaskLabelKey] - - if _, ok := pr.Status.TaskRuns[taskrun.Name]; !ok { - // This taskrun was missing from the status. - // Add it without conditions, which are handled in the next loop - logger.Infof("Found a TaskRun %s that was missing from the PipelineRun status", taskrun.Name) - pr.Status.TaskRuns[taskrun.Name] = &v1beta1.PipelineRunTaskRunStatus{ - PipelineTaskName: pipelineTaskName, - Status: &taskrun.Status, - } - } - } -} - -func updatePipelineRunStatusFromCustomRunsOrRuns(logger *zap.SugaredLogger, pr *v1beta1.PipelineRun, runObjects []v1beta1.RunObject) { - // If no RunObject was found, nothing to be done. We never remove runs from the status - if len(runObjects) == 0 { - return - } - if pr.Status.Runs == nil { - pr.Status.Runs = make(map[string]*v1beta1.PipelineRunRunStatus) - } - - // Get the names, their task label values, and their status objects for all CustomRuns or Runs associated with the PipelineRun - names, taskLabels, _, statuses := filterRunsForPipelineRunStatus(logger, pr, runObjects) - - // Loop over all the elements and populate the status map - for idx := range names { - name := names[idx] - taskLabel := taskLabels[idx] - crStatus := statuses[idx] - if _, ok := pr.Status.Runs[name]; !ok { - // This run was missing from the status. - pr.Status.Runs[name] = &v1beta1.PipelineRunRunStatus{ - PipelineTaskName: taskLabel, - Status: crStatus, - } - } - } -} - func updatePipelineRunStatusFromChildRefs(logger *zap.SugaredLogger, pr *v1beta1.PipelineRun, trs []*v1beta1.TaskRun, runObjects []v1beta1.RunObject) { // If no TaskRun or RunObject was found, nothing to be done. We never remove child references from the status. // We do still return an empty map of TaskRun/Run names keyed by PipelineTask name for later functions. diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index e619df1aee9..5bc880948e1 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -1446,8 +1446,18 @@ func TestReconcileOnCompletedPipelineRun(t *testing.T) { // and that does not have the latest status from TaskRuns yet. It checks that the TaskRun status is updated // in the PipelineRun status, that the completion status is not altered, that not error is returned and // a successful event is triggered - taskRunName := "test-pipeline-run-completed-hello-world" + taskRunName := "test-pipeline-run-completed-hello-world-task-run" + runName := "test-pipeline-run-completed-hello-world-run" pipelineRunName := "test-pipeline-run-completed" + rs := []*v1alpha1.Run{parse.MustParseRun(t, fmt.Sprintf(` +metadata: + name: %s +spec: {} +status: + conditions: + - status: "False" + type: Succeeded +`, runName))} prs := []*v1beta1.PipelineRun{parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(` metadata: name: %s @@ -1464,10 +1474,14 @@ status: status: "True" type: Succeeded childReferences: - - name: test-pipeline-run-completed-hello-world + - name: test-pipeline-run-completed-hello-world-task-run pipelineTaskName: hello-world-1 kind: TaskRun apiVersion: tekton.dev/v1beta1 + - name: test-pipeline-run-completed-hello-world-run + pipelineTaskName: hello-world-1 + kind: Run + apiVersion: tekton.dev/v1beta1 `, pipelineRunName))} ps := []*v1beta1.Pipeline{simpleHelloWorldPipeline} ts := []*v1beta1.Task{simpleHelloWorldTask} @@ -1484,6 +1498,13 @@ status: }, Name: taskRunName, PipelineTaskName: "hello-world-1", + }, { + TypeMeta: runtime.TypeMeta{ + APIVersion: v1beta1.SchemeGroupVersion.String(), + Kind: "Run", + }, + Name: runName, + PipelineTaskName: "hello-world-1", }} expectedTaskRunsStatus := make(map[string]*v1beta1.PipelineRunTaskRunStatus) @@ -1501,6 +1522,7 @@ status: Pipelines: ps, Tasks: ts, TaskRuns: trs, + Runs: rs, } prt := newPipelineRunTest(t, d) defer prt.Cancel() @@ -1771,13 +1793,11 @@ status: status: Unknown type: Succeeded startTime: "2021-12-31T00:00:00Z" - runs: - test-pipeline-run-custom-task-hello-world-1: - pipelineTaskName: hello-world-1 - status: - conditions: - - status: Unknown - type: Succeeded + childReferences: + - name: test-pipeline-run-custom-task-hello-world-1 + pipelineTaskName: hello-world-1 + kind: CustomRun + apiVersion: example.dev/v0 `)} prs[0].Spec.Timeout = tc.timeout prs[0].Spec.Timeouts = tc.timeouts @@ -2168,12 +2188,11 @@ status: status: Unknown reason: Running message: "running..." - taskRuns: - %s%s: - pipelineTaskName: %s - status: {} - startTime: %s -`, prName, v1beta1.PipelineRunSpecStatusCancelledRunFinally, ptName, prName, ptName, now.Format(time.RFC3339))), + childReferences: + - name: %s%s + pipelineTaskName: %s + kind: TaskRun +`, prName, v1beta1.PipelineRunSpecStatusCancelledRunFinally, ptName, prName, ptName)), } trs := []*v1beta1.TaskRun{ @@ -2490,14 +2509,10 @@ spec: pipeline: 12h0m0s status: startTime: "2021-12-31T00:00:00Z" - taskRuns: - test-pipeline-run-with-timeout-hello-world-1: - pipelineTaskName: hello-world-1 - status: - conditions: - - lastTransitionTime: null - status: "Unknown" - type: Succeeded + childReferences: + - name: test-pipeline-run-with-timeout-hello-world-1 + pipelineTaskName: hello-world-1 + kind: TaskRun `)} ts := []*v1beta1.Task{simpleHelloWorldTask} @@ -2583,14 +2598,10 @@ spec: tasks: 2m status: startTime: "2021-12-31T23:55:00Z" - taskRuns: - test-pipeline-run-with-timeout-hello-world-1: - pipelineTaskName: hello-world-1 - status: - conditions: - - lastTransitionTime: null - status: "Unknown" - type: Succeeded + childReferences: + - name: test-pipeline-run-with-timeout-hello-world-1 + pipelineTaskName: hello-world-1 + kind: TaskRun `)} ts := []*v1beta1.Task{simpleHelloWorldTask} @@ -4669,7 +4680,6 @@ spec: pipelineRef: name: test-pipeline status: - runs: {} pipelineSpec: results: - description: pipeline result @@ -4703,7 +4713,6 @@ status: value: aResultValue - name: custom-result value: bResultValue - taskRuns: {} childReferences: - apiVersion: tekton.dev/v1beta1 kind: TaskRun @@ -4828,7 +4837,6 @@ spec: pipelineRef: name: test-pipeline status: - runs: {} pipelineSpec: results: - description: pipeline result @@ -4857,7 +4865,6 @@ status: value: aResultValue - name: custom-result value: bResultValue - taskRuns: {} childReferences: - apiVersion: tekton.dev/v1beta1 kind: CustomRun @@ -5973,7 +5980,6 @@ func getPipelineRun(pr, p string, status corev1.ConditionStatus, reason string, }, }, }, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{}}, }, } for k, v := range tr { @@ -7989,8 +7995,6 @@ status: kind: TaskRun name: pr-platforms-and-browsers-8 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), }, { name: "p-finally", @@ -8146,8 +8150,6 @@ status: kind: TaskRun name: pr-platforms-and-browsers-8 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), }} for _, tt := range tests { @@ -8586,8 +8588,6 @@ status: kind: TaskRun name: pr-platforms-and-browsers-8 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), }, { name: "p-finally", @@ -8754,8 +8754,6 @@ status: kind: TaskRun name: pr-platforms-and-browsers-8 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), }} for _, tt := range tests { @@ -8935,8 +8933,6 @@ status: kind: TaskRun name: pr-platforms-and-browsers-1 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), }, expectedPipelineRun: parse.MustParseV1beta1PipelineRun(t, ` @@ -8981,8 +8977,6 @@ status: kind: TaskRun name: pr-platforms-and-browsers-1 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), expectedTaskRuns: []*v1beta1.TaskRun{ mustParseTaskRunWithObjectMeta(t, @@ -9129,8 +9123,6 @@ status: kind: TaskRun name: pr-platforms-and-browsers-1 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), }, expectedPipelineRun: parse.MustParseV1beta1PipelineRun(t, ` @@ -9175,8 +9167,6 @@ status: kind: TaskRun name: pr-platforms-and-browsers-1 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), expectedTaskRuns: []*v1beta1.TaskRun{ mustParseTaskRunWithObjectMeta(t, @@ -9590,8 +9580,6 @@ status: kind: CustomRun name: pr-platforms-and-browsers-8 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), }, { name: "p-finally", @@ -9748,8 +9736,6 @@ status: kind: CustomRun name: pr-platforms-and-browsers-8 pipelineTaskName: platforms-and-browsers - taskRuns: {} - runs: {} `), }} for _, tt := range tests { diff --git a/pkg/reconciler/pipelinerun/pipelinerun_updatestatus_test.go b/pkg/reconciler/pipelinerun/pipelinerun_updatestatus_test.go index d524e512ec5..21650f4be98 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_updatestatus_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_updatestatus_test.go @@ -104,329 +104,6 @@ pipelineTaskName: task-4 } } -func TestUpdatePipelineRunStatusFromTaskRuns(t *testing.T) { - prUID := types.UID("11111111-1111-1111-1111-111111111111") - - taskRunsPRStatusData := getUpdateStatusTaskRunsData(t) - - prRunningStatus := duckv1.Status{ - Conditions: []apis.Condition{ - { - Type: "Succeeded", - Status: "Unknown", - Reason: "Running", - Message: "Not all Tasks in the Pipeline have finished executing", - }, - }, - } - - prStatusWithNoTaskRuns := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: taskRunsPRStatusData.noTaskRuns, - }, - } - - prStatusMissingTaskRun := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: taskRunsPRStatusData.missingTaskRun, - }, - } - - prStatusFoundTaskRun := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: taskRunsPRStatusData.foundTaskRun, - }, - } - - prStatusWithEmptyTaskRuns := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{}, - }, - } - - prStatusWithOrphans := v1beta1.PipelineRunStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - { - Type: "Succeeded", - Status: "Unknown", - Reason: "Running", - Message: "Not all Tasks in the Pipeline have finished executing", - }, - }, - }, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{}, - }, - } - - prStatusRecovered := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: taskRunsPRStatusData.recovered, - }, - } - - prStatusRecoveredSimple := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: taskRunsPRStatusData.simple, - }, - } - - allTaskRuns, taskRunsFromAnotherPR, taskRunsWithNoOwner, _, _, _ := getTestTaskRunsAndRuns(t) - - tcs := []struct { - prName string - prStatus v1beta1.PipelineRunStatus - trs []*v1beta1.TaskRun - expectedPrStatus v1beta1.PipelineRunStatus - }{ - { - prName: "no-status-no-taskruns", - prStatus: v1beta1.PipelineRunStatus{}, - trs: nil, - expectedPrStatus: v1beta1.PipelineRunStatus{}, - }, { - prName: "status-no-taskruns", - prStatus: prStatusWithNoTaskRuns, - trs: nil, - expectedPrStatus: prStatusWithNoTaskRuns, - }, { - prName: "status-nil-taskruns", - prStatus: prStatusWithEmptyTaskRuns, - trs: []*v1beta1.TaskRun{parse.MustParseV1beta1TaskRun(t, ` -metadata: - labels: - tekton.dev/pipelineTask: task-1 - name: pr-task-1-xxyyy - ownerReferences: - - uid: 11111111-1111-1111-1111-111111111111 -`)}, - expectedPrStatus: prStatusRecoveredSimple, - }, { - prName: "status-missing-taskruns", - prStatus: prStatusMissingTaskRun, - trs: []*v1beta1.TaskRun{ - parse.MustParseV1beta1TaskRun(t, ` -metadata: - labels: - tekton.dev/pipelineTask: task-3 - name: pr-task-3-xxyyy - ownerReferences: - - uid: 11111111-1111-1111-1111-111111111111 -`), - }, - expectedPrStatus: prStatusFoundTaskRun, - }, { - prName: "status-matching-taskruns-pr", - prStatus: prStatusWithNoTaskRuns, - trs: allTaskRuns, - expectedPrStatus: prStatusWithNoTaskRuns, - }, { - prName: "orphaned-taskruns-pr", - prStatus: prStatusWithOrphans, - trs: allTaskRuns, - expectedPrStatus: prStatusRecovered, - }, { - prName: "tr-from-another-pr", - prStatus: prStatusWithEmptyTaskRuns, - trs: taskRunsFromAnotherPR, - expectedPrStatus: prStatusWithEmptyTaskRuns, - }, { - prName: "tr-with-no-owner", - prStatus: prStatusWithEmptyTaskRuns, - trs: taskRunsWithNoOwner, - expectedPrStatus: prStatusWithEmptyTaskRuns, - }, - } - - for _, tc := range tcs { - t.Run(tc.prName, func(t *testing.T) { - logger := logtesting.TestLogger(t) - - pr := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{Name: tc.prName, UID: prUID}, - Status: tc.prStatus, - } - - updatePipelineRunStatusFromTaskRuns(logger, pr, tc.trs) - actualPrStatus := pr.Status - - expectedPRStatus := tc.expectedPrStatus - - // The TaskRun keys for recovered taskruns will contain a new random key, appended to the - // base name that we expect. Replace the random part so we can diff the whole structure - actualTaskRuns := actualPrStatus.PipelineRunStatusFields.TaskRuns - if actualTaskRuns != nil { - fixedTaskRuns := make(map[string]*v1beta1.PipelineRunTaskRunStatus) - re := regexp.MustCompile(`^[a-z\-]*?-task-[0-9]`) - for k, v := range actualTaskRuns { - newK := re.FindString(k) - fixedTaskRuns[newK+"-xxyyy"] = v - } - actualPrStatus.PipelineRunStatusFields.TaskRuns = fixedTaskRuns - } - - if d := cmp.Diff(expectedPRStatus, actualPrStatus); d != "" { - t.Errorf("expected the PipelineRun status to match %#v. Diff %s", expectedPRStatus, diff.PrintWantGot(d)) - } - }) - } -} - -func TestUpdatePipelineRunStatusFromRuns(t *testing.T) { - prUID := types.UID("11111111-1111-1111-1111-111111111111") - - prRunningStatus := duckv1.Status{ - Conditions: []apis.Condition{ - { - Type: "Succeeded", - Status: "Unknown", - Reason: "Running", - Message: "Not all Tasks in the Pipeline have finished executing", - }, - }, - } - - prStatusWithSomeRuns := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - Runs: map[string]*v1beta1.PipelineRunRunStatus{ - "pr-run-1-xxyyy": { - PipelineTaskName: "run-1", - Status: &v1beta1.CustomRunStatus{}, - }, - "pr-run-2-xxyyy": { - PipelineTaskName: "run-2", - Status: nil, - }, - }, - }, - } - - prStatusWithAllRuns := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - Runs: map[string]*v1beta1.PipelineRunRunStatus{ - "pr-run-1-xxyyy": { - PipelineTaskName: "run-1", - Status: &v1beta1.CustomRunStatus{}, - }, - "pr-run-2-xxyyy": { - PipelineTaskName: "run-2", - Status: nil, - }, - "pr-run-3-xxyyy": { - PipelineTaskName: "run-3", - Status: &v1beta1.CustomRunStatus{}, - }, - }, - }, - } - - prStatusWithEmptyRuns := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - Runs: map[string]*v1beta1.PipelineRunRunStatus{}, - }, - } - - prStatusRecoveredSimple := v1beta1.PipelineRunStatus{ - Status: prRunningStatus, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - Runs: map[string]*v1beta1.PipelineRunRunStatus{ - "pr-run-1-xxyyy": { - PipelineTaskName: "run-1", - Status: &v1beta1.CustomRunStatus{}, - }, - }, - }, - } - - _, _, _, allRuns, runsFromAnotherPR, runsWithNoOwner := getTestTaskRunsAndRuns(t) - - tcs := []struct { - prName string - prStatus v1beta1.PipelineRunStatus - runs []v1beta1.RunObject - expectedPrStatus v1beta1.PipelineRunStatus - }{ - { - prName: "no-status-no-runs", - prStatus: v1beta1.PipelineRunStatus{}, - runs: nil, - expectedPrStatus: v1beta1.PipelineRunStatus{}, - }, { - prName: "status-no-runs", - prStatus: prStatusWithSomeRuns, - runs: nil, - expectedPrStatus: prStatusWithSomeRuns, - }, { - prName: "status-nil-runs", - prStatus: prStatusWithEmptyRuns, - runs: []v1beta1.RunObject{parse.MustParseCustomRun(t, ` -metadata: - labels: - tekton.dev/pipelineTask: run-1 - name: pr-run-1-xxyyy - ownerReferences: - - uid: 11111111-1111-1111-1111-111111111111 -`)}, - expectedPrStatus: prStatusRecoveredSimple, - }, { - prName: "status-missing-runs", - prStatus: prStatusWithSomeRuns, - runs: []v1beta1.RunObject{parse.MustParseCustomRun(t, ` -metadata: - labels: - tekton.dev/pipelineTask: run-3 - name: pr-run-3-xxyyy - ownerReferences: - - uid: 11111111-1111-1111-1111-111111111111 -`)}, - expectedPrStatus: prStatusWithAllRuns, - }, { - prName: "status-matching-runs-pr", - prStatus: prStatusWithAllRuns, - runs: allRuns, - expectedPrStatus: prStatusWithAllRuns, - }, { - prName: "run-from-another-pr", - prStatus: prStatusWithEmptyRuns, - runs: runsFromAnotherPR, - expectedPrStatus: prStatusWithEmptyRuns, - }, { - prName: "run-with-no-owner", - prStatus: prStatusWithEmptyRuns, - runs: runsWithNoOwner, - expectedPrStatus: prStatusWithEmptyRuns, - }, - } - - for _, tc := range tcs { - t.Run(tc.prName, func(t *testing.T) { - logger := logtesting.TestLogger(t) - - pr := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{Name: tc.prName, UID: prUID}, - Status: tc.prStatus, - } - - updatePipelineRunStatusFromCustomRunsOrRuns(logger, pr, tc.runs) - actualPrStatus := pr.Status - - if d := cmp.Diff(tc.expectedPrStatus, actualPrStatus); d != "" { - t.Errorf("expected the PipelineRun status to match %#v. Diff %s", tc.expectedPrStatus, diff.PrintWantGot(d)) - } - }) - } -} - type updateStatusChildRefsData struct { noTaskRuns []v1beta1.ChildStatusReference missingTaskRun []v1beta1.ChildStatusReference diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go index d8d91299804..c0b28df0ecd 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go @@ -665,7 +665,7 @@ func ResolvePipelineTask( } } case rpt.IsCustomTask(): - rpt.RunObjectName = getRunName(pipelineRun.Status.Runs, pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name) + rpt.RunObjectName = getRunName(pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name) run, err := getRun(rpt.RunObjectName) if err != nil && !kerrors.IsNotFound(err) { return nil, fmt.Errorf("error retrieving RunObject %s: %w", rpt.RunObjectName, err) @@ -681,7 +681,7 @@ func ResolvePipelineTask( } } default: - rpt.TaskRunName = GetTaskRunName(pipelineRun.Status.TaskRuns, pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name) + rpt.TaskRunName = GetTaskRunName(pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name) if err := rpt.resolvePipelineRunTaskWithTaskRun(ctx, rpt.TaskRunName, getTask, getTaskRun, pipelineTask, providedResources); err != nil { return nil, err } @@ -786,19 +786,12 @@ func resolveTask( } // GetTaskRunName should return a unique name for a `TaskRun` if one has not already been defined, and the existing one otherwise. -func GetTaskRunName(taskRunsStatus map[string]*v1beta1.PipelineRunTaskRunStatus, childRefs []v1beta1.ChildStatusReference, ptName, prName string) string { +func GetTaskRunName(childRefs []v1beta1.ChildStatusReference, ptName, prName string) string { for _, cr := range childRefs { if cr.Kind == pipeline.TaskRunControllerName && cr.PipelineTaskName == ptName { return cr.Name } } - - for k, v := range taskRunsStatus { - if v.PipelineTaskName == ptName { - return k - } - } - return kmeta.ChildName(prName, fmt.Sprintf("-%s", ptName)) } @@ -831,7 +824,7 @@ func getNewTaskRunNames(ptName, prName string, combinationCount int) []string { // getRunName should return a unique name for a `Run` if one has not already // been defined, and the existing one otherwise. -func getRunName(runsStatus map[string]*v1beta1.PipelineRunRunStatus, childRefs []v1beta1.ChildStatusReference, ptName, prName string) string { +func getRunName(childRefs []v1beta1.ChildStatusReference, ptName, prName string) string { for _, cr := range childRefs { if cr.PipelineTaskName == ptName { if cr.Kind == pipeline.CustomRunControllerName || cr.Kind == pipeline.RunControllerName { @@ -840,12 +833,6 @@ func getRunName(runsStatus map[string]*v1beta1.PipelineRunRunStatus, childRefs [ } } - for k, v := range runsStatus { - if v.PipelineTaskName == ptName { - return k - } - } - return kmeta.ChildName(prName, fmt.Sprintf("-%s", ptName)) } diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index d816283fc37..9f335a18761 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -2381,11 +2381,6 @@ func TestResolvePipelineRun_withExistingTaskRuns(t *testing.T) { }, } providedResources := map[string]*resourcev1alpha1.PipelineResource{"git-resource": r} - taskrunStatus := map[string]*v1beta1.PipelineRunTaskRunStatus{} - taskrunStatus["pipelinerun-mytask-with-a-really-long-name-to-trigger-tru"] = &v1beta1.PipelineRunTaskRunStatus{ - PipelineTaskName: "mytask-with-a-really-long-name-to-trigger-truncation", - Status: &v1beta1.TaskRunStatus{}, - } pr := v1beta1.PipelineRun{ ObjectMeta: metav1.ObjectMeta{ @@ -2393,7 +2388,11 @@ func TestResolvePipelineRun_withExistingTaskRuns(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: taskrunStatus, + ChildReferences: []v1beta1.ChildStatusReference{{ + Name: "pipelinerun-mytask-with-a-really-long-name-to-trigger-tru", + PipelineTaskName: "mytask-with-a-really-long-name-to-trigger-truncation", + TypeMeta: runtime.TypeMeta{Kind: "TaskRun"}, + }}, }, }, } @@ -2426,7 +2425,6 @@ func TestResolvePipelineRun_withExistingTaskRuns(t *testing.T) { t.Fatalf("Expected to get current pipeline state %v, but actual differed %s", expectedTask, diff.PrintWantGot(d)) } } - func TestResolvedPipelineRun_PipelineTaskHasOptionalResources(t *testing.T) { names.TestingSeed() p := &v1beta1.Pipeline{ @@ -3372,11 +3370,7 @@ func TestResolvedPipelineRunTask_IsFinalTask(t *testing.T) { func TestGetTaskRunName(t *testing.T) { prName := "pipeline-run" - taskRunsStatus := map[string]*v1beta1.PipelineRunTaskRunStatus{ - "taskrun-for-task1": { - PipelineTaskName: "task1", - }, - } + childRefs := []v1beta1.ChildStatusReference{{ TypeMeta: runtime.TypeMeta{Kind: "TaskRun"}, Name: "taskrun-for-task1", @@ -3416,11 +3410,7 @@ func TestGetTaskRunName(t *testing.T) { if tc.prName != "" { testPrName = tc.prName } - trNameFromTRStatus := GetTaskRunName(taskRunsStatus, nil, tc.ptName, testPrName) - if d := cmp.Diff(tc.wantTrName, trNameFromTRStatus); d != "" { - t.Errorf("GetTaskRunName: %s", diff.PrintWantGot(d)) - } - trNameFromChildRefs := GetTaskRunName(nil, childRefs, tc.ptName, testPrName) + trNameFromChildRefs := GetTaskRunName(childRefs, tc.ptName, testPrName) if d := cmp.Diff(tc.wantTrName, trNameFromChildRefs); d != "" { t.Errorf("GetTaskRunName: %s", diff.PrintWantGot(d)) } @@ -3556,11 +3546,6 @@ func TestGetNamesOfRuns(t *testing.T) { func TestGetRunName(t *testing.T) { prName := "pipeline-run" - runsStatus := map[string]*v1beta1.PipelineRunRunStatus{ - "run-for-task1": { - PipelineTaskName: "task1", - }, - } childRefs := []v1beta1.ChildStatusReference{{ TypeMeta: runtime.TypeMeta{Kind: "CustomRun"}, Name: "run-for-task1", @@ -3600,15 +3585,11 @@ func TestGetRunName(t *testing.T) { if tc.prName != "" { testPrName = tc.prName } - rnFromRunsStatus := getRunName(runsStatus, nil, tc.ptName, testPrName) - if d := cmp.Diff(tc.wantTrName, rnFromRunsStatus); d != "" { - t.Errorf("GetTaskRunName: %s", diff.PrintWantGot(d)) - } - rnFromChildRefs := getRunName(nil, childRefs, tc.ptName, testPrName) + rnFromChildRefs := getRunName(childRefs, tc.ptName, testPrName) if d := cmp.Diff(tc.wantTrName, rnFromChildRefs); d != "" { t.Errorf("GetTaskRunName: %s", diff.PrintWantGot(d)) } - rnFromBoth := getRunName(runsStatus, childRefs, tc.ptName, testPrName) + rnFromBoth := getRunName(childRefs, tc.ptName, testPrName) if d := cmp.Diff(tc.wantTrName, rnFromBoth); d != "" { t.Errorf("GetTaskRunName: %s", diff.PrintWantGot(d)) } diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go b/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go index ff911914b8a..10a2d6cfbd2 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go @@ -24,7 +24,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - runv1beta1 "github.com/tektoncd/pipeline/pkg/apis/run/v1beta1" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -150,44 +149,6 @@ func (state PipelineRunState) AdjustStartTime(unadjustedStartTime *metav1.Time) return adjustedStartTime.DeepCopy() } -// GetTaskRunsStatus returns a map of taskrun name and the taskrun -// ignore a nil taskrun in pipelineRunState, otherwise, capture taskrun object from PipelineRun Status -// update taskrun status based on the pipelineRunState before returning it in the map -func (state PipelineRunState) GetTaskRunsStatus(pr *v1beta1.PipelineRun) map[string]*v1beta1.PipelineRunTaskRunStatus { - status := make(map[string]*v1beta1.PipelineRunTaskRunStatus) - for _, rpt := range state { - if rpt.IsCustomTask() { - continue - } - - if rpt.TaskRun == nil { - continue - } - - status[rpt.TaskRunName] = rpt.getTaskRunStatus(rpt.TaskRun, pr) - } - return status -} - -func (t *ResolvedPipelineTask) getTaskRunStatus(tr *v1beta1.TaskRun, pr *v1beta1.PipelineRun) *v1beta1.PipelineRunTaskRunStatus { - var prtrs *v1beta1.PipelineRunTaskRunStatus - if tr != nil { - prtrs = pr.Status.TaskRuns[tr.Name] - } - if prtrs == nil { - prtrs = &v1beta1.PipelineRunTaskRunStatus{ - PipelineTaskName: t.PipelineTask.Name, - WhenExpressions: t.PipelineTask.WhenExpressions, - } - } - - if tr != nil { - prtrs.Status = &tr.Status - } - - return prtrs -} - // GetTaskRunsResults returns a map of all successfully completed TaskRuns in the state, with the pipeline task name as // the key and the results from the corresponding TaskRun as the value. It only includes tasks which have completed successfully. func (state PipelineRunState) GetTaskRunsResults() map[string][]v1beta1.TaskRunResult { @@ -206,42 +167,6 @@ func (state PipelineRunState) GetTaskRunsResults() map[string][]v1beta1.TaskRunR return results } -// GetRunsStatus returns a map of run name and the run. -// Ignore a nil run in pipelineRunState, otherwise, capture run object from PipelineRun Status. -// Update run status based on the pipelineRunState before returning it in the map. -func (state PipelineRunState) GetRunsStatus(pr *v1beta1.PipelineRun) map[string]*v1beta1.PipelineRunRunStatus { - status := map[string]*v1beta1.PipelineRunRunStatus{} - for _, rpt := range state { - if !rpt.IsCustomTask() { - continue - } - - if rpt.RunObject == nil { - continue - } - - prrs := pr.Status.Runs[rpt.RunObjectName] - - if prrs == nil { - prrs = &v1beta1.PipelineRunRunStatus{ - PipelineTaskName: rpt.PipelineTask.Name, - WhenExpressions: rpt.PipelineTask.WhenExpressions, - } - } - prrs.Status = &v1beta1.CustomRunStatus{} - switch r := rpt.RunObject.(type) { - case *v1beta1.CustomRun: - prrs.Status = &r.Status - case *v1alpha1.Run: - crs := runv1beta1.FromRunStatus(r.Status) - prrs.Status = &crs - } - - status[rpt.RunObjectName] = prrs - } - return status -} - // GetRunsResults returns a map of all successfully completed Runs in the state, with the pipeline task name as the key // and the results from the corresponding TaskRun as the value. It only includes runs which have completed successfully. func (state PipelineRunState) GetRunsResults() map[string][]v1beta1.CustomRunResult { diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go index c02a79b3c0b..8a51e727b3e 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go @@ -25,7 +25,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" "github.com/tektoncd/pipeline/test/diff" @@ -2544,198 +2543,6 @@ func TestPipelineRunFacts_IsRunning(t *testing.T) { } } -// TestUpdateTaskRunsState runs "getTaskRunsStatus" and verifies how it updates a PipelineRun status -// from a TaskRun associated to the PipelineRun -func TestUpdateTaskRunsState(t *testing.T) { - pr := parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: test-pipeline-run - namespace: foo -spec: - pipelineRef: - name: test-pipeline -`) - - pipelineTask := v1beta1.PipelineTask{ - Name: "unit-test-1", - WhenExpressions: []v1beta1.WhenExpression{{ - Input: "foo", - Operator: selection.In, - Values: []string{"foo", "bar"}, - }}, - TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"}, - } - unscheduledPipelineTask := v1beta1.PipelineTask{ - Name: "unit-test-2", - WhenExpressions: []v1beta1.WhenExpression{{ - Input: "foo", - Operator: selection.In, - Values: []string{"foo", "bar"}, - }}, - TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"}, - } - - task := parse.MustParseV1beta1Task(t, fmt.Sprintf(` -metadata: - name: unit-test-task - namespace: foo -spec: - resources: - inputs: - - name: workspace - type: %s -`, resourcev1alpha1.PipelineResourceTypeGit)) - - taskrun := parse.MustParseV1beta1TaskRun(t, ` -metadata: - name: test-pipeline-run-success-unit-test-1 - namespace: foo -spec: - taskRef: - name: unit-test-task - serviceAccountName: test-sa - timeout: 1h0m0s -status: - conditions: - - type: Succeeded - steps: - - container: - terminated: - exitCode: 0 -`) - - state := PipelineRunState{{ - PipelineTask: &pipelineTask, - TaskRunName: "test-pipeline-run-success-unit-test-1", - TaskRun: taskrun, - ResolvedTaskResources: &resources.ResolvedTaskResources{ - TaskSpec: &task.Spec, - }, - }, { - PipelineTask: &unscheduledPipelineTask, - TaskRunName: "test-pipeline-run-success-unit-test-2", - ResolvedTaskResources: &resources.ResolvedTaskResources{ - TaskSpec: &task.Spec, - }, - }} - pr.Status.InitializeConditions(testClock) - status := state.GetTaskRunsStatus(pr) - - expectedPipelineRunStatus := parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: pipelinerun - namespace: foo -status: - taskRuns: - test-pipeline-run-success-unit-test-1: - pipelineTaskName: unit-test-1 - status: - conditions: - - type: Succeeded - steps: - - container: - terminated: - exitCode: 0 - whenExpressions: - - input: foo - operator: in - values: ["foo", "bar"] -`) - - if d := cmp.Diff(expectedPipelineRunStatus.Status.TaskRuns, status); d != "" { - t.Fatalf("Expected PipelineRun status to match TaskRun(s) status, but got a mismatch: %s", diff.PrintWantGot(d)) - } -} - -// TestUpdateRunsState runs "getRunsStatus" and verifies how it updates a PipelineRun status -// from a Run associated to the PipelineRun -func TestUpdateRunsState(t *testing.T) { - pr := parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: test-pipeline-run - namespace: foo -spec: - pipelineRef: - name: test-pipeline -`) - - pipelineTask := v1beta1.PipelineTask{ - Name: "unit-test-1", - WhenExpressions: []v1beta1.WhenExpression{{ - Input: "foo", - Operator: selection.In, - Values: []string{"foo", "bar"}, - }}, - TaskRef: &v1beta1.TaskRef{ - APIVersion: "example.dev/v0", - Kind: "Example", - Name: "unit-test-run", - }, - } - unscheduledPipelineTask := v1beta1.PipelineTask{ - Name: "unit-test-2", - WhenExpressions: []v1beta1.WhenExpression{{ - Input: "foo", - Operator: selection.In, - Values: []string{"foo", "bar"}, - }}, - TaskRef: &v1beta1.TaskRef{ - APIVersion: "example.dev/v0", - Kind: "Example", - Name: "unit-test-run", - }, - } - - run := parse.MustParseCustomRun(t, ` -metadata: - name: unit-test-run - namespace: foo -status: - conditions: - - type: Succeeded - status: "True" -`) - - state := PipelineRunState{{ - PipelineTask: &pipelineTask, - CustomTask: true, - RunObjectName: "test-pipeline-run-success-unit-test-1", - RunObject: run, - }, { - PipelineTask: &unscheduledPipelineTask, - CustomTask: true, - RunObjectName: "test-pipeline-run-success-unit-test-2", - }} - pr.Status.InitializeConditions(testClock) - status := state.GetRunsStatus(pr) - - expectedPipelineRunStatus := parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: pipelinerun - namespace: foo -status: - runs: - test-pipeline-run-success-unit-test-1: - pipelineTaskName: unit-test-1 - status: - conditions: - - type: Succeeded - status: "True" - steps: - - container: - terminated: - exitCode: 0 - whenExpressions: - - input: foo - operator: in - values: ["foo", "bar"] -`) - - if d := cmp.Diff(expectedPipelineRunStatus.Status.Runs, status); d != "" { - t.Fatalf("Expected PipelineRun status to match Run(s) status, but got a mismatch: %s", diff.PrintWantGot(d)) - } -} - func TestPipelineRunState_GetResultsFuncs(t *testing.T) { state := PipelineRunState{{ TaskRunName: "successful-task-with-results", diff --git a/pkg/reconciler/pipelinerun/timeout_test.go b/pkg/reconciler/pipelinerun/timeout_test.go index 4cb530a41fc..520c8b0c91f 100644 --- a/pkg/reconciler/pipelinerun/timeout_test.go +++ b/pkg/reconciler/pipelinerun/timeout_test.go @@ -56,9 +56,6 @@ func TestTimeoutPipelineRun(t *testing.T) { Name: "t1", PipelineTaskName: "task-1", }}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "t1": {PipelineTaskName: "task-1"}, - }, }}, }, taskRuns: []*v1beta1.TaskRun{ @@ -100,10 +97,6 @@ func TestTimeoutPipelineRun(t *testing.T) { Name: "t2", PipelineTaskName: "task-2", }}, - Runs: map[string]*v1beta1.PipelineRunRunStatus{ - "t1": {PipelineTaskName: "task-1"}, - "t2": {PipelineTaskName: "task-2"}, - }, }}, }, customRuns: []*v1beta1.CustomRun{ diff --git a/test/propagated_params_test.go b/test/propagated_params_test.go index 1f5ed8087d0..227aaff6e8a 100644 --- a/test/propagated_params_test.go +++ b/test/propagated_params_test.go @@ -39,7 +39,7 @@ var ( ignoreTypeMeta = cmpopts.IgnoreFields(metav1.TypeMeta{}, "Kind", "APIVersion") ignoreObjectMeta = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion", "UID", "CreationTimestamp", "Generation", "ManagedFields", "Labels", "Annotations", "OwnerReferences") ignoreCondition = cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime.Inner.Time", "Message") - ignorePipelineRunStatus = cmpopts.IgnoreFields(v1beta1.PipelineRunStatusFields{}, "StartTime", "CompletionTime", "FinallyStartTime", "ChildReferences", "TaskRuns") + ignorePipelineRunStatus = cmpopts.IgnoreFields(v1beta1.PipelineRunStatusFields{}, "StartTime", "CompletionTime", "FinallyStartTime", "ChildReferences") ignoreTaskRunStatus = cmpopts.IgnoreFields(v1beta1.TaskRunStatusFields{}, "StartTime", "CompletionTime") ignoreConditions = cmpopts.IgnoreFields(duckv1.Status{}, "Conditions") ignoreContainerStates = cmpopts.IgnoreFields(corev1.ContainerState{}, "Terminated")