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
9cc47e3b
Commit
9cc47e3b
authored
Nov 14, 2018
by
Mikalai Radchuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes flaky tests for kubectl port-forward
parent
504466c4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
68 deletions
+30
-68
portforward.go
test/e2e/kubectl/portforward.go
+30
-68
No files found.
test/e2e/kubectl/portforward.go
View file @
9cc47e3b
...
...
@@ -47,6 +47,11 @@ const (
podName
=
"pfpod"
)
const
(
podCheckInterval
=
1
*
time
.
Second
postStartWaitTimeout
=
2
*
time
.
Minute
)
// TODO support other ports besides 80
var
(
portForwardRegexp
=
regexp
.
MustCompile
(
"Forwarding from (127.0.0.1|
\\
[::1
\\
]):([0-9]+) -> 80"
)
...
...
@@ -202,14 +207,6 @@ func doTestConnectSendDisconnect(bindAddress string, f *framework.Framework) {
if
err
:=
f
.
WaitForPodReady
(
pod
.
Name
);
err
!=
nil
{
framework
.
Failf
(
"Pod did not start running: %v"
,
err
)
}
defer
func
()
{
logs
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
if
err
!=
nil
{
framework
.
Logf
(
"Error getting pod log: %v"
,
err
)
}
else
{
framework
.
Logf
(
"Pod log:
\n
%s"
,
logs
)
}
}()
By
(
"Running 'kubectl port-forward'"
)
cmd
:=
runPortForward
(
f
.
Namespace
.
Name
,
pod
.
Name
,
80
)
...
...
@@ -241,12 +238,12 @@ func doTestConnectSendDisconnect(bindAddress string, f *framework.Framework) {
}
By
(
"Verifying logs"
)
logOutput
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
if
err
!=
nil
{
framework
.
Failf
(
"Error retrieving pod logs: %v"
,
err
)
}
verifyLogMessage
(
logOutput
,
"Accepted client connection"
)
verifyLogMessage
(
logOutput
,
"Done"
)
Eventually
(
func
()
(
string
,
error
)
{
return
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
},
postStartWaitTimeout
,
podCheckInterval
)
.
Should
(
SatisfyAll
(
ContainSubstring
(
"Accepted client connection"
),
ContainSubstring
(
"Done"
),
)
)
}
func
doTestMustConnectSendNothing
(
bindAddress
string
,
f
*
framework
.
Framework
)
{
...
...
@@ -258,14 +255,6 @@ func doTestMustConnectSendNothing(bindAddress string, f *framework.Framework) {
if
err
:=
f
.
WaitForPodReady
(
pod
.
Name
);
err
!=
nil
{
framework
.
Failf
(
"Pod did not start running: %v"
,
err
)
}
defer
func
()
{
logs
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
if
err
!=
nil
{
framework
.
Logf
(
"Error getting pod log: %v"
,
err
)
}
else
{
framework
.
Logf
(
"Pod log:
\n
%s"
,
logs
)
}
}()
By
(
"Running 'kubectl port-forward'"
)
cmd
:=
runPortForward
(
f
.
Namespace
.
Name
,
pod
.
Name
,
80
)
...
...
@@ -286,12 +275,12 @@ func doTestMustConnectSendNothing(bindAddress string, f *framework.Framework) {
}
By
(
"Verifying logs"
)
logOutput
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
if
err
!=
nil
{
framework
.
Failf
(
"Error retrieving pod logs: %v"
,
err
)
}
verifyLogMessage
(
logOutput
,
"Accepted client connection"
)
verifyLogMessage
(
logOutput
,
"Expected to read 3 bytes from client, but got 0 instead"
)
Eventually
(
func
()
(
string
,
error
)
{
return
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
},
postStartWaitTimeout
,
podCheckInterval
)
.
Should
(
SatisfyAll
(
ContainSubstring
(
"Accepted client connection"
),
ContainSubstring
(
"Expected to read 3 bytes from client, but got 0 instead"
),
)
)
}
func
doTestMustConnectSendDisconnect
(
bindAddress
string
,
f
*
framework
.
Framework
)
{
...
...
@@ -303,14 +292,6 @@ func doTestMustConnectSendDisconnect(bindAddress string, f *framework.Framework)
if
err
:=
f
.
WaitForPodReady
(
pod
.
Name
);
err
!=
nil
{
framework
.
Failf
(
"Pod did not start running: %v"
,
err
)
}
defer
func
()
{
logs
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
if
err
!=
nil
{
framework
.
Logf
(
"Error getting pod log: %v"
,
err
)
}
else
{
framework
.
Logf
(
"Pod log:
\n
%s"
,
logs
)
}
}()
By
(
"Running 'kubectl port-forward'"
)
cmd
:=
runPortForward
(
f
.
Namespace
.
Name
,
pod
.
Name
,
80
)
...
...
@@ -352,13 +333,13 @@ func doTestMustConnectSendDisconnect(bindAddress string, f *framework.Framework)
}
By
(
"Verifying logs"
)
logOutput
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
if
err
!=
nil
{
framework
.
Failf
(
"Error retrieving pod logs: %v"
,
err
)
}
verifyLogMessage
(
logOutput
,
"^Accepted client connection$"
)
verifyLogMessage
(
logOutput
,
"^Received expected client data$"
)
verifyLogMessage
(
logOutput
,
"^Done$"
)
Eventually
(
func
()
(
string
,
error
)
{
return
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
},
postStartWaitTimeout
,
podCheckInterval
)
.
Should
(
SatisfyAll
(
ContainSubstring
(
"Accepted client connection"
),
ContainSubstring
(
"Received expected client data"
),
ContainSubstring
(
"Done"
),
)
)
}
func
doTestOverWebSockets
(
bindAddress
string
,
f
*
framework
.
Framework
)
{
...
...
@@ -373,14 +354,6 @@ func doTestOverWebSockets(bindAddress string, f *framework.Framework) {
if
err
:=
f
.
WaitForPodReady
(
pod
.
Name
);
err
!=
nil
{
framework
.
Failf
(
"Pod did not start running: %v"
,
err
)
}
defer
func
()
{
logs
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
if
err
!=
nil
{
framework
.
Logf
(
"Error getting pod log: %v"
,
err
)
}
else
{
framework
.
Logf
(
"Pod log:
\n
%s"
,
logs
)
}
}()
req
:=
f
.
ClientSet
.
CoreV1
()
.
RESTClient
()
.
Get
()
.
Namespace
(
f
.
Namespace
.
Name
)
.
...
...
@@ -449,12 +422,12 @@ func doTestOverWebSockets(bindAddress string, f *framework.Framework) {
},
time
.
Minute
,
10
*
time
.
Second
)
.
Should
(
BeNil
())
By
(
"Verifying logs"
)
logOutput
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
if
err
!=
nil
{
framework
.
Failf
(
"Error retrieving pod logs: %v"
,
err
)
}
verifyLogMessage
(
logOutput
,
"^Accepted client connection$"
)
verifyLogMessage
(
logOutput
,
"^Received expected client data$"
)
Eventually
(
func
()
(
string
,
error
)
{
return
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
pod
.
Name
,
"portforwardtester"
)
},
postStartWaitTimeout
,
podCheckInterval
)
.
Should
(
SatisfyAll
(
ContainSubstring
(
"Accepted client connection"
),
ContainSubstring
(
"Received expected client data"
),
)
)
}
var
_
=
SIGDescribe
(
"Kubectl Port forwarding"
,
func
()
{
...
...
@@ -504,17 +477,6 @@ var _ = SIGDescribe("Kubectl Port forwarding", func() {
})
})
func
verifyLogMessage
(
log
,
expected
string
)
{
re
:=
regexp
.
MustCompile
(
expected
)
lines
:=
strings
.
Split
(
log
,
"
\n
"
)
for
i
:=
range
lines
{
if
re
.
MatchString
(
lines
[
i
])
{
return
}
}
framework
.
Failf
(
"Missing %q from log: %s"
,
expected
,
log
)
}
func
wsRead
(
conn
*
websocket
.
Conn
)
(
byte
,
[]
byte
,
error
)
{
for
{
var
data
[]
byte
...
...
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