Skip to content

Commit

Permalink
Fix number of completed and failed task in case of ValidationFailed
Browse files Browse the repository at this point in the history
Signed-off-by: divyansh42 <[email protected]>
  • Loading branch information
divyansh42 authored and tekton-robot committed Nov 5, 2024
1 parent 95e7a4e commit b2f8553
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,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:
Expand Down
15 changes: 13 additions & 2 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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
Expand Down Expand Up @@ -424,7 +426,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

Expand All @@ -444,12 +447,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 += 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()
Expand Down Expand Up @@ -644,6 +654,7 @@ func (facts *PipelineRunFacts) getPipelineTasksCount() pipelineRunStatusCount {
Incomplete: 0,
SkippedDueToTimeout: 0,
IgnoredFailed: 0,
ValidationFailed: 0,
}
for _, t := range facts.State {
switch {
Expand All @@ -664,7 +675,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 ||
Expand Down

0 comments on commit b2f8553

Please sign in to comment.