Skip to content

fix(SRVKP-14519): report snippet on new taskrun failures - #2986

Merged
chmouel merged 1 commit into
mainfrom
SRVKP-14519-taskrun-failure-reasons
Sep 18, 2026
Merged

chmouel merged 1 commit into
mainfrom
SRVKP-14519-taskrun-failure-reasons

Conversation

@chmouel

@chmouel chmouel commented Sep 17, 2026

Copy link
Copy Markdown
Member

📝 Description of the Change

Failure snippets stopped showing up on failed PipelineRuns, and the GitHub
inline error annotations disappeared with them.

Tekton now reports granular TaskRun failure reasons instead of the generic
Failed: a step exiting non-zero is reported as StepFailed, and there are
also StepOOM, SidecarFailed, SidecarOOM, InitContainerFailed,
InitContainerOOM, PodEvicted and FailureIgnored.

CollectFailedTasksLogSnippet only accepted the literal reason Failed:

} else if ti.Reason != tektonv1.PipelineRunReasonFailed.String() {
    continue
}

so every step failure was filtered out, the map came back empty,
getFailureSnippet returned an empty string and the
{{- if not (eq .Mt.FailureSnippet "")}} block of the status template was
never rendered. The same function feeds getFailuresMessageAsAnnotations in
the GitHub provider, hence the missing annotations.

The reasons are now listed explicitly in two sets:

  • container logs are fetched for Failed, StepFailed, StepOOM,
    SidecarFailed, SidecarOOM and PodEvicted;
  • the condition message is used, without fetching logs, for the reasons that
    never produce step logs: validation, cancelled, timeout, image pull,
    container config and pod creation failures, plus InitContainerFailed and
    InitContainerOOM.

FailureIgnored is still skipped, so a successful PipelineRun does not grow a
failure snippet. Any unknown failure reason is now logged as a warning instead
of being dropped silently, so the next Tekton addition is visible.

Verified on a live cluster: the failed TaskRun reported
Succeeded=False reason=StepFailed with message
"step-lint" exited with code 2: Error and no snippet was posted.

🔗 Linked GitHub Issue

Fixes #

Jira: https://issues.redhat.com/browse/SRVKP-14519

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

TestCollectFailedTasksLogSnippet gained cases for StepFailed, StepOOM,
SidecarFailed, PodEvicted, InitContainerFailed (message fallback),
FailureIgnored (skipped) and an unknown reason (skipped plus warning).

TestGiteaErrorSnippet now asserts the Failure snippet: section is present,
not only the log line. TestGiteaErrorSnippetCustomLines normalizes the
reason in the comment before the golden comparison, since the reason string
depends on the Tekton version.

🤖 AI Assistance

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Investigation, fix and tests were done with AI assistance; the root cause was
confirmed against a running cluster and the change was reviewed and tested
locally with make test and make lint.

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's guide
  • ✨ I have ensured my commit message prefix matches the type of change
  • ♽ I have run make test and make lint locally
  • 📖 I have added or updated documentation for any user-facing changes (none needed, the documented behaviour is unchanged)
  • 🧪 I have added sufficient unit tests for my code changes
  • 🎁 I have added end-to-end tests where feasible
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it

Copilot AI lite review requested due to automatic review settings September 17, 2026 12:51
@pipelines-as-code

Copy link
Copy Markdown

Paco Review 🔍

This PR refactors the task failure reason handling in CollectFailedTasksLogSnippet to use explicit lookup maps (reasonsWithoutPodLogs and reasonsWithPodLogs) instead of a long inline condition chain. It adds coverage for several new Tekton failure reasons (StepFailed, StepOOM, SidecarFailed, PodEvicted, InitContainerFailed) and introduces a warning log for unknown failure reasons. Test coverage is significantly expanded, and the E2E golden file is normalized to handle variable Tekton failure reason strings across versions.

Review difficulty: 3/5 (Moderate) — Moderate complexity refactor touching failure-path logic with meaningful behavioral changes; the new unknown-reason warning path and the change to how task conditions are checked add non-trivial correctness surface.

1 new inline comment(s) found.

Reviewed commit: 6472694

@pipelines-as-code pipelines-as-code Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paco inline comments -- see the Paco Review summary comment for the overview.

