mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Simplify dual or single port logic
This commit is contained in:
parent
ef2eaa4f8f
commit
dfeb617cc0
@ -185,13 +185,13 @@ func translateServicePortToTargetPort(ports []string, svc corev1.Service, pod co
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// should fail when localPort is empty (=> use random local port)
|
||||
localportnum, err := strconv.Atoi(localPort)
|
||||
// convert the resolved target port back to a string
|
||||
remotePort = strconv.Itoa(int(containerPort))
|
||||
|
||||
if int32(portnum) != containerPort || localPort == "" || (int32(localportnum) != containerPort && err == nil) {
|
||||
translated = append(translated, fmt.Sprintf("%s:%d", localPort, containerPort))
|
||||
if localPort != remotePort {
|
||||
translated = append(translated, fmt.Sprintf("%s:%s", localPort, remotePort))
|
||||
} else {
|
||||
translated = append(translated, fmt.Sprintf("%d", containerPort))
|
||||
translated = append(translated, remotePort)
|
||||
}
|
||||
}
|
||||
return translated, nil
|
||||
|
Loading…
Reference in New Issue
Block a user