From 4e4d629af75ebb7e58f49d195f0ad8fd6ceaa00e Mon Sep 17 00:00:00 2001 From: hasheddan Date: Sun, 19 Jul 2020 10:04:53 -0500 Subject: [PATCH] Return error instead of panic if container index outside bounds Adds check for index out of bounds error instead of panic when passing container to kubectl exec. Signed-off-by: hasheddan --- test/e2e/storage/testsuites/subpath.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/e2e/storage/testsuites/subpath.go b/test/e2e/storage/testsuites/subpath.go index 29adc9f7d3e..3781a5bdbfa 100644 --- a/test/e2e/storage/testsuites/subpath.go +++ b/test/e2e/storage/testsuites/subpath.go @@ -1059,6 +1059,9 @@ func formatVolume(f *framework.Framework, pod *v1.Pod) { } func podContainerExec(pod *v1.Pod, containerIndex int, command string) (string, error) { + if containerIndex > len(pod.Spec.Containers)-1 { + return "", fmt.Errorf("container not found in pod: index %d", containerIndex) + } var shell string var option string if framework.NodeOSDistroIs("windows") {