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 <georgedanielmangum@gmail.com>
This commit is contained in:
hasheddan 2020-07-19 10:04:53 -05:00
parent 3a0b683c01
commit 4e4d629af7
No known key found for this signature in database
GPG Key ID: BD68BC686A14C271

View File

@ -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") {