-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update SyncPluginsForTarget API to allow configuring stdout
and stderr
externally
#88
Conversation
46c31cf
to
79f6bfc
Compare
stdout
and stderr
optionsstdout
and stderr
externally
stdout
and stderr
externallystdout
and stderr
externally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the flexibility of this approach @anujc25.
So this LGTM if we are ok with breaking the experimental API.
P.S.
If anyone is curious (as I was), after quick googling, I confirmed that this API even allows to write to stdout/stderr
and at the same time have the plugin capture the output using io.MultiWriter
, to allow a plugin to check the final output.
var out bytes.Buffer
w := io.MultiWriter(os.Stdout, &out)
err := plugin.SyncPluginsForTarget(types.TargetK8s, plugin.WithStderr(w))
// process out.String()
Thanks @marckhouzam for the review and feedback. I like the However, I am not sure we should always write to So I am thinking maybe we can use this |
2e2080b
to
63a8e2d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! I think this is a very nice API.
We are mixing terminology between stdout
and any other output stream.
For example WithStdout
is meant to set a output stream, not necessarily to stdout
, while WithNoStdout()
is meant to remove the use of stdout
. I recommend a bit of renaming. I've put suggestions in-line.
63a8e2d
to
f187b51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit about the original example I gave you being wrong but the rest LGTM.
Thanks @anujc25 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice enhancement, thanks for the changes. Just some nits on a comment block and the PR description.
On the PR description:
We mention that API outputs to stdout/err by default, but it is not sufficiently clear IMO that this behavior is new.
Maybe a tweak to the description would be to augment with something like
Note: Unlike before, the API will now write the output/error of the plugin sync operation to stderr and stdout by default. Callers who previously manage the output by processing the return values of the API call should consider turning off the default writing to the os.Stdout and os.Stderr by passing WithNoStdout and WithNoStderr options as the additional parameters to the function call in order to avoid duplicate echoing.
It wouldn't hurt to make it a tad clearer in the release note as well.
Finally, given that we mentioned WithNoStdout and WithNoStderr, its seems consistent with describing overriding output and error streams to mention WithOutputWriter and WithErrorWriter as well.
88035be
to
7d7cab3
Compare
What this PR does / why we need it
The
TanzuPluginSyncForTarget
API is exposed to sync plugins as an experimental API.stdout
andstderr
are returned as part of the API and are not actively written to thestdout
orstderr
.This change exposes additional
CommandOptions
to configure theoutputWriter
anderrorWriter
usingWithOutputWriter
andWithErrorWriter
options when invoking theTanzuPluginSyncForTarget
API, along with writing the output directly to theos.Stdout
andos.Stderr
by default.Note: Unlike before, the API will now write the output/error of the plugin sync operation to stderr and stdout by default. Callers who previously manage the output by processing the return values of the API call should consider turning off the default writing to the os.Stdout and os.Stderr by passing WithNoStdout and WithNoStderr options as the additional parameters to the function call in order to avoid duplicate echoing.
Which issue(s) this PR fixes
Fixes #
Describe testing done for PR
Release note
Additional information
Special notes for your reviewer