Skip to content

Commit

Permalink
Cleanup: Move PipelineRun Reasons to pkg/apis
Browse files Browse the repository at this point in the history
Prior to this commit, strings that were set as "Reasons" in the PipelineRun status
were split between pkg/apis and pkg/reconciler/pipelinerun. This commit moves all PipelineRun
reasons to pkg/apis and adds aliases for backwards compatibility. This adds consistency,
correctly signals to clients that all Reasons are part of the API, and helps avoid circular imports.
  • Loading branch information
lbernick authored and tekton-robot committed Sep 13, 2023
1 parent 6cf7c5e commit 602e48e
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 82 deletions.
75 changes: 75 additions & 0 deletions docs/pipeline-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1944,12 +1944,87 @@ and no new Tasks will be scheduled by the controller, but final tasks are now ru
</tr><tr><td><p>&#34;Completed&#34;</p></td>
<td><p>PipelineRunReasonCompleted is the reason set when the PipelineRun completed successfully with one or more skipped Tasks</p>
</td>
</tr><tr><td><p>&#34;PipelineRunCouldntCancel&#34;</p></td>
<td><p>ReasonCouldntCancel indicates that a PipelineRun was cancelled but attempting to update
all of the running TaskRuns as cancelled failed.</p>
</td>
</tr><tr><td><p>&#34;CouldntGetPipeline&#34;</p></td>
<td><p>ReasonCouldntGetPipeline indicates that the reason for the failure status is that the
associated Pipeline couldn&rsquo;t be retrieved</p>
</td>
</tr><tr><td><p>&#34;CouldntGetTask&#34;</p></td>
<td><p>ReasonCouldntGetTask indicates that the reason for the failure status is that the
associated Pipeline&rsquo;s Tasks couldn&rsquo;t all be retrieved</p>
</td>
</tr><tr><td><p>&#34;PipelineRunCouldntTimeOut&#34;</p></td>
<td><p>ReasonCouldntTimeOut indicates that a PipelineRun was timed out but attempting to update
all of the running TaskRuns as timed out failed.</p>
</td>
</tr><tr><td><p>&#34;CreateRunFailed&#34;</p></td>
<td><p>ReasonCreateRunFailed indicates that the pipeline fails to create the taskrun or other run resources</p>
</td>
</tr><tr><td><p>&#34;Failed&#34;</p></td>
<td><p>PipelineRunReasonFailed is the reason set when the PipelineRun completed with a failure</p>
</td>
</tr><tr><td><p>&#34;PipelineValidationFailed&#34;</p></td>
<td><p>ReasonFailedValidation indicates that the reason for failure status is
that pipelinerun failed runtime validation</p>
</td>
</tr><tr><td><p>&#34;InvalidPipelineResourceBindings&#34;</p></td>
<td><p>ReasonInvalidBindings indicates that the reason for the failure status is that the
PipelineResources bound in the PipelineRun didn&rsquo;t match those declared in the Pipeline</p>
</td>
</tr><tr><td><p>&#34;PipelineInvalidGraph&#34;</p></td>
<td><p>ReasonInvalidGraph indicates that the reason for the failure status is that the
associated Pipeline is an invalid graph (a.k.a wrong order, cycle, …)</p>
</td>
</tr><tr><td><p>&#34;InvalidMatrixParameterTypes&#34;</p></td>
<td><p>ReasonInvalidMatrixParameterTypes indicates a matrix contains invalid parameter types</p>
</td>
</tr><tr><td><p>&#34;InvalidTaskResultReference&#34;</p></td>
<td><p>ReasonInvalidTaskResultReference indicates a task result was declared
but was not initialized by that task</p>
</td>
</tr><tr><td><p>&#34;InvalidTaskRunSpecs&#34;</p></td>
<td><p>ReasonInvalidTaskRunSpec indicates that PipelineRun.Spec.TaskRunSpecs[].PipelineTaskName is defined with
a not exist taskName in pipelineSpec.</p>
</td>
</tr><tr><td><p>&#34;InvalidWorkspaceBindings&#34;</p></td>
<td><p>ReasonInvalidWorkspaceBinding indicates that a Pipeline expects a workspace but a
PipelineRun has provided an invalid binding.</p>
</td>
</tr><tr><td><p>&#34;ObjectParameterMissKeys&#34;</p></td>
<td><p>ReasonObjectParameterMissKeys indicates that the object param value provided from PipelineRun spec
misses some keys required for the object param declared in Pipeline spec.</p>
</td>
</tr><tr><td><p>&#34;ParamArrayIndexingInvalid&#34;</p></td>
<td><p>ReasonParamArrayIndexingInvalid indicates that the use of param array indexing is not under correct api fields feature gate
or the array is out of bound.</p>
</td>
</tr><tr><td><p>&#34;ParameterMissing&#34;</p></td>
<td><p>ReasonParameterMissing indicates that the reason for the failure status is that the
associated PipelineRun didn&rsquo;t provide all the required parameters</p>
</td>
</tr><tr><td><p>&#34;ParameterTypeMismatch&#34;</p></td>
<td><p>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.</p>
</td>
</tr><tr><td><p>&#34;PipelineRunPending&#34;</p></td>
<td><p>PipelineRunReasonPending is the reason set when the PipelineRun is in the pending state</p>
</td>
</tr><tr><td><p>&#34;RequiredWorkspaceMarkedOptional&#34;</p></td>
<td><p>ReasonRequiredWorkspaceMarkedOptional indicates an optional workspace
has been passed to a Task that is expecting a non-optional workspace</p>
</td>
</tr><tr><td><p>&#34;ResolvingPipelineRef&#34;</p></td>
<td><p>ReasonResolvingPipelineRef indicates that the PipelineRun is waiting for
its pipelineRef to be asynchronously resolved.</p>
</td>
</tr><tr><td><p>&#34;ResourceVerificationFailed&#34;</p></td>
<td><p>ReasonResourceVerificationFailed indicates that the pipeline fails the trusted resource verification,
it could be the content has changed, signature is invalid or public key is invalid</p>
</td>
</tr><tr><td><p>&#34;Running&#34;</p></td>
<td><p>PipelineRunReasonRunning is the reason set when the PipelineRun is running</p>
</td>
Expand Down
56 changes: 56 additions & 0 deletions pkg/apis/pipeline/v1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,62 @@ const (
// PipelineRunReasonStoppedRunningFinally indicates that pipeline has been gracefully stopped
// and no new Tasks will be scheduled by the controller, but final tasks are now running
PipelineRunReasonStoppedRunningFinally PipelineRunReason = "StoppedRunningFinally"
// ReasonCouldntGetPipeline indicates that the reason for the failure status is that the
// associated Pipeline couldn't be retrieved
PipelineRunReasonCouldntGetPipeline PipelineRunReason = "CouldntGetPipeline"
// ReasonInvalidBindings indicates that the reason for the failure status is that the
// PipelineResources bound in the PipelineRun didn't match those declared in the Pipeline
PipelineRunReasonInvalidBindings PipelineRunReason = "InvalidPipelineResourceBindings"
// ReasonInvalidWorkspaceBinding indicates that a Pipeline expects a workspace but a
// PipelineRun has provided an invalid binding.
PipelineRunReasonInvalidWorkspaceBinding PipelineRunReason = "InvalidWorkspaceBindings"
// ReasonInvalidTaskRunSpec indicates that PipelineRun.Spec.TaskRunSpecs[].PipelineTaskName is defined with
// a not exist taskName in pipelineSpec.
PipelineRunReasonInvalidTaskRunSpec PipelineRunReason = "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.
PipelineRunReasonParameterTypeMismatch PipelineRunReason = "ParameterTypeMismatch"
// ReasonObjectParameterMissKeys indicates that the object param value provided from PipelineRun spec
// misses some keys required for the object param declared in Pipeline spec.
PipelineRunReasonObjectParameterMissKeys PipelineRunReason = "ObjectParameterMissKeys"
// ReasonParamArrayIndexingInvalid indicates that the use of param array indexing is not under correct api fields feature gate
// or the array is out of bound.
PipelineRunReasonParamArrayIndexingInvalid PipelineRunReason = "ParamArrayIndexingInvalid"
// ReasonCouldntGetTask indicates that the reason for the failure status is that the
// associated Pipeline's Tasks couldn't all be retrieved
PipelineRunReasonCouldntGetTask PipelineRunReason = "CouldntGetTask"
// ReasonParameterMissing indicates that the reason for the failure status is that the
// associated PipelineRun didn't provide all the required parameters
PipelineRunReasonParameterMissing PipelineRunReason = "ParameterMissing"
// ReasonFailedValidation indicates that the reason for failure status is
// that pipelinerun failed runtime validation
PipelineRunReasonFailedValidation PipelineRunReason = "PipelineValidationFailed"
// ReasonInvalidGraph indicates that the reason for the failure status is that the
// associated Pipeline is an invalid graph (a.k.a wrong order, cycle, …)
PipelineRunReasonInvalidGraph PipelineRunReason = "PipelineInvalidGraph"
// ReasonCouldntCancel indicates that a PipelineRun was cancelled but attempting to update
// all of the running TaskRuns as cancelled failed.
PipelineRunReasonCouldntCancel PipelineRunReason = "PipelineRunCouldntCancel"
// ReasonCouldntTimeOut indicates that a PipelineRun was timed out but attempting to update
// all of the running TaskRuns as timed out failed.
PipelineRunReasonCouldntTimeOut PipelineRunReason = "PipelineRunCouldntTimeOut"
// ReasonInvalidMatrixParameterTypes indicates a matrix contains invalid parameter types
PipelineRunReasonInvalidMatrixParameterTypes PipelineRunReason = "InvalidMatrixParameterTypes"
// ReasonInvalidTaskResultReference indicates a task result was declared
// but was not initialized by that task
PipelineRunReasonInvalidTaskResultReference PipelineRunReason = "InvalidTaskResultReference"
// ReasonRequiredWorkspaceMarkedOptional indicates an optional workspace
// has been passed to a Task that is expecting a non-optional workspace
PipelineRunReasonRequiredWorkspaceMarkedOptional PipelineRunReason = "RequiredWorkspaceMarkedOptional"
// ReasonResolvingPipelineRef indicates that the PipelineRun is waiting for
// its pipelineRef to be asynchronously resolved.
PipelineRunReasonResolvingPipelineRef PipelineRunReason = "ResolvingPipelineRef"
// ReasonResourceVerificationFailed indicates that the pipeline fails the trusted resource verification,
// it could be the content has changed, signature is invalid or public key is invalid
PipelineRunReasonResourceVerificationFailed PipelineRunReason = "ResourceVerificationFailed"
// ReasonCreateRunFailed indicates that the pipeline fails to create the taskrun or other run resources
PipelineRunReasonCreateRunFailed PipelineRunReason = "CreateRunFailed"
)

