Skip to content

Commit

Permalink
fix: backport, divide stdout and stderr from helm to not create corru…
Browse files Browse the repository at this point in the history
…pted 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`
  • Loading branch information
renzodavid9 authored Jan 19, 2023
1 parent cb5a221 commit 64f6ffd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
14 changes: 12 additions & 2 deletions pkg/skaffold/deploy/helm/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
20 changes: 18 additions & 2 deletions pkg/skaffold/deploy/helm/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand All @@ -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)
}

0 comments on commit 64f6ffd

Please sign in to comment.