Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add FailureReason field for PipelineRun and TaskRun Status #7545

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/pipeline-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,19 @@ map[string]string
<p>SpanContext contains tracing span context fields</p>
</td>
</tr>
<tr>
<td>
<code>failureReason</code><br/>
<em>
string
</em>
</td>
<td>
<p>FailureReason stands for the granular PipelineRun failure reason.
It is the provisional status field for making breaking changes to the existing PipelineRunReasons. It will replace
the existing apis.Condition.Reason with the next major version bump.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1.PipelineRunTaskRunStatus">PipelineRunTaskRunStatus
Expand Down Expand Up @@ -5718,6 +5731,19 @@ map[string]string
<p>SpanContext contains tracing span context fields</p>
</td>
</tr>
<tr>
<td>
<code>failureReason</code><br/>
<em>
string
</em>
</td>
<td>
<p>FailureReason stands for the granular TaskRun failure reason.
It is the provisional status field for making breaking changes to the existing PipelineRunReasons. It will replace
the existing apis.Condition.Reason with the next major version bump.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1.TaskRunStepSpec">TaskRunStepSpec
Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/pipeline/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/apis/pipeline/v1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ const (
// ReasonInvalidTaskResultReference indicates a task result was declared
// but was not initialized by that task
PipelineRunReasonInvalidTaskResultReference PipelineRunReason = "InvalidTaskResultReference"
// PipelineRunReasonInvalidPipelineResultReference indicates a pipeline result was declared
// by the pipeline but not initialized in the pipelineTask
PipelineRunReasonInvalidPipelineResultReference PipelineRunReason = "InvalidPipelineResultReference"
// ReasonRequiredWorkspaceMarkedOptional indicates an optional workspace
// has been passed to a Task that is expecting a non-optional workspace
PipelineRunReasonRequiredWorkspaceMarkedOptional PipelineRunReason = "RequiredWorkspaceMarkedOptional"
Expand Down Expand Up @@ -470,6 +473,11 @@ func (pr *PipelineRunStatus) MarkFailed(reason, messageFormat string, messageA .
pr.CompletionTime = &succeeded.LastTransitionTime.Inner
}

// SetFailureReason sets PipelineRun failure reason that is more granular and precise
func (prs *PipelineRunStatus) SetFailureReason(reason TaskRunReason) {
prs.FailureReason = reason.String()
}

// MarkRunning changes the Succeeded condition to Unknown with the provided reason and message.
func (pr *PipelineRunStatus) MarkRunning(reason, messageFormat string, messageA ...interface{}) {
pipelineRunCondSet.Manage(pr).MarkUnknown(apis.ConditionSucceeded, reason, messageFormat, messageA...)
Expand Down Expand Up @@ -527,6 +535,11 @@ type PipelineRunStatusFields struct {

// SpanContext contains tracing span context fields
SpanContext map[string]string `json:"spanContext,omitempty"`

// FailureReason stands for the granular PipelineRun failure reason.
// It is the provisional status field for making breaking changes to the existing PipelineRunReasons. It will replace
// the existing apis.Condition.Reason with the next major version bump.
FailureReason string `json:"failureReason,omitempty"`
}

// SkippedTask is used to describe the Tasks that were skipped due to their When Expressions
Expand Down
16 changes: 16 additions & 0 deletions pkg/apis/pipeline/v1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@
"x-kubernetes-patch-merge-key": "type",
"x-kubernetes-patch-strategy": "merge"
},
"failureReason": {
"description": "FailureReason stands for the granular PipelineRun failure reason. It is the provisional status field for making breaking changes to the existing PipelineRunReasons. It will replace the existing apis.Condition.Reason with the next major version bump.",
"type": "string"
},
"finallyStartTime": {
"description": "FinallyStartTime is when all non-finally tasks have been completed and only finally tasks are being executed.",
"$ref": "#/definitions/v1.Time"
Expand Down Expand Up @@ -747,6 +751,10 @@
"description": "CompletionTime is the time the PipelineRun completed.",
"$ref": "#/definitions/v1.Time"
},
"failureReason": {
"description": "FailureReason stands for the granular PipelineRun failure reason. It is the provisional status field for making breaking changes to the existing PipelineRunReasons. It will replace the existing apis.Condition.Reason with the next major version bump.",
"type": "string"
},
"finallyStartTime": {
"description": "FinallyStartTime is when all non-finally tasks have been completed and only finally tasks are being executed.",
"$ref": "#/definitions/v1.Time"
Expand Down Expand Up @@ -2045,6 +2053,10 @@
"x-kubernetes-patch-merge-key": "type",
"x-kubernetes-patch-strategy": "merge"
},
"failureReason": {
"description": "FailureReason stands for the granular TaskRun failure reason. It is the provisional status field for making breaking changes to the existing PipelineRunReasons. It will replace the existing apis.Condition.Reason with the next major version bump.",
"type": "string"
},
"observedGeneration": {
"description": "ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.",
"type": "integer",
Expand Down Expand Up @@ -2124,6 +2136,10 @@
"description": "CompletionTime is the time the build completed.",
"$ref": "#/definitions/v1.Time"
},
"failureReason": {
"description": "FailureReason stands for the granular TaskRun failure reason. It is the provisional status field for making breaking changes to the existing PipelineRunReasons. It will replace the existing apis.Condition.Reason with the next major version bump.",
"type": "string"
},
"podName": {
"description": "PodName is the name of the pod responsible for executing this task's steps.",
"type": "string",
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/pipeline/v1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ func (trs *TaskRunStatus) MarkResourceFailed(reason TaskRunReason, err error) {
trs.CompletionTime = &succeeded.LastTransitionTime.Inner
}

// SetFailureReason sets TaskRun failure reason that is more granular and precise
// to the existing TaskRunReason
func (trs *TaskRunStatus) SetFailureReason(reason TaskRunReason) {
trs.FailureReason = reason.String()
}

// TaskRunStatusFields holds the fields of TaskRun's status. This is defined
// separately and inlined so that other types can readily consume these fields
// via duck typing.
Expand Down Expand Up @@ -291,6 +297,11 @@ type TaskRunStatusFields struct {

// SpanContext contains tracing span context fields
SpanContext map[string]string `json:"spanContext,omitempty"`

// FailureReason stands for the granular TaskRun failure reason.
// It is the provisional status field for making breaking changes to the existing PipelineRunReasons. It will replace
// the existing apis.Condition.Reason with the next major version bump.
FailureReason string `json:"failureReason,omitempty"`
}

// TaskRunStepSpec is used to override the values of a Step in the corresponding Task.
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
if err := resources.ValidatePipelineResults(pipelineSpec, pipelineRunFacts.State); err != nil {
logger.Errorf("Failed to resolve task result reference for %q with error %v", pr.Name, err)
pr.Status.MarkFailed(v1.PipelineRunReasonInvalidTaskResultReference.String(), err.Error())
pr.Status.SetFailureReason(v1.InvalidPipelineResultReference)
return controller.NewPermanentError(err)
}

Expand Down Expand Up @@ -794,7 +795,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
pr.Status.Results, err = resources.ApplyTaskResultsToPipelineResults(ctx, pipelineSpec.Results,
pipelineRunFacts.State.GetTaskRunsResults(), pipelineRunFacts.State.GetRunsResults(), taskStatus)
if err != nil {
pr.Status.MarkFailed(v1.PipelineRunReasonCouldntGetPipelineResult.String(),
pr.Status.MarkFailed(v1.PipelineRunReasonInvalidPipelineResultReference.String(),
"Failed to get PipelineResult from TaskRun Results for PipelineRun %s: %s",
pr.Name, err)
return err
Expand Down