diff --git a/examples/v1beta1/pipelineruns/6682-regression.yaml b/examples/v1beta1/pipelineruns/6682-regression.yaml new file mode 100644 index 00000000000..12811c1d4fa --- /dev/null +++ b/examples/v1beta1/pipelineruns/6682-regression.yaml @@ -0,0 +1,54 @@ +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: dummy-pipeline + namespace: default +spec: + tasks: + - name: init + params: + - name: resource + value: resouce + taskRef: + apiVersion: tekton.dev/v1beta1 + kind: ClusterTask + name: init + workspaces: + - name: output + workspace: shared + workspaces: + - description: Main workspace that is shared across each task in the build pipeline + name: shared +--- +apiVersion: tekton.dev/v1beta1 +kind: ClusterTask +metadata: + name: init +spec: + workspaces: + - name: output + params: + - name: resource + type: string + steps: + - name: hello + image: registry.access.redhat.com/ubi9-micro:latest + args: ["$(params.resource)"] + command: ["echo"] +--- +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: dummy +spec: + pipelineRef: + name: dummy-pipeline + workspaces: + - name: shared + volumeClaimTemplate: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Mi diff --git a/pkg/apis/pipeline/v1beta1/pipeline_types.go b/pkg/apis/pipeline/v1beta1/pipeline_types.go index 84e030ec453..ff8f94f4813 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_types.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_types.go @@ -224,7 +224,7 @@ type PipelineTask struct { func (et *EmbeddedTask) IsCustomTask() bool { // Note that if `apiVersion` is set to `"tekton.dev/v1beta1"` and `kind` is set to `"Task"`, // the reference will be considered a Custom Task - https://github.com/tektoncd/pipeline/issues/6457 - return et != nil && et.APIVersion != "" && et.Kind != "" + return et != nil && et.APIVersion != "" && et.Kind != "" && et.Kind != string(ClusterTaskKind) } // IsMatrixed return whether pipeline task is matrixed diff --git a/pkg/apis/pipeline/v1beta1/pipeline_types_test.go b/pkg/apis/pipeline/v1beta1/pipeline_types_test.go index f137ae152a6..84b05467f52 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_types_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_types_test.go @@ -940,6 +940,15 @@ func TestEmbeddedTask_IsCustomTask(t *testing.T) { }, }, want: true, + }, { + name: "custom task - clustertask is not customtask", + et: &EmbeddedTask{ + TypeMeta: runtime.TypeMeta{ + Kind: string(ClusterTaskKind), + APIVersion: "example/v0", + }, + }, + want: false, }, } for _, tt := range tests { diff --git a/pkg/apis/pipeline/v1beta1/taskref_types.go b/pkg/apis/pipeline/v1beta1/taskref_types.go index f8f231cd961..2ffa1e0d88c 100644 --- a/pkg/apis/pipeline/v1beta1/taskref_types.go +++ b/pkg/apis/pipeline/v1beta1/taskref_types.go @@ -58,5 +58,5 @@ const ( func (tr *TaskRef) IsCustomTask() bool { // Note that if `apiVersion` is set to `"tekton.dev/v1beta1"` and `kind` is set to `"Task"`, // the reference will be considered a Custom Task - https://github.com/tektoncd/pipeline/issues/6457 - return tr != nil && tr.APIVersion != "" && tr.Kind != "" + return tr != nil && tr.APIVersion != "" && tr.Kind != "" && tr.Kind != ClusterTaskKind } diff --git a/pkg/apis/pipeline/v1beta1/taskref_types_test.go b/pkg/apis/pipeline/v1beta1/taskref_types_test.go index 6666556003d..426d99edc73 100644 --- a/pkg/apis/pipeline/v1beta1/taskref_types_test.go +++ b/pkg/apis/pipeline/v1beta1/taskref_types_test.go @@ -48,6 +48,13 @@ func TestTaskRef_IsCustomTask(t *testing.T) { APIVersion: "example/v0", }, want: false, + }, { + name: "not a custom task - kind is clustertask", + tr: &v1beta1.TaskRef{ + Name: string(v1beta1.ClusterTaskKind), + APIVersion: "example/v0", + }, + want: false, }, { name: "custom task with name", tr: &v1beta1.TaskRef{ diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 23c6fe72e58..dd77ab3c3b5 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -11791,3 +11791,52 @@ spec: t.Errorf("Expected PipelineRun to still be Succeeded, but reason is %s", reconciledRun.Status.GetCondition(apis.ConditionSucceeded)) } } + +func TestReconcileClusterTaskWithApiVersion(t *testing.T) { + ps := []*v1beta1.Pipeline{parse.MustParseV1beta1Pipeline(t, ` +metadata: + name: test-pipeline + namespace: foo +spec: + tasks: + - name: unit-test-cluster-task + taskRef: + name: unit-test-cluster-task + apiversion: tekton.dev/v1beta1 + kind: ClusterTask +`)} + prs := []*v1beta1.PipelineRun{parse.MustParseV1beta1PipelineRun(t, ` +metadata: + name: test-pipeline-run-with-clustertask + namespace: foo +spec: + pipelineRef: + name: test-pipeline + serviceAccountName: test-sa +`)} + + clusterTasks := []*v1beta1.ClusterTask{ + parse.MustParseClusterTask(t, ` +metadata: + name: unit-test-cluster-task +spec: + steps: + - image: ubuntu + script: | + #!/usr/bin/env bash + echo "Hello from bash!" +`)} + + d := test.Data{ + PipelineRuns: prs, + Pipelines: ps, + ClusterTasks: clusterTasks, + } + prt := newPipelineRunTest(t, d) + defer prt.Cancel() + + wantEvents := []string{} + reconciledRun, _ := prt.reconcileRun("foo", "test-pipeline-run-with-clustertask", wantEvents, false) + + checkPipelineRunConditionStatusAndReason(t, reconciledRun, corev1.ConditionUnknown, v1beta1.PipelineRunReasonRunning.String()) +}