Skip to content

Commit

Permalink
fix(taskrun): resolve issue with TaskRun not failing promptly after P…
Browse files Browse the repository at this point in the history
…od OOM

fix tektoncd#8170

When an OOM occurs in a Pod related to TaskRun, the TaskRun should be marked
as failed immediately instead of waiting for it to timeout.
  • Loading branch information
l-qing committed Aug 2, 2024
1 parent dd36119 commit 652e718
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func MakeTaskRunStatus(ctx context.Context, logger *zap.SugaredLogger, tr v1.Tas

sortPodContainerStatuses(pod.Status.ContainerStatuses, pod.Spec.Containers)

complete := areContainersCompleted(ctx, pod) || pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed
complete := areContainersCompleted(ctx, pod) ||
pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed ||
DidTaskRunFail(pod)

if complete {
onError, ok := tr.Annotations[v1.PipelineTaskOnErrorAnnotation]
Expand Down
8 changes: 6 additions & 2 deletions pkg/pod/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func TestMakeTaskRunStatus(t *testing.T) {
}},
},
want: v1.TaskRunStatus{
Status: statusRunning(),
Status: statusFailure(v1.TaskRunReasonFailed.String(), "\"step-state-name\" exited with code 123"),
TaskRunStatusFields: v1.TaskRunStatusFields{
Steps: []v1.StepState{{
ContainerState: corev1.ContainerState{
Expand All @@ -843,6 +843,8 @@ func TestMakeTaskRunStatus(t *testing.T) {
Container: "step-state-name",
}},
Sidecars: []v1.SidecarState{},
// We don't actually care about the time, just that it's not nil
CompletionTime: &metav1.Time{Time: time.Now()},
},
},
}, {
Expand All @@ -866,7 +868,7 @@ func TestMakeTaskRunStatus(t *testing.T) {
}},
},
want: v1.TaskRunStatus{
Status: statusRunning(),
Status: statusFailure(v1.TaskRunReasonFailed.String(), "\"step-state-name\" exited with code 123"),
TaskRunStatusFields: v1.TaskRunStatusFields{
Steps: []v1.StepState{{
ContainerState: corev1.ContainerState{
Expand All @@ -878,6 +880,8 @@ func TestMakeTaskRunStatus(t *testing.T) {
ImageID: "image-id",
}},
Sidecars: []v1.SidecarState{},
// We don't actually care about the time, just that it's not nil
CompletionTime: &metav1.Time{Time: time.Now()},
},
},
}, {
Expand Down

0 comments on commit 652e718

Please sign in to comment.