fix: route registry messages to stderr in template and show#32217
fix: route registry messages to stderr in template and show#32217amarkdotdev wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR silences output from registry client creation by switching the writer passed into newRegistryClient to io.Discard.
Changes:
- Pass
io.Discardinstead of the commandoutwriter when constructing the registry client intemplate. - Pass
io.Discardinstead of the providedoutwriter when constructing the registry client inshow.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/cmd/template.go | Suppresses registry-client initialization output during template command execution. |
| pkg/cmd/show.go | Suppresses registry-client initialization output during show command execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d821387 to
a92a610
Compare
|
Thanks for the review. Both points were fair —
|
a92a610 to
dd201e9
Compare
|
Gentle ping on this one. The CI is green and the change is small. Would appreciate a maintainer review when someone has bandwidth. Thanks! |
|
All review threads are resolved and CI is green — ready for another look when convenient. |
|
Thanks @amarkdotdev for the contribution. I think we need some tests to avoid regression. |
|
@benoittgt Added |
| registryClient, err := newRegistryClient(cmd.ErrOrStderr(), client.CertFile, client.KeyFile, client.CaFile, | ||
| client.InsecureSkipTLSVerify, client.PlainHTTP, client.Username, client.Password) |
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| client.OutputFormat = action.ShowAll | ||
| err := addRegistryClient(out, client) | ||
| err := addRegistryClient(cmd.ErrOrStderr(), client) | ||
| if err != nil { |
| cmd := newTemplateCmd(actionConfig, stdout) | ||
| cmd.SetOut(stdout) | ||
| cmd.SetErr(stderr) | ||
| cmd.SetArgs([]string{"testdata/testcharts/subchart"}) | ||
|
|
||
| require.NoError(t, cmd.Execute()) | ||
| require.NotEmpty(t, stdout.String()) | ||
| require.NotSame(t, cmd.OutOrStdout(), cmd.ErrOrStderr()) | ||
| } |
When pulling an OCI chart, the registry client prints "Pulled: ..." and "Digest: ..." status lines (and deprecation/underscore warnings) to its configured output writer. Since v4.2.1 (introduced by helm#32056), these messages leaked into the stdout output of helm template and helm show, breaking downstream consumers such as cdk8s and other YAML parsers. Fix by passing the command's stderr to the registry client in the template and show commands instead of stdout. This keeps stdout clean for machine-readable YAML while still surfacing registry warnings and status messages on stderr for troubleshooting, rather than discarding them. The pull/push commands continue to print these messages on their normal output writer. The show command's addRegistryClient writer parameter is renamed to registryOut and wired through to the registry client, so it is no longer a no-op. Fixes helm#32215 Signed-off-by: amarkdotdev <[email protected]>
Exercise helm template and helm show against an in-process OCI registry (repotest.NewOCIServer) and assert Pulled:/Digest: status lines appear on stderr only, keeping stdout free of registry noise. Signed-off-by: amarkdotdev <[email protected]>
26d674e to
f85198a
Compare
| func TestAddRegistryClientUsesProvidedWriter(t *testing.T) { | ||
| writer := &bytes.Buffer{} | ||
| client := action.NewShow(action.ShowChart, &action.Configuration{}) | ||
|
|
||
| require.NoError(t, addRegistryClient(writer, client)) | ||
| } |
What this solves
Since v4.2.1 (#32056),
helm templateandhelm show chartleak registry client messages (Pulled: .../Digest: ...) into stdout, which breaks downstream YAML consumers (e.g. cdk8s panics with "Cannot read properties of undefined").Root cause
The template and show commands passed
out(stdout) to the registry client. ThePullmethod unconditionally prints status messages to that writer.Fix
Pass
cmd.ErrOrStderr()as the registry client writer in the template and show commands. Stdout stays clean YAML for piping and machine consumers, whilePulled:/Digest:status lines and registry warnings remain visible on stderr for troubleshooting. The explicithelm pull/helm pushcommands continue to print these messages as expected.In
show.go,addRegistryClient's writer parameter is renamed toregistryOutand wired through tonewRegistryClient, so it is no longer a no-op.Testing
go test -count=1 -run 'TestTemplateOCIRegistryMessagesNotOnStdout|TestShowOCIRegistryMessagesNotOnStdout|TestAddRegistryClientUsesProvidedWriter' ./pkg/cmd/repotest.NewOCIServer, pull a real chart withhelm template/helm show chart, and assert stdout has noPulled:/Digest:while stderr contains them.Fixes #32215