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
6694a455
Commit
6694a455
authored
Dec 11, 2014
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add doc for {namespace} path param, fixup and verify proxy paths
parent
14dd466e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
5 deletions
+16
-5
apiserver.go
pkg/apiserver/apiserver.go
+10
-3
proxy.go
pkg/apiserver/proxy.go
+3
-2
proxy_test.go
pkg/apiserver/proxy_test.go
+3
-0
No files found.
pkg/apiserver/apiserver.go
View file @
6694a455
...
@@ -100,7 +100,7 @@ func indirectArbitraryPointer(ptrToObject interface{}) interface{} {
...
@@ -100,7 +100,7 @@ func indirectArbitraryPointer(ptrToObject interface{}) interface{} {
return
reflect
.
Indirect
(
reflect
.
ValueOf
(
ptrToObject
))
.
Interface
()
return
reflect
.
Indirect
(
reflect
.
ValueOf
(
ptrToObject
))
.
Interface
()
}
}
func
registerResourceHandlers
(
ws
*
restful
.
WebService
,
version
string
,
path
string
,
storage
RESTStorage
,
kinds
map
[
string
]
reflect
.
Type
,
h
restful
.
RouteFunction
)
{
func
registerResourceHandlers
(
ws
*
restful
.
WebService
,
version
string
,
path
string
,
storage
RESTStorage
,
kinds
map
[
string
]
reflect
.
Type
,
h
restful
.
RouteFunction
,
namespaceScope
bool
)
{
glog
.
V
(
3
)
.
Infof
(
"Installing /%s/%s
\n
"
,
version
,
path
)
glog
.
V
(
3
)
.
Infof
(
"Installing /%s/%s
\n
"
,
version
,
path
)
object
:=
storage
.
New
()
object
:=
storage
.
New
()
_
,
kind
,
err
:=
api
.
Scheme
.
ObjectVersionAndKind
(
object
)
_
,
kind
,
err
:=
api
.
Scheme
.
ObjectVersionAndKind
(
object
)
...
@@ -118,6 +118,11 @@ func registerResourceHandlers(ws *restful.WebService, version string, path strin
...
@@ -118,6 +118,11 @@ func registerResourceHandlers(ws *restful.WebService, version string, path strin
// See github.com/emicklei/go-restful/blob/master/jsr311.go for routing logic
// See github.com/emicklei/go-restful/blob/master/jsr311.go for routing logic
// and status-code behavior
// and status-code behavior
if
namespaceScope
{
path
=
"ns/{namespace}/"
+
path
ws
.
Param
(
ws
.
PathParameter
(
"namespace"
,
"object name and auth scope, such as for teams and projects"
)
.
DataType
(
"string"
))
}
glog
.
V
(
3
)
.
Infof
(
"Installing version=/%s, kind=/%s, path=/%s
\n
"
,
version
,
kind
,
path
)
ws
.
Route
(
ws
.
POST
(
path
)
.
To
(
h
)
.
ws
.
Route
(
ws
.
POST
(
path
)
.
To
(
h
)
.
Doc
(
"create a "
+
kind
)
.
Doc
(
"create a "
+
kind
)
.
...
@@ -221,8 +226,10 @@ func (g *APIGroupVersion) InstallREST(container *restful.Container, root string,
...
@@ -221,8 +226,10 @@ func (g *APIGroupVersion) InstallREST(container *restful.Container, root string,
}
}
for
path
,
storage
:=
range
g
.
handler
.
storage
{
for
path
,
storage
:=
range
g
.
handler
.
storage
{
registerResourceHandlers
(
ws
,
version
,
path
,
storage
,
kinds
,
h
)
// register legacy patterns where namespace is optional in path
registerResourceHandlers
(
ws
,
version
,
"ns/{namespace}/"
+
path
,
storage
,
kinds
,
h
)
registerResourceHandlers
(
ws
,
version
,
path
,
storage
,
kinds
,
h
,
false
)
// register pattern where namespace is required in path
registerResourceHandlers
(
ws
,
version
,
path
,
storage
,
kinds
,
h
,
true
)
}
}
// TODO: port the rest of these. Sadly, if we don't, we'll have inconsistent
// TODO: port the rest of these. Sadly, if we don't, we'll have inconsistent
...
...
pkg/apiserver/proxy.go
View file @
6694a455
...
@@ -90,8 +90,9 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
...
@@ -90,8 +90,9 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
}
id
:=
parts
[
1
]
id
:=
parts
[
1
]
rest
:=
""
rest
:=
""
if
len
(
parts
)
==
3
{
if
len
(
parts
)
>
2
{
rest
=
parts
[
2
]
proxyParts
:=
parts
[
2
:
]
rest
=
strings
.
Join
(
proxyParts
,
"/"
)
}
}
storage
,
ok
:=
r
.
storage
[
kind
]
storage
,
ok
:=
r
.
storage
[
kind
]
if
!
ok
{
if
!
ok
{
...
...
pkg/apiserver/proxy_test.go
View file @
6694a455
...
@@ -154,6 +154,9 @@ func TestProxy(t *testing.T) {
...
@@ -154,6 +154,9 @@ func TestProxy(t *testing.T) {
if
e
,
a
:=
item
.
reqBody
,
string
(
gotBody
);
e
!=
a
{
if
e
,
a
:=
item
.
reqBody
,
string
(
gotBody
);
e
!=
a
{
t
.
Errorf
(
"%v - expected %v, got %v"
,
item
.
method
,
e
,
a
)
t
.
Errorf
(
"%v - expected %v, got %v"
,
item
.
method
,
e
,
a
)
}
}
if
e
,
a
:=
item
.
path
,
req
.
URL
.
Path
;
e
!=
a
{
t
.
Errorf
(
"%v - expected %v, got %v"
,
item
.
method
,
e
,
a
)
}
fmt
.
Fprint
(
w
,
item
.
respBody
)
fmt
.
Fprint
(
w
,
item
.
respBody
)
}))
}))
defer
proxyServer
.
Close
()
defer
proxyServer
.
Close
()
...
...
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