-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Clean up RunsToCompletion interface #4479
Conversation
/assign jerop |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for splitting out the refactor @lbernick 😸
I have some non-blocking comments (can fix in a follow up PR)
- The function name in the
TaskRun
object isHasTimedOut
- can we consider usingHasTimedOut
instead ofIsTimedOut
for consistency?
pipeline/pkg/apis/pipeline/v1beta1/taskrun_types.go
Lines 386 to 398 in f4c939c
// HasTimedOut returns true if the TaskRun runtime is beyond the allowed timeout | |
func (tr *TaskRun) HasTimedOut(ctx context.Context) bool { | |
if tr.Status.StartTime.IsZero() { | |
return false | |
} | |
timeout := tr.GetTimeout(ctx) | |
// If timeout is set to 0 or defaulted to 0, there is no timeout. | |
if timeout == apisconfig.NoTimeoutDuration { | |
return false | |
} | |
runtime := time.Since(tr.Status.StartTime.Time) | |
return runtime > timeout | |
} |
- The
HasTimedOut
function inTaskRun
has tests - can we please add some tests for the same functionalityPipelineRuns
as well?
pipeline/pkg/apis/pipeline/v1beta1/taskrun_types_test.go
Lines 247 to 322 in f0a2f00
func TestHasTimedOut(t *testing.T) { | |
// IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC | |
zeroTime := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC) | |
testCases := []struct { | |
name string | |
taskRun *v1beta1.TaskRun | |
expectedStatus bool | |
}{{ | |
name: "TaskRun not started", | |
taskRun: &v1beta1.TaskRun{ | |
Status: v1beta1.TaskRunStatus{ | |
Status: duckv1beta1.Status{ | |
Conditions: []apis.Condition{{ | |
Type: apis.ConditionSucceeded, | |
Status: corev1.ConditionFalse, | |
}}, | |
}, | |
TaskRunStatusFields: v1beta1.TaskRunStatusFields{ | |
StartTime: &metav1.Time{Time: zeroTime}, | |
}, | |
}, | |
}, | |
expectedStatus: false, | |
}, { | |
name: "TaskRun no timeout", | |
taskRun: &v1beta1.TaskRun{ | |
Spec: v1beta1.TaskRunSpec{ | |
Timeout: &metav1.Duration{ | |
Duration: 0 * time.Minute, | |
}, | |
}, | |
Status: v1beta1.TaskRunStatus{ | |
Status: duckv1beta1.Status{ | |
Conditions: []apis.Condition{{ | |
Type: apis.ConditionSucceeded, | |
Status: corev1.ConditionFalse, | |
}}, | |
}, | |
TaskRunStatusFields: v1beta1.TaskRunStatusFields{ | |
StartTime: &metav1.Time{Time: time.Now().Add(-15 * time.Hour)}, | |
}, | |
}, | |
}, | |
expectedStatus: false, | |
}, { | |
name: "TaskRun timed out", | |
taskRun: &v1beta1.TaskRun{ | |
Spec: v1beta1.TaskRunSpec{ | |
Timeout: &metav1.Duration{ | |
Duration: 10 * time.Second, | |
}, | |
}, | |
Status: v1beta1.TaskRunStatus{ | |
Status: duckv1beta1.Status{ | |
Conditions: []apis.Condition{{ | |
Type: apis.ConditionSucceeded, | |
Status: corev1.ConditionFalse, | |
}}, | |
}, | |
TaskRunStatusFields: v1beta1.TaskRunStatusFields{ | |
StartTime: &metav1.Time{Time: time.Now().Add(-15 * time.Second)}, | |
}, | |
}, | |
}, | |
expectedStatus: true, | |
}} | |
for _, tc := range testCases { | |
t.Run(tc.name, func(t *testing.T) { | |
result := tc.taskRun.HasTimedOut(context.Background()) | |
if d := cmp.Diff(result, tc.expectedStatus); d != "" { | |
t.Fatalf(diff.PrintWantGot(d)) | |
} | |
}) | |
} | |
} |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jerop The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The RunsToCompletion interface was introduced so that PipelineRuns and Runs could conform to a common interface for CloudEvents and subsequently removed. This commit removes the redundant function PipelineRun.IsTimedOut (redundant with PipelineRun.HasTimedOut). PipelineRun.HasTimedOut was introduced so that PipelineRun would implement RunsToCompletion. "HasTimedOut" was kept (as opposed to "IsTimedOut") for the sake of consistency with TaskRun and Run. It also removes stale references to RunsToCompletion. No functional changes.
The following is the coverage report on the affected files.
|
Done.
I think PipelineRuns.IsTimedOut is already tested; just replaced with HasTimedOut. |
The following is the coverage report on the affected files.
|
sounds good, thanks @lbernick! |
/test pull-tekton-pipeline-integration-tests |
/lgtm |
Changes
The RunsToCompletion interface was introduced so that PipelineRuns and Runs
could conform to a common interface for CloudEvents and subsequently removed (both in #2677).
This commit removes the redundant function PipelineRun.IsTimedOut (redundant with PipelineRun.HasTimedOut). PipelineRun.HasTimedOut was introduced so that PipelineRun would implement RunsToCompletion.
"HasTimedOut" was kept (as opposed to "IsTimedOut") for the sake of consistency with TaskRun and Run.
It also removes stale references to RunsToCompletion. No functional changes.
This PR moves cleanup code out of #4440.
/kind cleanup
Submitter Checklist
As the author of this PR, please check off the items in this checklist:
functionality, content, code)
Release Notes