Simplify dual or single port logic

This commit is contained in:
Jordan Liggitt 2020-03-23 22:04:14 -04:00
parent ef2eaa4f8f
commit dfeb617cc0

View File

@ -185,13 +185,13 @@ func translateServicePortToTargetPort(ports []string, svc corev1.Service, pod co
return nil, err return nil, err
} }
// should fail when localPort is empty (=> use random local port) // convert the resolved target port back to a string
localportnum, err := strconv.Atoi(localPort) remotePort = strconv.Itoa(int(containerPort))
if int32(portnum) != containerPort || localPort == "" || (int32(localportnum) != containerPort && err == nil) { if localPort != remotePort {
translated = append(translated, fmt.Sprintf("%s:%d", localPort, containerPort)) translated = append(translated, fmt.Sprintf("%s:%s", localPort, remotePort))
} else { } else {
translated = append(translated, fmt.Sprintf("%d", containerPort)) translated = append(translated, remotePort)
} }
} }
return translated, nil return translated, nil