Skip to content

Commit

Permalink
Merge branch 'main' into gerard/sc-114089/remote-host-analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
diamonwiggins authored Oct 31, 2024
2 parents b3992ed + 544a700 commit 054d7a2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/collect/runner.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package collect

import (
"bytes"
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"

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

results <- map[string][]byte{
nodeName: []byte(logs),
nodeName: logs,
}

return nil
Expand Down Expand Up @@ -314,16 +314,16 @@ func WaitForPodCompleted(ctx context.Context, client kubernetes.Interface, names
})
}

func GetContainerLogs(ctx context.Context, client kubernetes.Interface, namespace string, podName string, containerName string, waitForComplete bool, interval time.Duration) (string, error) {
func GetContainerLogs(ctx context.Context, client kubernetes.Interface, namespace string, podName string, containerName string, waitForComplete bool, interval time.Duration) ([]byte, error) {
if waitForComplete {
if err := WaitForPodCompleted(ctx, client, namespace, podName, interval); err != nil {
return "", err
return nil, err
}
}
return getContainerLogsInternal(ctx, client, namespace, podName, containerName, false)
}

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

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

err = retry.OnError(retry.DefaultBackoff, retryableFn, logsFn)
if err != nil {
return "", err
return nil, err
}
if strings.Contains(string(logs), "Internal Error") {
return "", fmt.Errorf("Fetched log contains \"Internal Error\": %q", string(logs))
if bytes.Contains(logs, []byte("Internal Error")) {
return nil, fmt.Errorf("Fetched log contains \"Internal Error\": %q", string(logs))
}

return string(logs), nil
return logs, nil
}

0 comments on commit 054d7a2

Please sign in to comment.