Skip to content

Commit

Permalink
Fix reason of PipelineRun status for PipelineRun having tasks timeout
Browse files Browse the repository at this point in the history
This patch fixes to set the reason of PipelineRun
status to PipelineRunTimeout if the tasks of a PipelineRun
timeout because of the timeout.tasks parameter

Fixes: tektoncd#7573

Signed-off-by: Shiv Verma <shverma@redhat.com>
  • Loading branch information
pratap0007 committed Mar 7, 2024
1 parent 742292d commit 352db1a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ func (facts *PipelineRunFacts) GetPipelineConditionStatus(ctx context.Context, p
}
}

if pr.HaveTasksTimedOut(ctx, c) {
return &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1.PipelineRunReasonTimedOut.String(),
Message: fmt.Sprintf("PipelineRun %q failed to finish within %q", pr.Name, pr.TasksTimeout().Duration.String()),
}
}

// report the count in PipelineRun Status
// get the count of successful tasks, failed tasks, cancelled tasks, skipped task, and incomplete tasks
s := facts.getPipelineTasksCount()
Expand Down
33 changes: 33 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,39 @@ func TestGetPipelineConditionStatus_PipelineTimeouts(t *testing.T) {
}
}

// pipeline should result in timeout if its runtime exceeds its spec.Timeouts.Tasks based on its status.Timeout
func TestGetPipelineConditionStatus_PipelineTasksTimeouts(t *testing.T) {
d, err := dagFromState(oneFinishedState)
if err != nil {
t.Fatalf("Unexpected error while building DAG for state %v: %v", oneFinishedState, err)
}
pr := &v1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun-no-tasks-started"},
Spec: v1.PipelineRunSpec{
Timeouts: &v1.TimeoutFields{
Tasks: &metav1.Duration{Duration: 1 * time.Minute},
},
},
Status: v1.PipelineRunStatus{
PipelineRunStatusFields: v1.PipelineRunStatusFields{
StartTime: &metav1.Time{Time: now.Add(-2 * time.Minute)},
},
},
}
facts := PipelineRunFacts{
State: oneFinishedState,
TasksGraph: d,
FinalTasksGraph: &dag.Graph{},
TimeoutsState: PipelineRunTimeoutsState{
Clock: testClock,
},
}
c := facts.GetPipelineConditionStatus(context.Background(), pr, zap.NewNop().Sugar(), testClock)
if c.Status != corev1.ConditionFalse && c.Reason != v1.PipelineRunReasonTimedOut.String() {
t.Fatalf("Expected to get status %s but got %s for state %v", corev1.ConditionFalse, c.Status, oneFinishedState)
}
}

func TestGetPipelineConditionStatus_OnError(t *testing.T) {
var oneFailedStateOnError = PipelineRunState{{
PipelineTask: &v1.PipelineTask{
Expand Down

0 comments on commit 352db1a

Please sign in to comment.