Skip to content

Commit

Permalink
cluster task is not custom task
Browse files Browse the repository at this point in the history
This commit closes #6682. When apiversion and kind are both set for
taskref, the task is considered to ba a custom task. For v1beta1 cluster
task, it is also considered to be a custom task. This commit fixes this.

Signed-off-by: Yongxuan Zhang [email protected]
  • Loading branch information
Yongxuanzhang committed May 23, 2023
1 parent 96212a1 commit b7806f4
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 2 deletions.
54 changes: 54 additions & 0 deletions examples/v1beta1/pipelineruns/6682-regression.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/taskref_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskref_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
49 changes: 49 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit b7806f4

Please sign in to comment.