Skip to content

Commit 544a700

Browse files
[sc-114813] copy HostCollector fails to copy binary files when run in cluster (#1669)
* Don't convert output bytes to string This prevents binary files getting mangled when the collector ourput is being passed around between functions * Update pkg/collect/runner.go Co-authored-by: Evans Mungai <[email protected]> * organise imports --------- Co-authored-by: Evans Mungai <[email protected]>
1 parent 059b5d1 commit 544a700

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pkg/collect/runner.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package collect
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"fmt"
78
"strconv"
8-
"strings"
99
"time"
1010

1111
"github.com/pkg/errors"
@@ -57,7 +57,7 @@ func (r *podRunner) run(ctx context.Context, collector *troubleshootv1beta2.Host
5757
}
5858

5959
results <- map[string][]byte{
60-
nodeName: []byte(logs),
60+
nodeName: logs,
6161
}
6262

6363
return nil
@@ -314,16 +314,16 @@ func WaitForPodCompleted(ctx context.Context, client kubernetes.Interface, names
314314
})
315315
}
316316

317-
func GetContainerLogs(ctx context.Context, client kubernetes.Interface, namespace string, podName string, containerName string, waitForComplete bool, interval time.Duration) (string, error) {
317+
func GetContainerLogs(ctx context.Context, client kubernetes.Interface, namespace string, podName string, containerName string, waitForComplete bool, interval time.Duration) ([]byte, error) {
318318
if waitForComplete {
319319
if err := WaitForPodCompleted(ctx, client, namespace, podName, interval); err != nil {
320-
return "", err
320+
return nil, err
321321
}
322322
}
323323
return getContainerLogsInternal(ctx, client, namespace, podName, containerName, false)
324324
}
325325

326-
func getContainerLogsInternal(ctx context.Context, client kubernetes.Interface, namespace string, podName string, containerName string, previous bool) (string, error) {
326+
func getContainerLogsInternal(ctx context.Context, client kubernetes.Interface, namespace string, podName string, containerName string, previous bool) ([]byte, error) {
327327
var logs []byte
328328
var err error
329329

@@ -349,11 +349,11 @@ func getContainerLogsInternal(ctx context.Context, client kubernetes.Interface,
349349

350350
err = retry.OnError(retry.DefaultBackoff, retryableFn, logsFn)
351351
if err != nil {
352-
return "", err
352+
return nil, err
353353
}
354-
if strings.Contains(string(logs), "Internal Error") {
355-
return "", fmt.Errorf("Fetched log contains \"Internal Error\": %q", string(logs))
354+
if bytes.Contains(logs, []byte("Internal Error")) {
355+
return nil, fmt.Errorf("Fetched log contains \"Internal Error\": %q", string(logs))
356356
}
357357

358-
return string(logs), nil
358+
return logs, nil
359359
}

0 commit comments

Comments
 (0)