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
c27feb36
Commit
c27feb36
authored
Jan 28, 2016
by
Fabio Yeon
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20260 from lavalamp/flake-kubectl-proxy
Determinisitically get kubectl proxy port
parents
54816aab
22b43d8f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
12 deletions
+25
-12
test-cmd.sh
hack/test-cmd.sh
+25
-12
No files found.
hack/test-cmd.sh
View file @
c27feb36
...
@@ -28,9 +28,12 @@ source "${KUBE_ROOT}/hack/lib/test.sh"
...
@@ -28,9 +28,12 @@ source "${KUBE_ROOT}/hack/lib/test.sh"
# Stops the running kubectl proxy, if there is one.
# Stops the running kubectl proxy, if there is one.
function
stop-proxy
()
function
stop-proxy
()
{
{
[[
-n
"
${
PROXY_PORT
-
}
"
]]
&&
kube::log::status
"Stopping proxy on port
${
PROXY_PORT
}
"
[[
-n
"
${
PROXY_PID
-
}
"
]]
&&
kill
"
${
PROXY_PID
}
"
1>&2 2>/dev/null
[[
-n
"
${
PROXY_PID
-
}
"
]]
&&
kill
"
${
PROXY_PID
}
"
1>&2 2>/dev/null
[[
-n
"
${
PROXY_PORT_FILE
-
}
"
]]
&&
rm
-f
${
PROXY_PORT_FILE
}
PROXY_PID
=
PROXY_PID
=
PROXY_PORT
=
PROXY_PORT
=
PROXY_PORT_FILE
=
}
}
# Starts "kubect proxy" to test the client proxy. $1: api_prefix
# Starts "kubect proxy" to test the client proxy. $1: api_prefix
...
@@ -38,22 +41,32 @@ function start-proxy()
...
@@ -38,22 +41,32 @@ function start-proxy()
{
{
stop-proxy
stop-proxy
kube::log::status
"Starting kubectl proxy"
PROXY_PORT_FILE
=
$(
mktemp
proxy-port.out.XXXXX
)
kube::log::status
"Starting kubectl proxy on random port; output file in
${
PROXY_PORT_FILE
}
; args:
${
1
-
}
"
for
retry
in
$(
seq
1 3
)
;
do
PROXY_PORT
=
$(
kube::util::get_random_port
)
if
[
$#
-eq
0
]
;
then
kube::log::status
"On try
${
retry
}
, use proxy port
${
PROXY_PORT
}
if it's free"
kubectl proxy
--port
=
0
--www
=
.
1>
${
PROXY_PORT_FILE
}
2>&1 &
if
kube::util::test_host_port_free
"127.0.0.1"
"
${
PROXY_PORT
}
"
;
then
else
if
[
$#
-eq
0
]
;
then
kubectl proxy
--port
=
0
--www
=
.
--api-prefix
=
"
$1
"
1>
${
PROXY_PORT_FILE
}
2>&1 &
kubectl proxy
-p
${
PROXY_PORT
}
--www
=
.
1>&2 &
break
fi
else
PROXY_PID
=
$!
kubectl proxy
-p
${
PROXY_PORT
}
--www
=
.
--api-prefix
=
"
$1
"
1>&2 &
break
PROXY_PORT
=
fi
local
attempts
=
0
while
[[
-z
${
PROXY_PORT
}
]]
;
do
if
((
${
attempts
}
>
9
))
;
then
kill
"
${
PROXY_PID
}
"
kube::log::error_exit
"Couldn't start proxy. Failed to read port after
${
attempts
}
tries. Got:
$(
cat
${
PROXY_PORT_FILE
})
"
fi
fi
sleep
1
;
sleep
.5
kube::log::status
"Attempt
${
attempts
}
to read
${
PROXY_PORT_FILE
}
..."
PROXY_PORT
=
$(
sed
's/.*Starting to serve on 127.0.0.1:\([0-9]*\)$/\1/'
<
${
PROXY_PORT_FILE
})
attempts
=
$((
attempts+1
))
done
done
PROXY_PID
=
$!
kube::log::status
"kubectl proxy running on port
${
PROXY_PORT
}
"
# We try checking kubectl proxy 30 times with 1s delays to avoid occasional
# We try checking kubectl proxy 30 times with 1s delays to avoid occasional
# failures.
# failures.
if
[
$#
-eq
0
]
;
then
if
[
$#
-eq
0
]
;
then
...
...
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