-
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
Consolidate cancel and timeout logic #2365
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"fmt" | ||
"time" | ||
|
||
apisconfig "github.com/tektoncd/pipeline/pkg/apis/config" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -71,6 +72,10 @@ const ( | |
// TaskRunSpecStatusCancelled indicates that the user wants to cancel the task, | ||
// if not already cancelled or terminated | ||
TaskRunSpecStatusCancelled = "TaskRunCancelled" | ||
|
||
// TaskRunReasonCancelled indicates that the TaskRun has been cancelled | ||
// because it was requested so by the user | ||
TaskRunReasonCancelled = "TaskRunCancelled" | ||
) | ||
|
||
// TaskRunInputs holds the input values that this task was invoked with. | ||
|
@@ -120,6 +125,17 @@ func (trs *TaskRunStatus) MarkResourceNotConvertible(err *CannotConvertError) { | |
}) | ||
} | ||
|
||
// MarkResourceFailed sets the ConditionSucceeded condition to ConditionFalse | ||
// based on an error that occurred and a reason | ||
func (trs *TaskRunStatus) MarkResourceFailed(reason string, err error) { | ||
taskRunCondSet.Manage(trs).SetCondition(apis.Condition{ | ||
Type: apis.ConditionSucceeded, | ||
Status: corev1.ConditionFalse, | ||
Reason: reason, | ||
Message: err.Error(), | ||
}) | ||
} | ||
|
||
// TaskRunStatusFields holds the fields of TaskRun's status. This is defined | ||
// separately and inlined so that other types can readily consume these fields | ||
// via duck typing. | ||
|
@@ -333,6 +349,28 @@ func (tr *TaskRun) IsCancelled() bool { | |
return tr.Spec.Status == TaskRunSpecStatusCancelled | ||
} | ||
|
||
// HasTimedOut returns true if the TaskRun runtime is beyond the allowed timeout | ||
func (tr *TaskRun) HasTimedOut() bool { | ||
if tr.Status.StartTime.IsZero() { | ||
return false | ||
} | ||
timeout := tr.GetTimeout() | ||
// 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 | ||
} | ||
|
||
func (tr *TaskRun) GetTimeout() time.Duration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey @afrittoli are you sure we need this function? looking at the taskrun defaulting logic it looks like we default the value of the timeout: also we don't have the same function for pipelineruns, and finally finally |
||
// Use the platform default is no timeout is set | ||
if tr.Spec.Timeout == nil { | ||
return apisconfig.DefaultTimeoutMinutes * time.Minute | ||
} | ||
return tr.Spec.Timeout.Duration | ||
} | ||
|
||
// GetRunKey return the taskrun key for timeout handler map | ||
func (tr *TaskRun) GetRunKey() string { | ||
// The address of the pointer is a threadsafe unique identifier for the taskrun | ||
|
This file was deleted.
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.
Not sure if this should be in alpha too...
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.
It doesn't as it's just an alias in
v1alpha1
😉