Merge pull request #95055 from vinaykul/e2e-tests

Add LookForStringInPodExecToContainer(...) that takes container name as argument.
This commit is contained in:
Kubernetes Prow Robot 2020-09-29 12:05:25 -07:00 committed by GitHub
commit aaf9883747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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...)
})