From 64f6ffd59dd1c76e73ae41cd81a712cd1726c5e1 Mon Sep 17 00:00:00 2001 From: Renzo Rojas Date: Thu, 19 Jan 2023 14:04:24 -0500 Subject: [PATCH] fix: backport, divide stdout and stderr from helm to not create corrupted outputs (#8333) * fix: backport, set stdout and stderr for helm command to not create corrupted outputs * fix: change log level to Info so `skaffold render --output=render.yaml` produces same output as `skaffold render &> render.yaml` --- pkg/skaffold/deploy/helm/deploy.go | 14 ++++++++++++-- pkg/skaffold/deploy/helm/util.go | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/pkg/skaffold/deploy/helm/deploy.go b/pkg/skaffold/deploy/helm/deploy.go index 563a323c301..37195ee3f74 100644 --- a/pkg/skaffold/deploy/helm/deploy.go +++ b/pkg/skaffold/deploy/helm/deploy.go @@ -439,9 +439,19 @@ func (h *Deployer) Render(ctx context.Context, out io.Writer, builds []graph.Art } outBuffer := new(bytes.Buffer) - if err := h.exec(ctx, outBuffer, false, nil, args...); err != nil { - return userErr("std out err", fmt.Errorf(outBuffer.String())) + errBuffer := new(bytes.Buffer) + + err = h.execWithStdoutAndStderr(ctx, outBuffer, errBuffer, false, nil, args...) + errorMsg := errBuffer.String() + + if len(errorMsg) > 0 { + olog.Entry(ctx).Infof(errorMsg) + } + + if err != nil { + return userErr("std out err", fmt.Errorf(outBuffer.String(), fmt.Errorf(errorMsg))) } + renderedManifests.Write(outBuffer.Bytes()) } diff --git a/pkg/skaffold/deploy/helm/util.go b/pkg/skaffold/deploy/helm/util.go index a06bba04d30..63eca99e3ac 100644 --- a/pkg/skaffold/deploy/helm/util.go +++ b/pkg/skaffold/deploy/helm/util.go @@ -198,8 +198,8 @@ func envVarForImage(imageName string, digest string) map[string]string { return customMap } -// exec executes the helm command, writing combined stdout/stderr to the provided writer -func (h *Deployer) exec(ctx context.Context, out io.Writer, useSecrets bool, env []string, args ...string) error { +// generates the helm command to run according to the given configuration +func (h *Deployer) generateHelmCommand(ctx context.Context, useSecrets bool, env []string, args ...string) *exec.Cmd { args = append([]string{"--kube-context", h.kubeContext}, args...) args = append(args, h.Flags.Global...) @@ -215,8 +215,24 @@ func (h *Deployer) exec(ctx context.Context, out io.Writer, useSecrets bool, env if len(env) > 0 { cmd.Env = env } + + return cmd +} + +// executes the helm command, writing combined stdout/stderr to the provided writer +func (h *Deployer) exec(ctx context.Context, out io.Writer, useSecrets bool, env []string, args ...string) error { + cmd := h.generateHelmCommand(ctx, useSecrets, env, args...) cmd.Stdout = out cmd.Stderr = out return util.RunCmd(ctx, cmd) } + +// executes the helm command, writing stdout and stderr to the provided writers +func (h *Deployer) execWithStdoutAndStderr(ctx context.Context, stdout io.Writer, stderr io.Writer, useSecrets bool, env []string, args ...string) error { + cmd := h.generateHelmCommand(ctx, useSecrets, env, args...) + cmd.Stdout = stdout + cmd.Stderr = stderr + + return util.RunCmd(ctx, cmd) +}