Skip to content

Commit

Permalink
Simplify dual or single port logic
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Mar 24, 2020
1 parent ef2eaa4 commit dfeb617
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions staging/src/k8s.io/kubectl/pkg/cmd/portforward/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dfeb617

Please sign in to comment.