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
b07e29b0
Commit
b07e29b0
authored
Oct 12, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14789 from JanetKuo/fix-e2e-test-flake-kubectl-proxy
Use random ports when doing kubectl proxy in testing
parents
149ca1ec
5d08dcf8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
4 deletions
+39
-4
util.sh
hack/lib/util.sh
+26
-0
test-cmd.sh
hack/test-cmd.sh
+13
-4
No files found.
hack/lib/util.sh
View file @
b07e29b0
...
@@ -48,6 +48,32 @@ kube::util::wait_for_url() {
...
@@ -48,6 +48,32 @@ kube::util::wait_for_url() {
return
1
return
1
}
}
# returns a random port
kube::util::get_random_port
()
{
awk
-v
min
=
1
-v
max
=
65535
'BEGIN{srand(); print int(min+rand()*(max-min+1))}'
}
# use netcat to check if the host($1):port($2) is free (return 0 means free, 1 means used)
kube::util::test_host_port_free
()
{
local
host
=
$1
local
port
=
$2
local
success
=
0
local
fail
=
1
which nc
>
/dev/null
||
{
kube::log::usage
"netcat isn't installed, can't verify if
${
host
}
:
${
port
}
is free, skipping the check..."
return
${
success
}
}
if
[
!
$(
nc
-vz
"
${
host
}
${
port
}
"
)
]
;
then
kube::log::status
"
${
host
}
:
${
port
}
is free, proceeding..."
return
${
success
}
else
kube::log::status
"
${
host
}
:
${
port
}
is already used"
return
${
fail
}
fi
}
# Example: kube::util::trap_add 'echo "in trap DEBUG"' DEBUG
# Example: kube::util::trap_add 'echo "in trap DEBUG"' DEBUG
# See: http://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
# See: http://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
kube::util::trap_add
()
{
kube::util::trap_add
()
{
...
...
hack/test-cmd.sh
View file @
b07e29b0
...
@@ -30,6 +30,7 @@ function stop-proxy()
...
@@ -30,6 +30,7 @@ function stop-proxy()
{
{
[[
-n
"
${
PROXY_PID
-
}
"
]]
&&
kill
"
${
PROXY_PID
}
"
1>&2 2>/dev/null
[[
-n
"
${
PROXY_PID
-
}
"
]]
&&
kill
"
${
PROXY_PID
}
"
1>&2 2>/dev/null
PROXY_PID
=
PROXY_PID
=
PROXY_PORT
=
}
}
# Starts "kubect proxy" to test the client proxy. You may pass options, e.g.
# Starts "kubect proxy" to test the client proxy. You may pass options, e.g.
...
@@ -39,9 +40,18 @@ function start-proxy()
...
@@ -39,9 +40,18 @@ function start-proxy()
stop-proxy
stop-proxy
kube::log::status
"Starting kubectl proxy"
kube::log::status
"Starting kubectl proxy"
# the --www and --www-prefix are just to make something definitely show up for
# wait_for_url to see.
for
retry
in
$(
seq
1 3
)
;
do
kubectl proxy
-p
${
PROXY_PORT
}
--www
=
.
--www-prefix
=
/healthz
"
$@
"
1>&2 &
PROXY_PORT
=
$(
kube::util::get_random_port
)
kube::log::status
"On try
${
retry
}
, use proxy port
${
PROXY_PORT
}
if it's free"
if
kube::util::test_host_port_free
"127.0.0.1"
"
${
PROXY_PORT
}
"
;
then
# the --www and --www-prefix are just to make something definitely show up for
# wait_for_url to see.
kubectl proxy
-p
${
PROXY_PORT
}
--www
=
.
--www-prefix
=
/healthz
"
$@
"
1>&2 &
break
fi
sleep
1
;
done
PROXY_PID
=
$!
PROXY_PID
=
$!
kube::util::wait_for_url
"http://127.0.0.1:
${
PROXY_PORT
}
/healthz"
"kubectl proxy
$@
"
kube::util::wait_for_url
"http://127.0.0.1:
${
PROXY_PORT
}
/healthz"
"kubectl proxy
$@
"
}
}
...
@@ -86,7 +96,6 @@ API_HOST=${API_HOST:-127.0.0.1}
...
@@ -86,7 +96,6 @@ API_HOST=${API_HOST:-127.0.0.1}
KUBELET_PORT
=
${
KUBELET_PORT
:-
10250
}
KUBELET_PORT
=
${
KUBELET_PORT
:-
10250
}
KUBELET_HEALTHZ_PORT
=
${
KUBELET_HEALTHZ_PORT
:-
10248
}
KUBELET_HEALTHZ_PORT
=
${
KUBELET_HEALTHZ_PORT
:-
10248
}
CTLRMGR_PORT
=
${
CTLRMGR_PORT
:-
10252
}
CTLRMGR_PORT
=
${
CTLRMGR_PORT
:-
10252
}
PROXY_PORT
=
${
PROXY_PORT
:-
8001
}
PROXY_HOST
=
127.0.0.1
# kubectl only serves on localhost.
PROXY_HOST
=
127.0.0.1
# kubectl only serves on localhost.
# ensure ~/.kube/config isn't loaded by tests
# ensure ~/.kube/config isn't loaded by tests
...
...
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