Skip to content

Commit

Permalink
Add RunReason and CustomRunReason
Browse files Browse the repository at this point in the history
Prior to this change, we did not have `RunReason` and `CustomRunReason`.
As a result, there were instances where we reused `TaskRunReason` and
`PipelineRunReason`. This worked because the underlying strings are the
same, but it is confusing when reading the code (and reviewing changes).

In this change, we:
- introduce `RunReason` and `CustomRunReason`
- clean up existing reasons to use the enum
- add three common reasons - started, running, successful and failed
  • Loading branch information
jerop committed Nov 3, 2022
1 parent 14eba83 commit a2044ac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
23 changes: 19 additions & 4 deletions pkg/apis/pipeline/v1alpha1/run_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,34 @@ func (rs RunSpec) GetParam(name string) *v1beta1.Param {
return nil
}

// RunReason is an enum used to store all Run reason for the Succeeded condition that are controlled by the Run itself.
type RunReason string

const (
// RunReasonStarted is the reason set when the Run has just started.
RunReasonStarted RunReason = "Started"
// RunReasonRunning is the reason set when the Run is running.
RunReasonRunning RunReason = "Running"
// RunReasonSuccessful is the reason set when the Run completed successfully.
RunReasonSuccessful RunReason = "Succeeded"
// RunReasonFailed is the reason set when the Run completed with a failure.
RunReasonFailed RunReason = "Failed"
// RunReasonCancelled must be used in the Condition Reason to indicate that a Run was cancelled.
RunReasonCancelled = "RunCancelled"
RunReasonCancelled RunReason = "RunCancelled"
// RunReasonTimedOut must be used in the Condition Reason to indicate that a Run was timed out.
RunReasonTimedOut = "RunTimedOut"
RunReasonTimedOut RunReason = "RunTimedOut"
// RunReasonWorkspaceNotSupported can be used in the Condition Reason to indicate that the
// Run contains a workspace which is not supported by this custom task.
RunReasonWorkspaceNotSupported = "RunWorkspaceNotSupported"
RunReasonWorkspaceNotSupported RunReason = "RunWorkspaceNotSupported"
// RunReasonPodTemplateNotSupported can be used in the Condition Reason to indicate that the
// Run contains a pod template which is not supported by this custom task.
RunReasonPodTemplateNotSupported = "RunPodTemplateNotSupported"
RunReasonPodTemplateNotSupported RunReason = "RunPodTemplateNotSupported"
)

func (t RunReason) String() string {
return string(t)
}

// RunStatus defines the observed state of Run.
type RunStatus = runv1alpha1.RunStatus

Expand Down
21 changes: 18 additions & 3 deletions pkg/apis/pipeline/v1beta1/customrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,31 @@ func (rs CustomRunSpec) GetParam(name string) *Param {
return nil
}

// CustomRunReason is an enum used to store all Run reason for the Succeeded condition that are controlled by the CustomRun itself.
type CustomRunReason string

const (
// CustomRunReasonStarted is the reason set when the CustomRun has just started.
CustomRunReasonStarted CustomRunReason = "Started"
// CustomRunReasonRunning is the reason set when the CustomRun is running.
CustomRunReasonRunning CustomRunReason = "Running"
// CustomRunReasonSuccessful is the reason set when the CustomRun completed successfully.
CustomRunReasonSuccessful CustomRunReason = "Succeeded"
// CustomRunReasonFailed is the reason set when the CustomRun completed with a failure.
CustomRunReasonFailed CustomRunReason = "Failed"
// CustomRunReasonCancelled must be used in the Condition Reason to indicate that a CustomRun was cancelled.
CustomRunReasonCancelled = "CustomRunCancelled"
CustomRunReasonCancelled CustomRunReason = "CustomRunCancelled"
// CustomRunReasonTimedOut must be used in the Condition Reason to indicate that a CustomRun was timed out.
CustomRunReasonTimedOut = "CustomRunTimedOut"
CustomRunReasonTimedOut CustomRunReason = "CustomRunTimedOut"
// CustomRunReasonWorkspaceNotSupported can be used in the Condition Reason to indicate that the
// CustomRun contains a workspace which is not supported by this custom task.
CustomRunReasonWorkspaceNotSupported = "CustomRunWorkspaceNotSupported"
CustomRunReasonWorkspaceNotSupported CustomRunReason = "CustomRunWorkspaceNotSupported"
)

func (t CustomRunReason) String() string {
return string(t)
}

// CustomRunStatus defines the observed state of CustomRun.
type CustomRunStatus = runv1beta1.CustomRunStatus

Expand Down
8 changes: 4 additions & 4 deletions pkg/reconciler/customrun/customrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ func TestReconcile_CloudEvents(t *testing.T) {
condition: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Reason: v1beta1.TaskRunReasonRunning.String(),
Reason: v1beta1.CustomRunReasonRunning.String(),
},
wantCloudEvents: []string{`(?s)dev.tekton.event.customrun.running.v1.*test-customRun`},
}, {
name: "CustomRun with finished true condition",
condition: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: v1beta1.PipelineRunReasonSuccessful.String(),
Reason: v1beta1.CustomRunReasonSuccessful.String(),
},
wantCloudEvents: []string{`(?s)dev.tekton.event.customrun.successful.v1.*test-customRun`},
}, {
name: "CustomRun with finished false condition",
condition: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1beta1.PipelineRunReasonCancelled.String(),
Reason: v1beta1.CustomRunReasonCancelled.String(),
},
wantCloudEvents: []string{`(?s)dev.tekton.event.customrun.failed.v1.*test-customRun`},
}}
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestReconcile_CloudEvents_Disabled(t *testing.T) {
{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1beta1.PipelineRunReasonCancelled.String(),
Reason: v1beta1.CustomRunReasonCancelled.String(),
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/reconciler/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/test"
Expand Down Expand Up @@ -116,23 +115,23 @@ func TestReconcile_CloudEvents(t *testing.T) {
condition: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Reason: v1beta1.TaskRunReasonRunning.String(),
Reason: v1alpha1.RunReasonRunning.String(),
},
wantCloudEvents: []string{`(?s)dev.tekton.event.run.running.v1.*test-run`},
}, {
name: "Run with finished true condition",
condition: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: v1beta1.PipelineRunReasonSuccessful.String(),
Reason: v1alpha1.RunReasonSuccessful.String(),
},
wantCloudEvents: []string{`(?s)dev.tekton.event.run.successful.v1.*test-run`},
}, {
name: "Run with finished false condition",
condition: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1beta1.PipelineRunReasonCancelled.String(),
Reason: v1alpha1.RunReasonCancelled.String(),
},
wantCloudEvents: []string{`(?s)dev.tekton.event.run.failed.v1.*test-run`},
}}
Expand Down Expand Up @@ -255,7 +254,7 @@ func TestReconcile_CloudEvents_Disabled(t *testing.T) {
{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1beta1.PipelineRunReasonCancelled.String(),
Reason: v1alpha1.RunReasonCancelled.String(),
},
},
}
Expand Down

0 comments on commit a2044ac

Please sign in to comment.