mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-13 05:41:35 +00:00
client-go: Dynamic local port not accessible when port-forwarding
When setting up a port forwarding with the client-go library (using the `k8s.io/client-go/tools/portforward.PortForwarder`) with a non-defined local port (i.e. passing `:80` as `ports` parameter to `portforward.New(...)`), a local port will be assigned dynamically. Currently, the local port will be _always_ 0 if it was not specified initially. This is because the assigned local port is only set on a _copy_ of the actual `ForwardedPort` type that is obtained in a `range` loop. This PR changes this behaviour to set the local port at the correct instance by passing a pointer instead of a copy to the relevant functions. Kubernetes-commit: bbddd27f0dfffe6623763afe2c02c876ba925a7c
This commit is contained in:
committed by
Kubernetes Publisher
parent
91013a0646
commit
e70639fd33
@@ -205,8 +205,9 @@ func (pf *PortForwarder) forward() error {
|
||||
var err error
|
||||
|
||||
listenSuccess := false
|
||||
for _, port := range pf.ports {
|
||||
err = pf.listenOnPort(&port)
|
||||
for i := range pf.ports {
|
||||
port := &pf.ports[i]
|
||||
err = pf.listenOnPort(port)
|
||||
switch {
|
||||
case err == nil:
|
||||
listenSuccess = true
|
||||
|
Reference in New Issue
Block a user