diff --git a/test/e2e/docker_containers.go b/test/e2e/docker_containers.go index d1e90b6c8be..aa08670317f 100644 --- a/test/e2e/docker_containers.go +++ b/test/e2e/docker_containers.go @@ -45,7 +45,7 @@ var _ = Describe("Docker Containers", func() { }) It("should use the image defaults if command and args are blank", func() { - testContainerOutputInNamespace("use defaults", c, entrypointTestPod(), []string{ + testContainerOutputInNamespace("use defaults", c, entrypointTestPod(), 0, []string{ "[/ep default arguments]", }, ns) }) @@ -54,7 +54,7 @@ var _ = Describe("Docker Containers", func() { pod := entrypointTestPod() pod.Spec.Containers[0].Args = []string{"override", "arguments"} - testContainerOutputInNamespace("override arguments", c, pod, []string{ + testContainerOutputInNamespace("override arguments", c, pod, 0, []string{ "[/ep override arguments]", }, ns) }) @@ -65,7 +65,7 @@ var _ = Describe("Docker Containers", func() { pod := entrypointTestPod() pod.Spec.Containers[0].Command = []string{"/ep-2"} - testContainerOutputInNamespace("override command", c, pod, []string{ + testContainerOutputInNamespace("override command", c, pod, 0, []string{ "[/ep-2]", }, ns) }) @@ -75,7 +75,7 @@ var _ = Describe("Docker Containers", func() { pod.Spec.Containers[0].Command = []string{"/ep-2"} pod.Spec.Containers[0].Args = []string{"override", "arguments"} - testContainerOutputInNamespace("override all", c, pod, []string{ + testContainerOutputInNamespace("override all", c, pod, 0, []string{ "[/ep-2 override arguments]", }, ns) }) diff --git a/test/e2e/downward_api.go b/test/e2e/downward_api.go index 15be7a95a89..7e98897b32a 100644 --- a/test/e2e/downward_api.go +++ b/test/e2e/downward_api.go @@ -88,7 +88,7 @@ var _ = Describe("Downward API", func() { }, } - testContainerOutputInNamespace("downward api env vars", c, pod, []string{ + testContainerOutputInNamespace("downward api env vars", c, pod, 0, []string{ fmt.Sprintf("POD_NAME=%v", podName), fmt.Sprintf("POD_NAMESPACE=%v", ns), }, ns) diff --git a/test/e2e/empty_dir.go b/test/e2e/empty_dir.go index 526fa7aa2be..473789ad5da 100644 --- a/test/e2e/empty_dir.go +++ b/test/e2e/empty_dir.go @@ -41,7 +41,7 @@ var _ = Describe("EmptyDir volumes", func() { fmt.Sprintf("--fs_type=%v", volumePath), fmt.Sprintf("--file_mode=%v", volumePath), } - f.TestContainerOutput("emptydir r/w on tmpfs", pod, []string{ + f.TestContainerOutput("emptydir r/w on tmpfs", pod, 0, []string{ "mount type of \"/test-volume\": tmpfs", "mode of file \"/test-volume\": dtrwxrwxrwx", // we expect the sticky bit (mode flag t) to be set for the dir }) @@ -60,7 +60,7 @@ var _ = Describe("EmptyDir volumes", func() { fmt.Sprintf("--rw_new_file=%v", filePath), fmt.Sprintf("--file_mode=%v", filePath), } - f.TestContainerOutput("emptydir r/w on tmpfs", pod, []string{ + f.TestContainerOutput("emptydir r/w on tmpfs", pod, 0, []string{ "mount type of \"/test-volume\": tmpfs", "mode of file \"/test-volume/test-file\": -rw-r--r--", "content of file \"/test-volume/test-file\": mount-tester new file", diff --git a/test/e2e/framework.go b/test/e2e/framework.go index d7a42330d5a..4f31c914d38 100644 --- a/test/e2e/framework.go +++ b/test/e2e/framework.go @@ -99,9 +99,9 @@ func (f *Framework) WaitForPodRunning(podName string) error { return waitForPodRunningInNamespace(f.Client, podName, f.Namespace.Name) } -// Runs the given pod and verifies that its output matches the desired output. -func (f *Framework) TestContainerOutput(scenarioName string, pod *api.Pod, expectedOutput []string) { - testContainerOutputInNamespace(scenarioName, f.Client, pod, expectedOutput, f.Namespace.Name) +// Runs the given pod and verifies that the output of exact container matches the desired output. +func (f *Framework) TestContainerOutput(scenarioName string, pod *api.Pod, containerIndex int, expectedOutput []string) { + testContainerOutputInNamespace(scenarioName, f.Client, pod, containerIndex, expectedOutput, f.Namespace.Name) } // WaitForAnEndpoint waits for at least one endpoint to become available in the diff --git a/test/e2e/host_path.go b/test/e2e/host_path.go index f6ea59dd558..18ca46f8264 100644 --- a/test/e2e/host_path.go +++ b/test/e2e/host_path.go @@ -68,7 +68,7 @@ var _ = Describe("hostDir", func() { fmt.Sprintf("--fs_type=%v", volumePath), fmt.Sprintf("--file_mode=%v", volumePath), } - testContainerOutputInNamespace("emptydir r/w on tmpfs", c, pod, []string{ + testContainerOutputInNamespace("emptydir r/w on tmpfs", c, pod, 0, []string{ "mode of file \"/test-volume\": dtrwxrwxrwx", // we expect the sticky bit (mode flag t) to be set for the dir }, namespace.Name) @@ -87,7 +87,7 @@ var _ = Describe("hostDir", func() { fmt.Sprintf("--rw_new_file=%v", filePath), fmt.Sprintf("--file_mode=%v", filePath), } - testContainerOutputInNamespace("emptydir r/w on tmpfs", c, pod, []string{ + testContainerOutputInNamespace("emptydir r/w on tmpfs", c, pod, 0, []string{ "mode of file \"/test-volume/test-file\": -rw-r--r--", "content of file \"/test-volume/test-file\": mount-tester new file", }, namespace.Name, diff --git a/test/e2e/pods.go b/test/e2e/pods.go index 6c164ca3205..bb9da381957 100644 --- a/test/e2e/pods.go +++ b/test/e2e/pods.go @@ -451,7 +451,7 @@ var _ = Describe("Pods", func() { }, } - testContainerOutput("service env", c, pod, []string{ + testContainerOutput("service env", c, pod, 0, []string{ "FOOSERVICE_SERVICE_HOST=", "FOOSERVICE_SERVICE_PORT=", "FOOSERVICE_PORT=", diff --git a/test/e2e/secrets.go b/test/e2e/secrets.go index a25d54d8c87..048962bed24 100644 --- a/test/e2e/secrets.go +++ b/test/e2e/secrets.go @@ -92,7 +92,7 @@ var _ = Describe("Secrets", func() { }, } - testContainerOutputInNamespace("consume secrets", f.Client, pod, []string{ + testContainerOutputInNamespace("consume secrets", f.Client, pod, 0, []string{ "content of file \"/etc/secret-volume/data-1\": value-1", "mode of file \"/etc/secret-volume/data-1\": -r--r--r--", }, f.Namespace.Name) diff --git a/test/e2e/service_accounts.go b/test/e2e/service_accounts.go index 89cdf90d21a..117179290ec 100644 --- a/test/e2e/service_accounts.go +++ b/test/e2e/service_accounts.go @@ -75,7 +75,7 @@ var _ = Describe("ServiceAccounts", func() { }, } - f.TestContainerOutput("consume service account token", pod, []string{ + f.TestContainerOutput("consume service account token", pod, 0, []string{ fmt.Sprintf(`content of file "%s/%s": %s`, serviceaccount.DefaultAPITokenMountPath, api.ServiceAccountTokenKey, tokenContent), }) }) diff --git a/test/e2e/util.go b/test/e2e/util.go index 1f4dc6341c1..edc6f70d986 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -783,14 +783,14 @@ func runKubectl(args ...string) string { } // testContainerOutput runs testContainerOutputInNamespace with the default namespace. -func testContainerOutput(scenarioName string, c *client.Client, pod *api.Pod, expectedOutput []string) { - testContainerOutputInNamespace(scenarioName, c, pod, expectedOutput, api.NamespaceDefault) +func testContainerOutput(scenarioName string, c *client.Client, pod *api.Pod, containerIndex int, expectedOutput []string) { + testContainerOutputInNamespace(scenarioName, c, pod, containerIndex, expectedOutput, api.NamespaceDefault) } // testContainerOutputInNamespace runs the given pod in the given namespace and waits -// for the first container in the podSpec to move into the 'Success' status. It retrieves -// the container log and searches for lines of expected output. -func testContainerOutputInNamespace(scenarioName string, c *client.Client, pod *api.Pod, expectedOutput []string, ns string) { +// for all of the containers in the podSpec to move into the 'Success' status. It retrieves +// the exact container log and searches for lines of expected output. +func testContainerOutputInNamespace(scenarioName string, c *client.Client, pod *api.Pod, containerIndex int, expectedOutput []string, ns string) { By(fmt.Sprintf("Creating a pod to test %v", scenarioName)) defer c.Pods(ns).Delete(pod.Name, nil) @@ -798,10 +798,17 @@ func testContainerOutputInNamespace(scenarioName string, c *client.Client, pod * Failf("Failed to create pod: %v", err) } - containerName := pod.Spec.Containers[0].Name - // Wait for client pod to complete. - expectNoError(waitForPodSuccessInNamespace(c, pod.Name, containerName, ns)) + var containerName string + for id, container := range pod.Spec.Containers { + expectNoError(waitForPodSuccessInNamespace(c, pod.Name, container.Name, ns)) + if id == containerIndex { + containerName = container.Name + } + } + if containerName == "" { + Failf("Invalid container index: %d", containerIndex) + } // Grab its logs. Get host first. podStatus, err := c.Pods(ns).Get(pod.Name)