Comment thread pkg/kubeinteraction/status/task_status.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Add the existing validation failure reason to message-only handling so it is not dropped.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates TaskRun failure handling so snippets and annotations work with granular Tekton failure reasons.

Changes:

  • Categorizes log-based and message-only failure reasons.
  • Adds unit and Gitea test coverage.
  • Warns on unknown failure reasons.
File summaries
File Description
test/testdata/TestGiteaErrorSnippetCustomLines.golden Stabilizes reason-dependent golden output.
test/gitea_error_snippets_test.go Verifies rendered failure snippets.
pkg/kubeinteraction/status/task_status.go Classifies failure reasons and collects snippets.
pkg/kubeinteraction/status/task_status_test.go Tests granular failure handling.
Review details

Suppressed comments (2)

pkg/kubeinteraction/status/task_status.go:43

  • SidecarFailed and SidecarOOM are added to the log-fetching set, but the fetch loop below only iterates task.Status.Steps; Tekton reports sidecar termination in task.Status.Sidecars (TaskRunStatusFields.Sidecars / SidecarState). Consequently these newly supported reasons are returned with only the condition message and never receive the sidecar log snippet promised by this change. Include terminated sidecars when collecting logs (and add a regression test with TaskRunStatusFields.Sidecars).
	tektonv1.TaskRunReasonSidecarFailed.String(): {},
	tektonv1.TaskRunReasonSidecarOOM.String():    {},

pkg/kubeinteraction/status/task_status.go:30

  • Several failure reasons already defined by the bundled Tekton API are still classified as unknown and therefore dropped: TaskRunResolutionFailed, TaskValidationFailed, InvalidParamValue, and ResourceVerificationFailed. These represent resolution/validation/configuration failures that do not produce user step logs, so their condition messages should be included in reasonsWithoutPodLogs; otherwise snippets and provider annotations remain missing for those failures and an avoidable warning is emitted.
	tektonv1.TaskRunReasonFailedValidation.String():           {},
	tektonv1.TaskRunReasonCancelled.String():                  {},
	tektonv1.TaskRunReasonTimedOut.String():                   {},
	tektonv1.TaskRunReasonImagePullFailed.String():            {},
	tektonv1.TaskRunReasonCreateContainerConfigError.String(): {},
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/kubeinteraction/status/task_status.go
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.57%. Comparing base (399a216) to head (81eb706).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2986   +/-   ##
=======================================
  Coverage   91.56%   91.57%           
=======================================
  Files         164      164           
  Lines       12530    12532    +2     
=======================================
+ Hits        11473    11476    +3     
+ Misses       1056     1055    -1     
  Partials        1        1           
Flag Coverage Δ
unit-tests 91.57% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Tekton now describes a failed task with more precise reasons than the
old generic "Failed", a step that exits with an error is reported as
"StepFailed" and there are new reasons for out of memory kills, sidecar
failures, evicted pods and failed init containers.

Pipelines-as-Code only recognised the old name, so every step failure
was quietly ignored: no failure snippet at the bottom of the comment or
check run, and no inline error annotations on the changed files in
GitHub.

The failure reasons are now listed explicitly, split between the ones
where the container logs can be fetched and the ones that fail before
anything runs and only have a message to show, which also covers the
validation, resolution and parameter errors that were only partially
handled before. Failures that the pipeline author chose to ignore are
still left out. An unknown reason is now logged as a warning instead of
being dropped silently, so the next addition on the Tekton side is easy
to spot.

Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
@chmouel
chmouel force-pushed the SRVKP-14519-taskrun-failure-reasons branch from 6472694 to 81eb706 Compare September 17, 2026 13:24
@chmouel
chmouel requested a balanced review from Copilot September 17, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Sidecar failure reasons do not fetch logs from TaskRun sidecar states.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +46 to +47
tektonv1.TaskRunReasonSidecarFailed.String(): {},
tektonv1.TaskRunReasonSidecarOOM.String(): {},
@chmouel
chmouel merged commit aebdf02 into main Sep 18, 2026
17 checks passed
@chmouel
chmouel deleted the SRVKP-14519-taskrun-failure-reasons branch September 18, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants