Skip to content

Commit dc25bd3

Browse files
pratap0007tekton-robot
authored andcommitted
Fix reason of PipelineRun status for PipelineRun having tasks timeout
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 Signed-off-by: Shiv Verma <[email protected]>
1 parent 43c0bb9 commit dc25bd3

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

pkg/reconciler/pipelinerun/pipelinerun_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,20 +2891,21 @@ status:
28912891
defer prt.Cancel()
28922892

28932893
wantEvents := []string{
2894-
"Normal Started",
2894+
"Warning Failed PipelineRun",
28952895
}
28962896
reconciledRun, clients := prt.reconcileRun("foo", "test-pipeline-run-with-timeout", wantEvents, false)
28972897

2898-
if reconciledRun.Status.CompletionTime != nil {
2899-
t.Errorf("Expected nil CompletionTime on PipelineRun but was %s", reconciledRun.Status.CompletionTime)
2898+
if reconciledRun.Status.CompletionTime == nil {
2899+
t.Errorf("Expected CompletionTime on PipelineRun but was %s", reconciledRun.Status.CompletionTime)
29002900
}
29012901

2902-
// The PipelineRun should be running.
2903-
if reconciledRun.Status.GetCondition(apis.ConditionSucceeded).Reason != v1.PipelineRunReasonRunning.String() {
2904-
t.Errorf("Expected PipelineRun to be running, but condition reason is %s", reconciledRun.Status.GetCondition(apis.ConditionSucceeded).Reason)
2902+
// The PipelineRun should be timeout.
2903+
if reconciledRun.Status.GetCondition(apis.ConditionSucceeded).Reason != v1.PipelineRunReasonTimedOut.String() {
2904+
t.Errorf("Expected PipelineRun to be time out, but condition reason is %s", reconciledRun.Status.GetCondition(apis.ConditionSucceeded).Reason)
29052905
}
29062906

29072907
// Check that there is a skipped task for the expected reason
2908+
29082909
if len(reconciledRun.Status.SkippedTasks) != 1 {
29092910
t.Errorf("expected one skipped task, found %d", len(reconciledRun.Status.SkippedTasks))
29102911
} else if reconciledRun.Status.SkippedTasks[0].Reason != v1.TasksTimedOutSkip {
@@ -3031,7 +3032,7 @@ spec:
30313032
pipelineRef:
30323033
name: test-pipeline-with-finally
30333034
timeouts:
3034-
tasks: 5m
3035+
tasks: 25m
30353036
pipeline: 20m
30363037
status:
30373038
finallyStartTime: "2021-12-31T23:44:59Z"
@@ -3259,7 +3260,7 @@ spec:
32593260
pipelineRef:
32603261
name: test-pipeline-with-finally
32613262
timeouts:
3262-
tasks: 5m
3263+
tasks: 25m
32633264
pipeline: 20m
32643265
status:
32653266
startTime: "2021-12-31T23:40:00Z"
@@ -3308,7 +3309,7 @@ spec:
33083309
pipelineRef:
33093310
name: test-pipeline-with-finally
33103311
timeouts:
3311-
tasks: 5m
3312+
tasks: 25m
33123313
pipeline: 20m
33133314
status:
33143315
startTime: "2021-12-31T23:40:00Z"
@@ -3348,7 +3349,7 @@ spec:
33483349
pipelineRef:
33493350
name: test-pipeline-with-finally
33503351
timeouts:
3351-
tasks: 5m
3352+
tasks: 25m
33523353
pipeline: 20m
33533354
status:
33543355
startTime: "2021-12-31T23:40:00Z"

pkg/reconciler/pipelinerun/resources/pipelinerunstate.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,15 @@ func (facts *PipelineRunFacts) GetPipelineConditionStatus(ctx context.Context, p
497497
}
498498
}
499499

500+
if pr.HaveTasksTimedOut(ctx, c) {
501+
return &apis.Condition{
502+
Type: apis.ConditionSucceeded,
503+
Status: corev1.ConditionFalse,
504+
Reason: v1.PipelineRunReasonTimedOut.String(),
505+
Message: fmt.Sprintf("PipelineRun %q failed due to tasks failed to finish within %q", pr.Name, pr.TasksTimeout().Duration.String()),
506+
}
507+
}
508+
500509
// report the count in PipelineRun Status
501510
// get the count of successful tasks, failed tasks, cancelled tasks, skipped task, and incomplete tasks
502511
s := facts.getPipelineTasksCount()

pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,39 @@ func TestGetPipelineConditionStatus_PipelineTimeouts(t *testing.T) {
21412141
}
21422142
}
21432143

2144+
// pipeline should result in timeout if its runtime exceeds its spec.Timeouts.Tasks based on its status.Timeout
2145+
func TestGetPipelineConditionStatus_PipelineTasksTimeouts(t *testing.T) {
2146+
d, err := dagFromState(oneFinishedState)
2147+
if err != nil {
2148+
t.Fatalf("Unexpected error while building DAG for state %v: %v", oneFinishedState, err)
2149+
}
2150+
pr := &v1.PipelineRun{
2151+
ObjectMeta: metav1.ObjectMeta{Name: "pipelinerun-no-tasks-started"},
2152+
Spec: v1.PipelineRunSpec{
2153+
Timeouts: &v1.TimeoutFields{
2154+
Tasks: &metav1.Duration{Duration: 1 * time.Minute},
2155+
},
2156+
},
2157+
Status: v1.PipelineRunStatus{
2158+
PipelineRunStatusFields: v1.PipelineRunStatusFields{
2159+
StartTime: &metav1.Time{Time: now.Add(-2 * time.Minute)},
2160+
},
2161+
},
2162+
}
2163+
facts := PipelineRunFacts{
2164+
State: oneFinishedState,
2165+
TasksGraph: d,
2166+
FinalTasksGraph: &dag.Graph{},
2167+
TimeoutsState: PipelineRunTimeoutsState{
2168+
Clock: testClock,
2169+
},
2170+
}
2171+
c := facts.GetPipelineConditionStatus(t.Context(), pr, zap.NewNop().Sugar(), testClock)
2172+
if c.Status != corev1.ConditionFalse && c.Reason != v1.PipelineRunReasonTimedOut.String() {
2173+
t.Fatalf("Expected to get status %s but got %s for state %v", corev1.ConditionFalse, c.Status, oneFinishedState)
2174+
}
2175+
}
2176+
21442177
func TestGetPipelineConditionStatus_OnError(t *testing.T) {
21452178
var oneFailedStateOnError = PipelineRunState{{
21462179
PipelineTask: &v1.PipelineTask{

test/timeout_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ spec:
511511
}
512512

513513
t.Logf("Waiting for PipelineRun %s in namespace %s to be failed", pipelineRun.Name, namespace)
514-
if err := WaitForPipelineRunState(ctx, c, pipelineRun.Name, timeout, FailedWithReason(v1.PipelineRunReasonFailed.String(), pipelineRun.Name), "PipelineRunFailed", v1Version); err != nil {
514+
if err := WaitForPipelineRunState(ctx, c, pipelineRun.Name, timeout, FailedWithReason(v1.PipelineRunReasonTimedOut.String(), pipelineRun.Name), "PipelineRunFailed", v1Version); err != nil {
515515
t.Errorf("Error waiting for PipelineRun %s to finish: %s", pipelineRun.Name, err)
516516
}
517517

0 commit comments

Comments
 (0)