Add --log-failed flag to pipelinerun logs command#2920
Conversation
645e0bb to
ff3075b
Compare
Add a --log-failed flag to `tkn pipelinerun logs` that filters output to only show logs from failed TaskRuns, similar to how GitHub Actions shows failed job logs. When --log-failed is set and the PipelineRun is still running, the completed-logs path is used so only TaskRuns that have already failed are shown. If no TaskRuns have failed, an informative error is returned. The flag composes with --task (intersection of both filters). Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com> Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
ff3075b to
7549dc7
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new --log-failed flag to tkn pipelinerun logs to restrict output to logs from failed TaskRuns, wiring the option through log reader plumbing and documenting/testing the new behavior.
Changes:
- Introduce
--log-failedCLI flag and plumb it throughLogOptionsinto the logReader. - Filter PipelineRun TaskRuns to only those with
ConditionFalse, and return an error when none have failed. - Add unit tests and update generated user docs (man page + markdown).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/taskrun/taskrun.go | Adds TaskRun filtering helper to keep only failed runs based on status conditions. |
| pkg/options/logs.go | Extends LogOptions with a Failed boolean to carry the new flag through the stack. |
| pkg/log/reader.go | Stores the Failed option on the log Reader. |
| pkg/log/pipeline_reader.go | Uses failed to bypass live pipeline streaming and to filter ordered TaskRuns to failures only. |
| pkg/cmd/pipelinerun/logs.go | Adds --log-failed flag and updates command examples/help text. |
| pkg/cmd/pipelinerun/logs_test.go | Adds unit tests validating failed-only output and the “no failures” error case. |
| docs/man/man1/tkn-pipelinerun-logs.1 | Documents the new --log-failed option and example usage in man output. |
| docs/cmd/tkn_pipelinerun_logs.md | Documents the new --log-failed option and example usage in markdown docs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err := r.waitUntilAvailable(); err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| ordered, err := r.getOrderedTasks(pr) | ||
| ordered, trsMap, err := r.getOrderedTasks(pr) |
| prlo := logOpts(prName, ns, cs, dc, fake.Streamer(fakeLogs), false, false, true) | ||
| prlo.Failed = true | ||
| output, _ := fetchLogs(prlo) |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vdemeester The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
Add a
--log-failedflag totkn pipelinerun logsthat filters outputto only show logs from failed TaskRuns, similar to how GitHub CLI (gh) shows failed job logs. see https://docs.github.com/en/actions/how-tos/monitor-workflows/use-workflow-run-logs#viewing-logs-with-github-cli
Behavior
--log-failedis set, only TaskRuns withConditionFalsestatus are shown--log-failedis set and the PipelineRun is still running, the completed-logs path is used (skips--follow) so only already-failed TaskRuns appear--taskflag (intersection of both filters)Submitter Checklist