From 61205af69f9e4f0126d78bfb95b38982502f3cfe Mon Sep 17 00:00:00 2001 From: divyansh42 Date: Wed, 30 Oct 2024 15:26:49 +0530 Subject: [PATCH] Fix number of completed and failed task in case of ValidationFailed Signed-off-by: divyansh42 --- pkg/reconciler/pipelinerun/pipelinerun_test.go | 4 ++-- .../pipelinerun/resources/pipelinerunstate.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 451766624d3..780249b6a40 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -1290,8 +1290,8 @@ status: image: busybox script: 'exit 0' conditions: - - message: "Tasks Completed: 2 (Failed: 1, Cancelled 0), Skipped: 0" - reason: Failed + - message: "Tasks Completed: 1 (Failed: 0, Cancelled 0), Skipped: 0, Failed Validation: 1" + reason: PipelineValidationFailed status: "False" type: Succeeded childReferences: diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go b/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go index 8ca10e4903e..e0ea5a4c5a5 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go @@ -105,6 +105,8 @@ type pipelineRunStatusCount struct { Incomplete int // count of tasks skipped due to the relevant timeout having elapsed before the task is launched SkippedDueToTimeout int + // count of validation failed task and taskrun not created + ValidationFailed int } // ResetSkippedCache resets the skipped cache in the facts map @@ -498,7 +500,8 @@ func (facts *PipelineRunFacts) GetPipelineConditionStatus(ctx context.Context, p // report the count in PipelineRun Status // get the count of successful tasks, failed tasks, cancelled tasks, skipped task, and incomplete tasks s := facts.getPipelineTasksCount() - // completed task is a collection of successful, failed, cancelled tasks (skipped tasks are reported separately) + // completed task is a collection of successful, failed, cancelled tasks + // (skipped tasks and validation failed tasks are reported separately) cmTasks := s.Succeeded + s.Failed + s.Cancelled + s.IgnoredFailed totalFailedTasks := s.Failed + s.IgnoredFailed @@ -518,12 +521,19 @@ func (facts *PipelineRunFacts) GetPipelineConditionStatus(ctx context.Context, p message = fmt.Sprintf("Tasks Completed: %d (Failed: %d, Cancelled %d), Skipped: %d", cmTasks, totalFailedTasks, s.Cancelled, s.Skipped) } + // append validation failed count in the message + if s.ValidationFailed > 0 { + message = message + fmt.Sprintf(", Failed Validation: %d", s.ValidationFailed) + } // Set reason to ReasonCompleted - At least one is skipped if s.Skipped > 0 { reason = v1.PipelineRunReasonCompleted.String() } switch { + case s.ValidationFailed > 0: + reason = v1.PipelineRunReasonFailedValidation.String() + status = corev1.ConditionFalse case s.Failed > 0 || s.SkippedDueToTimeout > 0: // Set reason to ReasonFailed - At least one failed reason = v1.PipelineRunReasonFailed.String() @@ -719,6 +729,7 @@ func (facts *PipelineRunFacts) getPipelineTasksCount() pipelineRunStatusCount { Incomplete: 0, SkippedDueToTimeout: 0, IgnoredFailed: 0, + ValidationFailed: 0, } for _, t := range facts.State { switch { @@ -739,7 +750,7 @@ func (facts *PipelineRunFacts) getPipelineTasksCount() pipelineRunStatusCount { s.Failed++ } case t.isValidationFailed(facts.ValidationFailedTask): - s.Failed++ + s.ValidationFailed++ // increment skipped and skipped due to timeout counters since the task was skipped due to the pipeline, tasks, or finally timeout being reached before the task was launched case t.Skip(facts).SkippingReason == v1.PipelineTimedOutSkip || t.Skip(facts).SkippingReason == v1.TasksTimedOutSkip ||