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
f2765720
Commit
f2765720
authored
Nov 03, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16570 from liggitt/proxy_request_info
Auto commit by PR queue bot
parents
c080c8a1
600b5e63
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
handlers.go
pkg/apiserver/handlers.go
+11
-10
handlers_test.go
pkg/apiserver/handlers_test.go
+3
-0
No files found.
pkg/apiserver/handlers.go
View file @
f2765720
...
@@ -40,11 +40,10 @@ import (
...
@@ -40,11 +40,10 @@ import (
// CRUDdy GET/POST/PUT/DELETE actions on REST objects.
// CRUDdy GET/POST/PUT/DELETE actions on REST objects.
// TODO: find a way to keep this up to date automatically. Maybe dynamically populate list as handlers added to
// TODO: find a way to keep this up to date automatically. Maybe dynamically populate list as handlers added to
// master's Mux.
// master's Mux.
var
specialVerbs
=
map
[
string
]
bool
{
var
specialVerbs
=
sets
.
NewString
(
"proxy"
,
"redirect"
,
"watch"
)
"proxy"
:
true
,
"redirect"
:
true
,
// specialVerbsNoSubresources contains root verbs which do not allow subresources
"watch"
:
true
,
var
specialVerbsNoSubresources
=
sets
.
NewString
(
"proxy"
,
"redirect"
)
}
// Constant for the retry-after interval on rate limiting.
// Constant for the retry-after interval on rate limiting.
// TODO: maybe make this dynamic? or user-adjustable?
// TODO: maybe make this dynamic? or user-adjustable?
...
@@ -436,11 +435,13 @@ type RequestInfoResolver struct {
...
@@ -436,11 +435,13 @@ type RequestInfoResolver struct {
// /api/{version}/{resource}
// /api/{version}/{resource}
// /api/{version}/{resource}/{resourceName}
// /api/{version}/{resource}/{resourceName}
//
//
// Special verbs:
// Special verbs
without subresources
:
// /api/{version}/proxy/{resource}/{resourceName}
// /api/{version}/proxy/{resource}/{resourceName}
// /api/{version}/proxy/namespaces/{namespace}/{resource}/{resourceName}
// /api/{version}/proxy/namespaces/{namespace}/{resource}/{resourceName}
// /api/{version}/redirect/namespaces/{namespace}/{resource}/{resourceName}
// /api/{version}/redirect/namespaces/{namespace}/{resource}/{resourceName}
// /api/{version}/redirect/{resource}/{resourceName}
// /api/{version}/redirect/{resource}/{resourceName}
//
// Special verbs with subresources:
// /api/{version}/watch/{resource}
// /api/{version}/watch/{resource}
// /api/{version}/watch/namespaces/{namespace}/{resource}
// /api/{version}/watch/namespaces/{namespace}/{resource}
//
//
...
@@ -489,7 +490,7 @@ func (r *RequestInfoResolver) GetRequestInfo(req *http.Request) (RequestInfo, er
...
@@ -489,7 +490,7 @@ func (r *RequestInfoResolver) GetRequestInfo(req *http.Request) (RequestInfo, er
currentParts
=
currentParts
[
1
:
]
currentParts
=
currentParts
[
1
:
]
// handle input of form /{specialVerb}/*
// handle input of form /{specialVerb}/*
if
_
,
ok
:=
specialVerbs
[
currentParts
[
0
]];
ok
{
if
specialVerbs
.
Has
(
currentParts
[
0
])
{
if
len
(
currentParts
)
<
2
{
if
len
(
currentParts
)
<
2
{
return
requestInfo
,
fmt
.
Errorf
(
"unable to determine kind and namespace from url, %v"
,
req
.
URL
)
return
requestInfo
,
fmt
.
Errorf
(
"unable to determine kind and namespace from url, %v"
,
req
.
URL
)
}
}
...
@@ -534,13 +535,13 @@ func (r *RequestInfoResolver) GetRequestInfo(req *http.Request) (RequestInfo, er
...
@@ -534,13 +535,13 @@ func (r *RequestInfoResolver) GetRequestInfo(req *http.Request) (RequestInfo, er
// parts look like: resource/resourceName/subresource/other/stuff/we/don't/interpret
// parts look like: resource/resourceName/subresource/other/stuff/we/don't/interpret
switch
{
switch
{
case
len
(
requestInfo
.
Parts
)
>=
3
:
case
len
(
requestInfo
.
Parts
)
>=
3
&&
!
specialVerbsNoSubresources
.
Has
(
requestInfo
.
Verb
)
:
requestInfo
.
Subresource
=
requestInfo
.
Parts
[
2
]
requestInfo
.
Subresource
=
requestInfo
.
Parts
[
2
]
fallthrough
fallthrough
case
len
(
requestInfo
.
Parts
)
=
=
2
:
case
len
(
requestInfo
.
Parts
)
>
=
2
:
requestInfo
.
Name
=
requestInfo
.
Parts
[
1
]
requestInfo
.
Name
=
requestInfo
.
Parts
[
1
]
fallthrough
fallthrough
case
len
(
requestInfo
.
Parts
)
=
=
1
:
case
len
(
requestInfo
.
Parts
)
>
=
1
:
requestInfo
.
Resource
=
requestInfo
.
Parts
[
0
]
requestInfo
.
Resource
=
requestInfo
.
Parts
[
0
]
}
}
...
...
pkg/apiserver/handlers_test.go
View file @
f2765720
...
@@ -228,12 +228,15 @@ func TestGetAPIRequestInfo(t *testing.T) {
...
@@ -228,12 +228,15 @@ func TestGetAPIRequestInfo(t *testing.T) {
// special verbs
// special verbs
{
"GET"
,
"/api/v1/proxy/namespaces/other/pods/foo"
,
"proxy"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
""
,
"foo"
,
[]
string
{
"pods"
,
"foo"
}},
{
"GET"
,
"/api/v1/proxy/namespaces/other/pods/foo"
,
"proxy"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
""
,
"foo"
,
[]
string
{
"pods"
,
"foo"
}},
{
"GET"
,
"/api/v1/proxy/namespaces/other/pods/foo/subpath/not/a/subresource"
,
"proxy"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
""
,
"foo"
,
[]
string
{
"pods"
,
"foo"
,
"subpath"
,
"not"
,
"a"
,
"subresource"
}},
{
"GET"
,
"/api/v1/redirect/namespaces/other/pods/foo"
,
"redirect"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
""
,
"foo"
,
[]
string
{
"pods"
,
"foo"
}},
{
"GET"
,
"/api/v1/redirect/namespaces/other/pods/foo"
,
"redirect"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
""
,
"foo"
,
[]
string
{
"pods"
,
"foo"
}},
{
"GET"
,
"/api/v1/redirect/namespaces/other/pods/foo/subpath/not/a/subresource"
,
"redirect"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
""
,
"foo"
,
[]
string
{
"pods"
,
"foo"
,
"subpath"
,
"not"
,
"a"
,
"subresource"
}},
{
"GET"
,
"/api/v1/watch/pods"
,
"watch"
,
"api"
,
""
,
"v1"
,
api
.
NamespaceAll
,
"pods"
,
""
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
"/api/v1/watch/pods"
,
"watch"
,
"api"
,
""
,
"v1"
,
api
.
NamespaceAll
,
"pods"
,
""
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
"/api/v1/watch/namespaces/other/pods"
,
"watch"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
""
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
"/api/v1/watch/namespaces/other/pods"
,
"watch"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
""
,
""
,
[]
string
{
"pods"
}},
// subresource identification
// subresource identification
{
"GET"
,
"/api/v1/namespaces/other/pods/foo/status"
,
"get"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
"status"
,
"foo"
,
[]
string
{
"pods"
,
"foo"
,
"status"
}},
{
"GET"
,
"/api/v1/namespaces/other/pods/foo/status"
,
"get"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
"status"
,
"foo"
,
[]
string
{
"pods"
,
"foo"
,
"status"
}},
{
"GET"
,
"/api/v1/namespaces/other/pods/foo/proxy/subpath"
,
"get"
,
"api"
,
""
,
"v1"
,
"other"
,
"pods"
,
"proxy"
,
"foo"
,
[]
string
{
"pods"
,
"foo"
,
"proxy"
,
"subpath"
}},
{
"PUT"
,
"/api/v1/namespaces/other/finalize"
,
"update"
,
"api"
,
""
,
"v1"
,
"other"
,
"finalize"
,
""
,
""
,
[]
string
{
"finalize"
}},
{
"PUT"
,
"/api/v1/namespaces/other/finalize"
,
"update"
,
"api"
,
""
,
"v1"
,
"other"
,
"finalize"
,
""
,
""
,
[]
string
{
"finalize"
}},
// verb identification
// verb identification
...
...
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