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

Clean up RunsToCompletion interface #4479

Merged
merged 1 commit into from
Jan 13, 2022
Merged

Conversation

lbernick
Copy link
Member

@lbernick lbernick commented Jan 13, 2022

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:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in or deleted (only if no user facing changes)

Release Notes

NONE

@tekton-robot tekton-robot added release-note-none Denotes a PR that doesnt merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 13, 2022
@lbernick
Copy link
Member Author

/assign jerop
/assign afrittoli

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 81.8% 81.6% -0.2

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 81.8% 81.6% -0.2

Copy link
Member

@jerop jerop left a 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)

  1. The function name in the TaskRun object is HasTimedOut - can we consider using HasTimedOut instead of IsTimedOut for consistency?

// 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
}

  1. The HasTimedOut function in TaskRun has tests - can we please add some tests for the same functionality PipelineRuns as well?

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))
}
})
}
}

pkg/apis/pipeline/v1beta1/taskrun_types.go Outdated Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 13, 2022
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.
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 81.8% 81.6% -0.2

@tekton-robot tekton-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 13, 2022
@lbernick
Copy link
Member Author

  1. The function name in the TaskRun object is HasTimedOut - can we consider using HasTimedOut instead of IsTimedOut for consistency?

Done.

  1. The HasTimedOut function in TaskRun has tests - can we please add some tests for the same functionality PipelineRuns as well?

I think PipelineRuns.IsTimedOut is already tested; just replaced with HasTimedOut.

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipelinerun_types.go 81.8% 81.6% -0.2

@jerop
Copy link
Member

jerop commented Jan 13, 2022

sounds good, thanks @lbernick!

@jerop
Copy link
Member

jerop commented Jan 13, 2022

TestPipelineTaskTimeout is a known flake: #4427

/test pull-tekton-pipeline-integration-tests

@ghost
Copy link

ghost commented Jan 13, 2022

/lgtm

@tekton-robot tekton-robot assigned ghost Jan 13, 2022
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2022
@tekton-robot tekton-robot merged commit 1401ab7 into tektoncd:main Jan 13, 2022
@lbernick lbernick deleted the pr-timeout branch January 13, 2022 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants