From d0e9b56b75f9e4dbaf0fd1c07fae2a86d67ff1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Mon, 18 Oct 2021 16:33:24 +0200 Subject: [PATCH] ceph: only merge stderr on error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously we were merging the stderr even if it was empty, leading to unmarshall errors. The error simulation was done here https://play.golang.org/p/Sk2yw9GUWNu. Signed-off-by: Sébastien Han (cherry picked from commit 0e41e36ade91575d97012d4c75fd258d48b9ee3b) --- pkg/daemon/ceph/client/command.go | 4 +++- pkg/daemon/ceph/client/command_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/daemon/ceph/client/command.go b/pkg/daemon/ceph/client/command.go index d6288c070787..88646c486563 100644 --- a/pkg/daemon/ceph/client/command.go +++ b/pkg/daemon/ceph/client/command.go @@ -159,7 +159,9 @@ func (c *CephToolCommand) run() ([]byte, error) { if command == RBDTool { if c.RemoteExecution { output, stderr, err = c.context.RemoteExecutor.ExecCommandInContainerWithFullOutputWithTimeout(ProxyAppLabel, CommandProxyInitContainerName, c.clusterInfo.Namespace, append([]string{command}, args...)...) - output = fmt.Sprintf("%s. %s", output, stderr) + if stderr != "" || err != nil { + err = errors.Errorf("%s. %s", err.Error(), stderr) + } } else if c.timeout == 0 { output, err = c.context.Executor.ExecuteCommandWithOutput(command, args...) } else { diff --git a/pkg/daemon/ceph/client/command_test.go b/pkg/daemon/ceph/client/command_test.go index 5cd723ff39bc..85f69c35e257 100644 --- a/pkg/daemon/ceph/client/command_test.go +++ b/pkg/daemon/ceph/client/command_test.go @@ -139,7 +139,7 @@ func TestNewRBDCommand(t *testing.T) { assert.Error(t, err) assert.Len(t, cmd.args, 4) // This is not the best but it shows we go through the right codepath - assert.EqualError(t, err, "no pods found with selector \"rook-ceph-mgr\"") + assert.Contains(t, err.Error(), "no pods found with selector \"rook-ceph-mgr\"") }) }