Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
38a32525
Unverified
Commit
38a32525
authored
Feb 26, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Feb 26, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #73676 from martin-helmich/bugfix/expose-forwarded-local-port
client-go: Dynamically assigned local port number not retrievable when port-forwarding
parents
4505f122
bbddd27f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
2 deletions
+79
-2
portforward.go
...ing/src/k8s.io/client-go/tools/portforward/portforward.go
+3
-2
portforward_test.go
...rc/k8s.io/client-go/tools/portforward/portforward_test.go
+76
-0
No files found.
staging/src/k8s.io/client-go/tools/portforward/portforward.go
View file @
38a32525
...
...
@@ -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
...
...
staging/src/k8s.io/client-go/tools/portforward/portforward_test.go
View file @
38a32525
...
...
@@ -18,11 +18,13 @@ package portforward
import
(
"net"
"net/http"
"os"
"reflect"
"sort"
"strings"
"testing"
"time"
"k8s.io/apimachinery/pkg/util/httpstream"
)
...
...
@@ -39,6 +41,37 @@ func (d *fakeDialer) Dial(protocols ...string) (httpstream.Connection, string, e
return
d
.
conn
,
d
.
negotiatedProtocol
,
d
.
err
}
type
fakeConnection
struct
{
closed
bool
closeChan
chan
bool
}
func
newFakeConnection
()
httpstream
.
Connection
{
return
&
fakeConnection
{
closeChan
:
make
(
chan
bool
),
}
}
func
(
c
*
fakeConnection
)
CreateStream
(
headers
http
.
Header
)
(
httpstream
.
Stream
,
error
)
{
return
nil
,
nil
}
func
(
c
*
fakeConnection
)
Close
()
error
{
if
!
c
.
closed
{
c
.
closed
=
true
close
(
c
.
closeChan
)
}
return
nil
}
func
(
c
*
fakeConnection
)
CloseChan
()
<-
chan
bool
{
return
c
.
closeChan
}
func
(
c
*
fakeConnection
)
SetIdleTimeout
(
timeout
time
.
Duration
)
{
// no-op
}
func
TestParsePortsAndNew
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
input
[]
string
...
...
@@ -310,3 +343,46 @@ func TestGetListener(t *testing.T) {
}
}
func
TestGetPortsReturnsDynamicallyAssignedLocalPort
(
t
*
testing
.
T
)
{
dialer
:=
&
fakeDialer
{
conn
:
newFakeConnection
(),
}
stopChan
:=
make
(
chan
struct
{})
readyChan
:=
make
(
chan
struct
{})
errChan
:=
make
(
chan
error
)
defer
func
()
{
close
(
stopChan
)
forwardErr
:=
<-
errChan
if
forwardErr
!=
nil
{
t
.
Fatalf
(
"ForwardPorts returned error: %s"
,
forwardErr
)
}
}()
pf
,
err
:=
New
(
dialer
,
[]
string
{
":5000"
},
stopChan
,
readyChan
,
os
.
Stdout
,
os
.
Stderr
)
if
err
!=
nil
{
t
.
Fatalf
(
"error while calling New: %s"
,
err
)
}
go
func
()
{
errChan
<-
pf
.
ForwardPorts
()
close
(
errChan
)
}()
<-
pf
.
Ready
ports
,
err
:=
pf
.
GetPorts
()
if
len
(
ports
)
!=
1
{
t
.
Fatalf
(
"expected 1 port, got %d"
,
len
(
ports
))
}
port
:=
ports
[
0
]
if
port
.
Local
==
0
{
t
.
Fatalf
(
"local port is 0, expected != 0"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment