e2e: add func utils.GetFormattedErrorAndLog for logging failed pod

Signed-off-by: Hyeongju Johannes Lee <hyeongju.lee@intel.com>
This commit is contained in:
hj-johannes-lee 2023-07-28 23:16:45 +03:00 committed by Hyeongju Johannes Lee
parent 00c666ac57
commit 4b26ead3ac

View File

@ -17,6 +17,7 @@ package utils
import (
"context"
"fmt"
"io"
"os"
"path/filepath"
@ -41,6 +42,16 @@ const (
poll = time.Second
)
// GetPodLogs returns the log of the container. If not possible to get logs, it returns the error message.
func GetPodLogs(ctx context.Context, f *framework.Framework, podName, containerName string) string {
log, err := e2epod.GetPodLogs(ctx, f.ClientSet, f.Namespace.Name, podName, containerName)
if err != nil {
return fmt.Sprintf("unable to get log from pod: %v", err)
}
return fmt.Sprintf("log output of the container %s in the pod %s:%s", containerName, podName, log)
}
// WaitForNodesWithResource waits for nodes to have positive allocatable resource.
func WaitForNodesWithResource(ctx context.Context, c clientset.Interface, res v1.ResourceName, timeout time.Duration) error {
framework.Logf("Waiting up to %s for any positive allocatable resource %q", timeout, res)