From 7afe321c3915a0a47145d4c0f06d96f3917d1735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20N=C3=A4gele?= Date: Tue, 3 Nov 2020 20:59:01 +0100 Subject: [PATCH] Ignore stderr when parsing Helm version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helm v3.4.0 logs a warning about URL deprecation which causes semver parsing to fail. We need to only read stdout and ignore stderr here. Signed-off-by: Reinhard Nägele --- pkg/exec/exec.go | 19 +++++++++++++++++++ pkg/tool/helm.go | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/exec/exec.go b/pkg/exec/exec.go index 6220fbd1..3ab4bec9 100644 --- a/pkg/exec/exec.go +++ b/pkg/exec/exec.go @@ -40,6 +40,10 @@ func (p ProcessExecutor) RunProcessAndCaptureOutput(executable string, execArgs return p.RunProcessInDirAndCaptureOutput("", executable, execArgs) } +func (p ProcessExecutor) RunProcessAndCaptureStdout(executable string, execArgs ...interface{}) (string, error) { + return p.RunProcessInDirAndCaptureStdout("", executable, execArgs) +} + func (p ProcessExecutor) RunProcessInDirAndCaptureOutput(workingDirectory string, executable string, execArgs ...interface{}) (string, error) { cmd, err := p.CreateProcess(executable, execArgs...) if err != nil { @@ -55,6 +59,21 @@ func (p ProcessExecutor) RunProcessInDirAndCaptureOutput(workingDirectory string return strings.TrimSpace(string(bytes)), nil } +func (p ProcessExecutor) RunProcessInDirAndCaptureStdout(workingDirectory string, executable string, execArgs ...interface{}) (string, error) { + cmd, err := p.CreateProcess(executable, execArgs...) + if err != nil { + return "", err + } + + cmd.Dir = workingDirectory + bytes, err := cmd.Output() + + if err != nil { + return "", errors.Wrap(err, "Error running process") + } + return strings.TrimSpace(string(bytes)), nil +} + func (p ProcessExecutor) RunProcess(executable string, execArgs ...interface{}) error { cmd, err := p.CreateProcess(executable, execArgs...) if err != nil { diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index bcb01d6c..ffea48ab 100644 --- a/pkg/tool/helm.go +++ b/pkg/tool/helm.go @@ -84,5 +84,5 @@ func (h Helm) DeleteRelease(namespace string, release string) { } func (h Helm) Version() (string, error) { - return h.exec.RunProcessAndCaptureOutput("helm", "version", "--short") + return h.exec.RunProcessAndCaptureStdout("helm", "version", "--short") }