port-forward: fixed error handling for empty remote port
Signed-off-by: Omer Aplatony <omerap12@gmail.com> Kubernetes-commit: c01a8a51af10811e182be896795168bbd561c7e9
This commit is contained in:
parent
6989e5df8d
commit
dc6975b78c
|
@ -223,7 +223,9 @@ func convertPodNamedPortToNumber(ports []string, pod corev1.Pod) ([]string, erro
|
|||
var converted []string
|
||||
for _, port := range ports {
|
||||
localPort, remotePort := splitPort(port)
|
||||
|
||||
if remotePort == "" {
|
||||
return nil, fmt.Errorf("remote port cannot be empty")
|
||||
}
|
||||
containerPortStr := remotePort
|
||||
_, err := strconv.Atoi(remotePort)
|
||||
if err != nil {
|
||||
|
|
|
@ -820,6 +820,24 @@ func TestConvertPodNamedPortToNumber(t *testing.T) {
|
|||
ports: []string{"https", "http"},
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
name: "empty port name",
|
||||
pod: corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
ContainerPort: int32(27017)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ports: []string{"28015:"},
|
||||
converted: nil,
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue