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
5eb5b4a1
Commit
5eb5b4a1
authored
Jun 22, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test kubectl proxy in test-cmd.sh
parent
689a3ee7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
3 deletions
+75
-3
test-cmd.sh
hack/test-cmd.sh
+75
-3
No files found.
hack/test-cmd.sh
View file @
5eb5b4a1
...
@@ -25,11 +25,33 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
...
@@ -25,11 +25,33 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
source
"
${
KUBE_ROOT
}
/hack/lib/test.sh"
source
"
${
KUBE_ROOT
}
/hack/lib/test.sh"
# Stops the running kubectl proxy, if there is one.
function
stop-proxy
()
{
[[
-n
"
${
PROXY_PID
-
}
"
]]
&&
kill
"
${
PROXY_PID
}
"
1>&2 2>/dev/null
PROXY_PID
=
}
# Starts "kubect proxy" to test the client proxy. You may pass options, e.g.
# --api-prefix.
function
start-proxy
()
{
stop-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.
kubectl proxy
-p
${
PROXY_PORT
}
--www
=
.
--www-prefix
=
/healthz
"
$@
"
1>&2 &
PROXY_PID
=
$!
kube::util::wait_for_url
"http://127.0.0.1:
${
PROXY_PORT
}
/healthz"
"kubectl proxy
$@
"
}
function
cleanup
()
function
cleanup
()
{
{
[[
-n
${
APISERVER_PID
-
}
]]
&&
kill
${
APISERVER_PID
}
1>&2 2>/dev/null
[[
-n
"
${
APISERVER_PID
-
}
"
]]
&&
kill
"
${
APISERVER_PID
}
"
1>&2 2>/dev/null
[[
-n
${
CTLRMGR_PID
-
}
]]
&&
kill
${
CTLRMGR_PID
}
1>&2 2>/dev/null
[[
-n
"
${
CTLRMGR_PID
-
}
"
]]
&&
kill
"
${
CTLRMGR_PID
}
"
1>&2 2>/dev/null
[[
-n
${
KUBELET_PID
-
}
]]
&&
kill
${
KUBELET_PID
}
1>&2 2>/dev/null
[[
-n
"
${
KUBELET_PID
-
}
"
]]
&&
kill
"
${
KUBELET_PID
}
"
1>&2 2>/dev/null
stop-proxy
kube::etcd::cleanup
kube::etcd::cleanup
rm
-rf
"
${
KUBE_TEMP
}
"
rm
-rf
"
${
KUBE_TEMP
}
"
...
@@ -37,6 +59,22 @@ function cleanup()
...
@@ -37,6 +59,22 @@ function cleanup()
kube::log::status
"Clean up complete"
kube::log::status
"Clean up complete"
}
}
# Executes curl against the proxy. $1 is the path to use, $2 is the desired
# return code. Prints a helpful message on failure.
function
check-curl-proxy-code
()
{
local
status
local
-r
address
=
$1
local
-r
desired
=
$2
local
-r
full_address
=
"
${
PROXY_HOST
}
:
${
PROXY_PORT
}${
address
}
"
status
=
$(
curl
-w
"%{http_code}"
--silent
--output
/dev/null
"
${
full_address
}
"
)
if
[
"
${
status
}
"
==
"
${
desired
}
"
]
;
then
return
0
fi
echo
"For address
${
full_address
}
, got
${
status
}
but wanted
${
desired
}
"
return
1
}
trap
cleanup EXIT SIGINT
trap
cleanup EXIT SIGINT
kube::util::ensure-temp-dir
kube::util::ensure-temp-dir
...
@@ -49,6 +87,8 @@ API_HOST=${API_HOST:-127.0.0.1}
...
@@ -49,6 +87,8 @@ 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.
# Check kubectl
# Check kubectl
kube::log::status
"Running kubectl with no options"
kube::log::status
"Running kubectl with no options"
...
@@ -146,6 +186,38 @@ for version in "${kube_api_versions[@]}"; do
...
@@ -146,6 +186,38 @@ for version in "${kube_api_versions[@]}"; do
# Passing no arguments to create is an error
# Passing no arguments to create is an error
!
kubectl create
!
kubectl create
#######################
# kubectl local proxy #
#######################
# Make sure the UI can be proxied
start-proxy
--api-prefix
=
/
check-curl-proxy-code /ui 301
check-curl-proxy-code /metrics 200
if
[[
-n
"
${
version
}
"
]]
;
then
check-curl-proxy-code /api/
${
version
}
/namespaces 200
fi
stop-proxy
# Default proxy locks you into the /api path (legacy behavior)
start-proxy
check-curl-proxy-code /ui 404
check-curl-proxy-code /metrics 404
check-curl-proxy-code /api/ui 404
if
[[
-n
"
${
version
}
"
]]
;
then
check-curl-proxy-code /api/
${
version
}
/namespaces 200
fi
stop-proxy
# Custom paths let you see everything.
start-proxy
--api-prefix
=
/custom
check-curl-proxy-code /custom/ui 301
check-curl-proxy-code /custom/metrics 200
if
[[
-n
"
${
version
}
"
]]
;
then
check-curl-proxy-code /custom/api/
${
version
}
/namespaces 200
fi
stop-proxy
###########################
###########################
# POD creation / deletion #
# POD creation / deletion #
###########################
###########################
...
...
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