diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index a48eda3cdd9..8bf52af18ac 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -503,12 +503,15 @@ func RandomSuffix() string { } // LookForStringInPodExec looks for the given string in the output of a command -// executed in a specific pod container. +// executed in specified pod container, or the first container if not specified. // 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) { +func LookForStringInPodExec(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...) }) diff --git a/test/e2e/framework/volume/fixtures.go b/test/e2e/framework/volume/fixtures.go index 7e687f3ef8a..2cd0837ee78 100644 --- a/test/e2e/framework/volume/fixtures.go +++ b/test/e2e/framework/volume/fixtures.go @@ -458,7 +458,7 @@ func testVolumeContent(f *framework.Framework, pod *v1.Pod, fsGroup *int64, fsTy // Block: check content deviceName := fmt.Sprintf("/opt/%d", i) commands := generateReadBlockCmd(deviceName, len(test.ExpectedContent)) - _, err := framework.LookForStringInPodExec(pod.Namespace, pod.Name, commands, test.ExpectedContent, time.Minute) + _, err := framework.LookForStringInPodExec(pod.Namespace, pod.Name, "", commands, test.ExpectedContent, time.Minute) framework.ExpectNoError(err, "failed: finding the contents of the block device %s.", deviceName) // Check that it's a real block device @@ -467,7 +467,7 @@ func testVolumeContent(f *framework.Framework, pod *v1.Pod, fsGroup *int64, fsTy // Filesystem: check content fileName := fmt.Sprintf("/opt/%d/%s", i, test.File) commands := generateReadFileCmd(fileName) - _, err := framework.LookForStringInPodExec(pod.Namespace, pod.Name, commands, test.ExpectedContent, time.Minute) + _, err := framework.LookForStringInPodExec(pod.Namespace, pod.Name, "", commands, test.ExpectedContent, time.Minute) framework.ExpectNoError(err, "failed: finding the contents of the mounted file %s.", fileName) // Check that a directory has been mounted @@ -478,14 +478,14 @@ func testVolumeContent(f *framework.Framework, pod *v1.Pod, fsGroup *int64, fsTy // Filesystem: check fsgroup if fsGroup != nil { ginkgo.By("Checking fsGroup is correct.") - _, err = framework.LookForStringInPodExec(pod.Namespace, pod.Name, []string{"ls", "-ld", dirName}, strconv.Itoa(int(*fsGroup)), time.Minute) + _, err = framework.LookForStringInPodExec(pod.Namespace, pod.Name, "", []string{"ls", "-ld", dirName}, strconv.Itoa(int(*fsGroup)), time.Minute) framework.ExpectNoError(err, "failed: getting the right privileges in the file %v", int(*fsGroup)) } // Filesystem: check fsType if fsType != "" { ginkgo.By("Checking fsType is correct.") - _, err = framework.LookForStringInPodExec(pod.Namespace, pod.Name, []string{"grep", " " + dirName + " ", "/proc/mounts"}, fsType, time.Minute) + _, err = framework.LookForStringInPodExec(pod.Namespace, pod.Name, "", []string{"grep", " " + dirName + " ", "/proc/mounts"}, fsType, time.Minute) framework.ExpectNoError(err, "failed: getting the right fsType %s", fsType) } } diff --git a/test/e2e/network/example_cluster_dns.go b/test/e2e/network/example_cluster_dns.go index 38859856e99..102e7bb42f5 100644 --- a/test/e2e/network/example_cluster_dns.go +++ b/test/e2e/network/example_cluster_dns.go @@ -140,7 +140,7 @@ var _ = SIGDescribe("ClusterDns [Feature:Example]", func() { podName := pods.Items[0].Name queryDNS := fmt.Sprintf(queryDNSPythonTemplate, backendSvcName+"."+namespaces[0].Name) - _, err = framework.LookForStringInPodExec(namespaces[0].Name, podName, []string{"python", "-c", queryDNS}, "ok", dnsReadyTimeout) + _, err = framework.LookForStringInPodExec(namespaces[0].Name, podName, "", []string{"python", "-c", queryDNS}, "ok", dnsReadyTimeout) framework.ExpectNoError(err, "waiting for output from pod exec") updatedPodYaml := prepareResourceWithReplacedString(frontendPodYaml, fmt.Sprintf("dns-backend.development.svc.%s", framework.TestContext.ClusterDNSDomain), fmt.Sprintf("dns-backend.%s.svc.%s", namespaces[0].Name, framework.TestContext.ClusterDNSDomain)) diff --git a/test/e2e/storage/persistent_volumes-local.go b/test/e2e/storage/persistent_volumes-local.go index 13e97e96fe3..7ea4f512d60 100644 --- a/test/e2e/storage/persistent_volumes-local.go +++ b/test/e2e/storage/persistent_volumes-local.go @@ -791,7 +791,7 @@ func twoPodsReadWriteSerialTest(f *framework.Framework, config *localTestConfig, func createPodWithFsGroupTest(config *localTestConfig, testVol *localTestVolume, fsGroup int64, expectedFsGroup int64) *v1.Pod { pod, err := createLocalPod(config, testVol, &fsGroup) framework.ExpectNoError(err) - _, err = framework.LookForStringInPodExec(config.ns, pod.Name, []string{"stat", "-c", "%g", volumeDir}, strconv.FormatInt(expectedFsGroup, 10), time.Second*3) + _, err = framework.LookForStringInPodExec(config.ns, pod.Name, "", []string{"stat", "-c", "%g", volumeDir}, strconv.FormatInt(expectedFsGroup, 10), time.Second*3) framework.ExpectNoError(err, "failed to get expected fsGroup %d on directory %s in pod %s", fsGroup, volumeDir, pod.Name) return pod } diff --git a/test/e2e/storage/vsphere/vsphere_utils.go b/test/e2e/storage/vsphere/vsphere_utils.go index b1623eabfa4..1cef929c27a 100644 --- a/test/e2e/storage/vsphere/vsphere_utils.go +++ b/test/e2e/storage/vsphere/vsphere_utils.go @@ -381,7 +381,7 @@ func verifyVSphereVolumesAccessible(c clientset.Interface, pod *v1.Pod, persiste framework.ExpectEqual(isAttached, true, fmt.Sprintf("disk %v is not attached with the node", pv.Spec.VsphereVolume.VolumePath)) // Verify Volumes are accessible filepath := filepath.Join("/mnt/", fmt.Sprintf("volume%v", index+1), "/emptyFile.txt") - _, err = framework.LookForStringInPodExec(namespace, pod.Name, []string{"/bin/touch", filepath}, "", time.Minute) + _, err = framework.LookForStringInPodExec(namespace, pod.Name, "", []string{"/bin/touch", filepath}, "", time.Minute) framework.ExpectNoError(err) } } diff --git a/test/e2e/storage/vsphere/vsphere_volume_fstype.go b/test/e2e/storage/vsphere/vsphere_volume_fstype.go index b7e1d5c88e6..41e20397464 100644 --- a/test/e2e/storage/vsphere/vsphere_volume_fstype.go +++ b/test/e2e/storage/vsphere/vsphere_volume_fstype.go @@ -107,7 +107,7 @@ func invokeTestForFstype(f *framework.Framework, client clientset.Interface, nam // Create Pod and verify the persistent volume is accessible pod := createPodAndVerifyVolumeAccessible(client, namespace, pvclaim, persistentvolumes) - _, err := framework.LookForStringInPodExec(namespace, pod.Name, []string{"/bin/cat", "/mnt/volume1/fstype"}, expectedContent, time.Minute) + _, err := framework.LookForStringInPodExec(namespace, pod.Name, "", []string{"/bin/cat", "/mnt/volume1/fstype"}, expectedContent, time.Minute) framework.ExpectNoError(err) // Detach and delete volume