diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index a48eda3cdd9..b8c493dd08b 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -503,12 +503,21 @@ func RandomSuffix() string { } // LookForStringInPodExec looks for the given string in the output of a command -// executed in a specific pod container. +// executed in the first container of specified pod. // TODO(alejandrox1): move to pod/ subpkg once kubectl methods are refactored. func LookForStringInPodExec(ns, podName string, command []string, expectedString string, timeout time.Duration) (result string, err error) { + return LookForStringInPodExecToContainer(ns, podName, "", command, expectedString, timeout) +} + +// LookForStringInPodExecToContainer looks for the given string in the output of a +// command executed in specified pod container, or first container if not specified. +func LookForStringInPodExecToContainer(ns, podName, containerName string, command []string, expectedString string, timeout time.Duration) (result string, err error) { return lookForString(expectedString, timeout, func() string { - // use the first container - args := []string{"exec", podName, fmt.Sprintf("--namespace=%v", ns), "--"} + args := []string{"exec", podName, fmt.Sprintf("--namespace=%v", ns)} + if len(containerName) > 0 { + args = append(args, fmt.Sprintf("--container=%s", containerName)) + } + args = append(args, "--") args = append(args, command...) return RunKubectlOrDie(ns, args...) })