func (t PipelineRunReason) String() string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/pipelinerunmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ var (

const (
// ReasonCancelled indicates that a PipelineRun was cancelled.
ReasonCancelled = "Cancelled"
// Aliased for backwards compatibility; additional reasons should not be added here.
ReasonCancelled = v1.PipelineRunReasonCancelled
)

// Recorder holds keys for Tekton metrics
Expand Down Expand Up @@ -233,7 +234,7 @@ func (r *Recorder) DurationAndCount(pr *v1.PipelineRun, beforeCondition *apis.Co
status := "success"
if cond := pr.Status.GetCondition(apis.ConditionSucceeded); cond.Status == corev1.ConditionFalse {
status = "failed"
if cond.Reason == ReasonCancelled {
if cond.Reason == v1.PipelineRunReasonCancelled.String() {
status = "cancelled"
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipelinerunmetrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestRecordPipelineRunDurationCount(t *testing.T) {
Conditions: duckv1.Conditions{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: ReasonCancelled,
Reason: v1.PipelineRunReasonCancelled.String(),
}},
},
PipelineRunStatusFields: v1.PipelineRunStatusFields{
Expand Down
8 changes: 4 additions & 4 deletions pkg/reconciler/pipelinerun/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func cancelPipelineRun(ctx context.Context, logger *zap.SugaredLogger, pr *v1.Pi

// If we successfully cancelled all the TaskRuns and Runs, we can consider the PipelineRun cancelled.
if len(errs) == 0 {
reason := ReasonCancelled
reason := v1.PipelineRunReasonCancelled

pr.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: reason,
Reason: reason.String(),
Message: fmt.Sprintf("PipelineRun %q was cancelled", pr.Name),
})
// update pr completed time
Expand All @@ -113,7 +113,7 @@ func cancelPipelineRun(ctx context.Context, logger *zap.SugaredLogger, pr *v1.Pi
pr.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Reason: ReasonCouldntCancel,
Reason: v1.PipelineRunReasonCouldntCancel.String(),
Message: fmt.Sprintf("PipelineRun %q was cancelled but had errors trying to cancel TaskRuns and/or Runs: %s", pr.Name, e),
})
return fmt.Errorf("error(s) from cancelling TaskRun(s) from PipelineRun %s: %s", pr.Name, e)
Expand Down Expand Up @@ -194,7 +194,7 @@ func gracefullyCancelPipelineRun(ctx context.Context, logger *zap.SugaredLogger,
pr.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Reason: ReasonCouldntCancel,
Reason: v1.PipelineRunReasonCouldntCancel.String(),
Message: fmt.Sprintf("PipelineRun %q was cancelled but had errors trying to cancel TaskRuns and/or Runs: %s", pr.Name, e),
})
return fmt.Errorf("error(s) from cancelling TaskRun(s) from PipelineRun %s: %s", pr.Name, e)
Expand Down
Loading

0 comments on commit 602e48e

Please sign in to comment.