Skip to content

refactor: Use IOStreams for command output instead of os.Stdout and log#372

Merged
openshift-merge-bot[bot] merged 2 commits intoshipwright-io:mainfrom
kaizakin:feat/newlogger
Mar 10, 2026
Merged

refactor: Use IOStreams for command output instead of os.Stdout and log#372
openshift-merge-bot[bot] merged 2 commits intoshipwright-io:mainfrom
kaizakin:feat/newlogger

Conversation

@kaizakin
Copy link
Contributor

@kaizakin kaizakin commented Feb 23, 2026

Changes

Fixes #90

The original issue was about inconsistent user facing logging.
Turns out 95% of the codebase is already following the best practice as the same as kubectl.

Following @IrvingMg's suggestion,
I've updated some inconsistencies to follow the same structure as the rest of the commands.

/kind feature

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.

Release Notes

Update user facing logs to follow the same consistent pattern

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note labels Feb 23, 2026
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 23, 2026
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 2, 2026
@kaizakin kaizakin marked this pull request as ready for review March 2, 2026 12:58
Copilot AI review requested due to automatic review settings March 2, 2026 12:58
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 2, 2026
@openshift-ci openshift-ci bot requested review from adambkaplan and rxinui March 2, 2026 12:58
@openshift-ci openshift-ci bot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. and removed release-note labels Mar 2, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes user-facing CLI output by routing it through Kubernetes IOStreams (instead of writing directly to os.Stdout / fmt.Printf / log.Printf), aligning subcommands with the CLI’s existing stream-injection pattern.

Changes:

  • Update version subcommand to accept IOStreams and write to ioStreams.Out.
  • Switch multiple list subcommands’ tabwriter output from os.Stdout to io.Out.
  • Replace log.Printf/os.Stdout output in build upload with fmt.Fprintf(ioStreams.Out, ...) and thread streams through helpers.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/shp/cmd/version/version.go Accepts IOStreams and writes version output to ioStreams.Out.
pkg/shp/cmd/root.go Passes ioStreams into the version command constructor.
pkg/shp/cmd/clusterbuildstrategy/list.go Writes tabular list output to io.Out instead of os.Stdout.
pkg/shp/cmd/buildstrategy/list.go Writes tabular list output to io.Out instead of os.Stdout.
pkg/shp/cmd/buildrun/list.go Writes tabular list output to io.Out instead of os.Stdout.
pkg/shp/cmd/build/upload.go Uses IOStreams for user-facing progress/info output during buildrun creation and streaming.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kaizakin kaizakin changed the title Introduce New logger for centralized loging refactor: Use IOStreams for command output instead of os.Stdout and log Mar 2, 2026
@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 2, 2026
@openshift-ci openshift-ci bot added release-note and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 2, 2026
@kaizakin
Copy link
Contributor Author

kaizakin commented Mar 3, 2026

Verify check failing because of gosec, adding //nolint:gosec to suppress them

@kaizakin
Copy link
Contributor Author

kaizakin commented Mar 3, 2026

Ready to test again @adambkaplan

@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 3, 2026
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 3, 2026
@pull-request-size pull-request-size bot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 3, 2026
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 3, 2026
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 3, 2026
@IrvingMg
Copy link
Member

IrvingMg commented Mar 4, 2026

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Mar 4, 2026
// Run executes the primary business logic of this subcommand, by starting to watch over the build
// pod status and react accordingly.
func (u *UploadCommand) Run(p *params.Params, ioStreams *genericclioptions.IOStreams) error {
u.ioStreams = ioStreams
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this? Wasn’t u.ioStreams initialized before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need that initialization @IrvingMg

u.ioStreams is only declared in the struct and never initialized before Run()

in Complete(), the second parameter is _ *genericclioptions.IOStreams and is intentionally ignored, so u.ioStreams is still nil there.

Methods like createBuildRun and performDataStreaming use u.ioStreams, and they are called from Run

Copy link
Member

Choose a reason for hiding this comment

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

I see. Thanks for checking.

Then I’d just make a small suggestion: move u.ioStreams = ioStreams to Complete, as that method seems more appropriate for initializing the fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, Thanks for the review @IrvingMg

suggested changes has been made and ready for review again 😄

Signed-off-by: karthik balasubramanian <karthikbalasubramanian08@gmail.com>
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 7, 2026
Copy link
Member

@IrvingMg IrvingMg left a comment

Choose a reason for hiding this comment

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

As I mentioned in #90 (comment), it looks like genericclioptions.IOStreams is the common approach for handling output in CLIs. Since shp already uses it in most commands, these changes look good to me.

Still, it would be great to hear feedback from other @shipwright-io/contributors.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 7, 2026
// find out more in kubectl libraries and use them

writer := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
writer := tabwriter.NewWriter(io.Out, 0, 8, 2, '\t', 0)
Copy link
Member

Choose a reason for hiding this comment

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

Can you rename io to ioStreams as in upload.go. I think we should not use variable names that match Golang library packages.

Same in other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the requested changes and it's ready for review @SaschaSchwarze0

@SaschaSchwarze0 SaschaSchwarze0 added this to the release-v0.20.0 milestone Mar 9, 2026
Signed-off-by: karthik balasubramanian <karthikbalasubramanian08@gmail.com>
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 9, 2026
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 10, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 10, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SaschaSchwarze0

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 10, 2026
@openshift-merge-bot openshift-merge-bot bot merged commit 24b225a into shipwright-io:main Mar 10, 2026
10 checks passed
@github-project-automation github-project-automation bot moved this to Done in Issues Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Centralized Logging

5 participants