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

Add RunReason and CustomRunReason #5718

Merged
merged 1 commit into from
Nov 7, 2022
Merged
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
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
8 changes: 4 additions & 4 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (t ResolvedPipelineTask) isCancelledForTimeOut() bool {
isDone = isDone && run.IsDone()
c := run.Status.GetCondition(apis.ConditionSucceeded)
runCancelled := c.IsFalse() &&
c.Reason == v1alpha1.RunReasonCancelled &&
c.Reason == v1alpha1.RunReasonCancelled.String() &&
run.Spec.StatusMessage == v1alpha1.RunCancelledByPipelineTimeoutMsg
atLeastOneCancelled = atLeastOneCancelled || runCancelled
}
Expand All @@ -267,7 +267,7 @@ func (t ResolvedPipelineTask) isCancelledForTimeOut() bool {
}
c := t.Run.Status.GetCondition(apis.ConditionSucceeded)
return c != nil && c.IsFalse() &&
c.Reason == v1alpha1.RunReasonCancelled &&
c.Reason == v1alpha1.RunReasonCancelled.String() &&
t.Run.Spec.StatusMessage == v1alpha1.RunCancelledByPipelineTimeoutMsg
case t.IsMatrixed():
if len(t.TaskRuns) == 0 {
Expand Down Expand Up @@ -308,7 +308,7 @@ func (t ResolvedPipelineTask) isCancelled() bool {
for _, run := range t.Runs {
isDone = isDone && run.IsDone()
c := run.Status.GetCondition(apis.ConditionSucceeded)
runCancelled := c.IsFalse() && c.Reason == v1alpha1.RunReasonCancelled
runCancelled := c.IsFalse() && c.Reason == v1alpha1.RunReasonCancelled.String()
atLeastOneCancelled = atLeastOneCancelled || runCancelled
}
return atLeastOneCancelled && isDone
Expand All @@ -317,7 +317,7 @@ func (t ResolvedPipelineTask) isCancelled() bool {
return false
}
c := t.Run.Status.GetCondition(apis.ConditionSucceeded)
return c != nil && c.IsFalse() && c.Reason == v1alpha1.RunReasonCancelled
return c != nil && c.IsFalse() && c.Reason == v1alpha1.RunReasonCancelled.String()
case t.IsMatrixed():
if len(t.TaskRuns) == 0 {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ func withCancelledForTimeout(tr *v1beta1.TaskRun) *v1beta1.TaskRun {
}

func withRunCancelled(run *v1alpha1.Run) *v1alpha1.Run {
run.Status.Conditions[0].Reason = v1alpha1.RunReasonCancelled
run.Status.Conditions[0].Reason = v1alpha1.RunReasonCancelled.String()
return run
}

func withRunCancelledForTimeout(run *v1alpha1.Run) *v1alpha1.Run {
run.Spec.StatusMessage = v1alpha1.RunCancelledByPipelineTimeoutMsg
run.Status.Conditions[0].Reason = v1alpha1.RunReasonCancelled
run.Status.Conditions[0].Reason = v1alpha1.RunReasonCancelled.String()
return run
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ func TestGetPipelineConditionStatus(t *testing.T) {
Status: duckv1.Status{Conditions: []apis.Condition{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1alpha1.RunReasonCancelled,
Reason: v1alpha1.RunReasonCancelled.String(),
}}},
},
},
Expand All @@ -1728,7 +1728,7 @@ func TestGetPipelineConditionStatus(t *testing.T) {
Status: duckv1.Status{Conditions: []apis.Condition{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1alpha1.RunReasonCancelled,
Reason: v1alpha1.RunReasonCancelled.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