Skip to content

Commit

Permalink
fix: refine error resean with invalid pipelinename in taskrunspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
cugykw authored and tekton-robot committed Aug 16, 2023
1 parent 7554dcd commit 7884311
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ const (
// ReasonInvalidWorkspaceBinding indicates that a Pipeline expects a workspace but a
// PipelineRun has provided an invalid binding.
ReasonInvalidWorkspaceBinding = "InvalidWorkspaceBindings"
// ReasonInvalidServiceAccountMapping indicates that PipelineRun.Spec.TaskRunSpecs[].TaskServiceAccountName is defined with a wrong taskName
ReasonInvalidServiceAccountMapping = "InvalidServiceAccountMappings"
// ReasonInvalidTaskRunSpec indicates that PipelineRun.Spec.TaskRunSpecs[].PipelineTaskName is defined with
// a not exist taskName in pipelineSpec.
ReasonInvalidTaskRunSpec = "InvalidTaskRunSpecs"
// ReasonParameterTypeMismatch indicates that the reason for the failure status is that
// parameter(s) declared in the PipelineRun do not have the some declared type as the
// parameters(s) declared in the Pipeline that they are supposed to override.
Expand Down Expand Up @@ -512,7 +513,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel

// Ensure that the TaskRunSpecs defined are correct.
if err := resources.ValidateTaskRunSpecs(pipelineSpec, pr); err != nil {
pr.Status.MarkFailed(ReasonInvalidServiceAccountMapping,
pr.Status.MarkFailed(ReasonInvalidTaskRunSpec,
"PipelineRun %s/%s doesn't define taskRunSpecs correctly: %s",
pr.Namespace, pr.Name, err)
return controller.NewPermanentError(err)
Expand Down
21 changes: 21 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7049,6 +7049,24 @@ spec:
params:
- name: platform
value: linux
`),
parse.MustParseV1PipelineRun(t, `
metadata:
name: pipelinerun-with-invalid-taskrunspecs
namespace: foo
spec:
taskRunSpecs:
- metadata:
annotations:
env: test
pipelineTaskName: invalid-task-name
pipelineSpec:
tasks:
- name: pt0
taskSpec:
steps:
- image: foo:latest
serviceAccountName: test-sa
`),
}

Expand Down Expand Up @@ -7080,6 +7098,9 @@ spec:
}, {
name: "pipelinerun-matrix-param-invalid-type",
reason: ReasonInvalidMatrixParameterTypes,
}, {
name: "pipelinerun-with-invalid-taskrunspecs",
reason: ReasonInvalidTaskRunSpec,
},
}
for _, tc := range testCases {
Expand Down

0 comments on commit 7884311

Please sign in to comment.