Skip to content

Commit 4b26ead

Browse files
e2e: add func utils.GetFormattedErrorAndLog for logging failed pod
Signed-off-by: Hyeongju Johannes Lee <[email protected]>
1 parent 00c666a commit 4b26ead

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/e2e/utils/utils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package utils
1717

1818
import (
1919
"context"
20+
"fmt"
2021
"io"
2122
"os"
2223
"path/filepath"
@@ -41,6 +42,16 @@ const (
4142
poll = time.Second
4243
)
4344

45+
// GetPodLogs returns the log of the container. If not possible to get logs, it returns the error message.
46+
func GetPodLogs(ctx context.Context, f *framework.Framework, podName, containerName string) string {
47+
log, err := e2epod.GetPodLogs(ctx, f.ClientSet, f.Namespace.Name, podName, containerName)
48+
if err != nil {
49+
return fmt.Sprintf("unable to get log from pod: %v", err)
50+
}
51+
52+
return fmt.Sprintf("log output of the container %s in the pod %s:%s", containerName, podName, log)
53+
}
54+
4455
// WaitForNodesWithResource waits for nodes to have positive allocatable resource.
4556
func WaitForNodesWithResource(ctx context.Context, c clientset.Interface, res v1.ResourceName, timeout time.Duration) error {
4657
framework.Logf("Waiting up to %s for any positive allocatable resource %q", timeout, res)

0 commit comments

Comments
 (0)