mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-15 14:48:16 +00:00
export a method to expose which ports were forwarded
Without this change, the only method to discover what local port was bound (if port 0 was requested) is to parse it out of the "out" stream, which isn't the most reliable method. Kubernetes-commit: a9084923f2bd499c287b675007cb7c6c093d60ad
This commit is contained in:
committed by
Kubernetes Publisher
parent
93821fae80
commit
e1ca545b2c
@@ -340,3 +340,20 @@ func (pf *PortForwarder) Close() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetPorts will return the ports that were forwarded; this can be used to
|
||||
// retrieve the locally-bound port in cases where the input was port 0. This
|
||||
// function will signal an error if the Ready channel is nil or if the
|
||||
// listeners are not ready yet; this function will succeed after the Ready
|
||||
// channel has been closed.
|
||||
func (pf *PortForwarder) GetPorts() ([]ForwardedPort, error) {
|
||||
if pf.Ready == nil {
|
||||
return nil, fmt.Errorf("no Ready channel provided")
|
||||
}
|
||||
select {
|
||||
case <-pf.Ready:
|
||||
return pf.ports, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("listeners not ready")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user