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
ef25520b
Commit
ef25520b
authored
Nov 24, 2014
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make selfLink namespace aware
parent
b811eb83
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
7 deletions
+38
-7
apiserver_test.go
pkg/apiserver/apiserver_test.go
+15
-6
resthandler.go
pkg/apiserver/resthandler.go
+21
-1
interfaces.go
pkg/runtime/interfaces.go
+2
-0
No files found.
pkg/apiserver/apiserver_test.go
View file @
ef25520b
...
@@ -316,7 +316,8 @@ func TestSimpleList(t *testing.T) {
...
@@ -316,7 +316,8 @@ func TestSimpleList(t *testing.T) {
storage
[
"simple"
]
=
&
simpleStorage
storage
[
"simple"
]
=
&
simpleStorage
selfLinker
:=
&
setTestSelfLinker
{
selfLinker
:=
&
setTestSelfLinker
{
t
:
t
,
t
:
t
,
expectedSet
:
"/prefix/version/simple"
,
namespace
:
"other"
,
expectedSet
:
"/prefix/version/simple?namespace=other"
,
}
}
handler
:=
Handle
(
storage
,
codec
,
"/prefix"
,
testVersion
,
selfLinker
)
handler
:=
Handle
(
storage
,
codec
,
"/prefix"
,
testVersion
,
selfLinker
)
server
:=
httptest
.
NewServer
(
handler
)
server
:=
httptest
.
NewServer
(
handler
)
...
@@ -360,8 +361,9 @@ func TestNonEmptyList(t *testing.T) {
...
@@ -360,8 +361,9 @@ func TestNonEmptyList(t *testing.T) {
simpleStorage
:=
SimpleRESTStorage
{
simpleStorage
:=
SimpleRESTStorage
{
list
:
[]
Simple
{
list
:
[]
Simple
{
{
{
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Simple"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Simple"
},
Other
:
"foo"
,
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
"other"
},
Other
:
"foo"
,
},
},
},
},
}
}
...
@@ -394,6 +396,10 @@ func TestNonEmptyList(t *testing.T) {
...
@@ -394,6 +396,10 @@ func TestNonEmptyList(t *testing.T) {
if
listOut
.
Items
[
0
]
.
Other
!=
simpleStorage
.
list
[
0
]
.
Other
{
if
listOut
.
Items
[
0
]
.
Other
!=
simpleStorage
.
list
[
0
]
.
Other
{
t
.
Errorf
(
"Unexpected data: %#v, %s"
,
listOut
.
Items
[
0
],
string
(
body
))
t
.
Errorf
(
"Unexpected data: %#v, %s"
,
listOut
.
Items
[
0
],
string
(
body
))
}
}
expectedSelfLink
:=
"/prefix/version/simple?namespace=other"
if
listOut
.
Items
[
0
]
.
ObjectMeta
.
SelfLink
!=
expectedSelfLink
{
t
.
Errorf
(
"Unexpected data: %#v, %s"
,
listOut
.
Items
[
0
]
.
ObjectMeta
.
SelfLink
,
expectedSelfLink
)
}
}
}
func
TestGet
(
t
*
testing
.
T
)
{
func
TestGet
(
t
*
testing
.
T
)
{
...
@@ -651,11 +657,13 @@ type setTestSelfLinker struct {
...
@@ -651,11 +657,13 @@ type setTestSelfLinker struct {
t
*
testing
.
T
t
*
testing
.
T
expectedSet
string
expectedSet
string
name
string
name
string
namespace
string
called
bool
called
bool
}
}
func
(
s
*
setTestSelfLinker
)
Name
(
runtime
.
Object
)
(
string
,
error
)
{
return
s
.
name
,
nil
}
func
(
s
*
setTestSelfLinker
)
Namespace
(
runtime
.
Object
)
(
string
,
error
)
{
return
s
.
namespace
,
nil
}
func
(
*
setTestSelfLinker
)
SelfLink
(
runtime
.
Object
)
(
string
,
error
)
{
return
""
,
nil
}
func
(
s
*
setTestSelfLinker
)
Name
(
runtime
.
Object
)
(
string
,
error
)
{
return
s
.
name
,
nil
}
func
(
*
setTestSelfLinker
)
SelfLink
(
runtime
.
Object
)
(
string
,
error
)
{
return
""
,
nil
}
func
(
s
*
setTestSelfLinker
)
SetSelfLink
(
obj
runtime
.
Object
,
selfLink
string
)
error
{
func
(
s
*
setTestSelfLinker
)
SetSelfLink
(
obj
runtime
.
Object
,
selfLink
string
)
error
{
if
e
,
a
:=
s
.
expectedSet
,
selfLink
;
e
!=
a
{
if
e
,
a
:=
s
.
expectedSet
,
selfLink
;
e
!=
a
{
s
.
t
.
Errorf
(
"expected '%v', got '%v'"
,
e
,
a
)
s
.
t
.
Errorf
(
"expected '%v', got '%v'"
,
e
,
a
)
...
@@ -674,7 +682,8 @@ func TestSyncCreate(t *testing.T) {
...
@@ -674,7 +682,8 @@ func TestSyncCreate(t *testing.T) {
selfLinker
:=
&
setTestSelfLinker
{
selfLinker
:=
&
setTestSelfLinker
{
t
:
t
,
t
:
t
,
name
:
"bar"
,
name
:
"bar"
,
expectedSet
:
"/prefix/version/foo/bar"
,
namespace
:
"other"
,
expectedSet
:
"/prefix/version/foo/bar?namespace=other"
,
}
}
handler
:=
Handle
(
map
[
string
]
RESTStorage
{
handler
:=
Handle
(
map
[
string
]
RESTStorage
{
"foo"
:
&
storage
,
"foo"
:
&
storage
,
...
...
pkg/apiserver/resthandler.go
View file @
ef25520b
...
@@ -62,7 +62,17 @@ func (h *RESTHandler) setSelfLink(obj runtime.Object, req *http.Request) error {
...
@@ -62,7 +62,17 @@ func (h *RESTHandler) setSelfLink(obj runtime.Object, req *http.Request) error {
newURL
.
Path
=
path
.
Join
(
h
.
canonicalPrefix
,
req
.
URL
.
Path
)
newURL
.
Path
=
path
.
Join
(
h
.
canonicalPrefix
,
req
.
URL
.
Path
)
newURL
.
RawQuery
=
""
newURL
.
RawQuery
=
""
newURL
.
Fragment
=
""
newURL
.
Fragment
=
""
err
:=
h
.
selfLinker
.
SetSelfLink
(
obj
,
newURL
.
String
())
namespace
,
err
:=
h
.
selfLinker
.
Namespace
(
obj
)
if
err
!=
nil
{
return
err
}
// TODO Remove this when namespace is in path
if
len
(
namespace
)
>
0
{
query
:=
newURL
.
Query
()
query
.
Set
(
"namespace"
,
namespace
)
newURL
.
RawQuery
=
query
.
Encode
()
}
err
=
h
.
selfLinker
.
SetSelfLink
(
obj
,
newURL
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -89,10 +99,20 @@ func (h *RESTHandler) setSelfLinkAddName(obj runtime.Object, req *http.Request)
...
@@ -89,10 +99,20 @@ func (h *RESTHandler) setSelfLinkAddName(obj runtime.Object, req *http.Request)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
namespace
,
err
:=
h
.
selfLinker
.
Namespace
(
obj
)
if
err
!=
nil
{
return
err
}
newURL
:=
*
req
.
URL
newURL
:=
*
req
.
URL
newURL
.
Path
=
path
.
Join
(
h
.
canonicalPrefix
,
req
.
URL
.
Path
,
name
)
newURL
.
Path
=
path
.
Join
(
h
.
canonicalPrefix
,
req
.
URL
.
Path
,
name
)
newURL
.
RawQuery
=
""
newURL
.
RawQuery
=
""
newURL
.
Fragment
=
""
newURL
.
Fragment
=
""
// TODO Remove this when namespace is in path
if
len
(
namespace
)
>
0
{
query
:=
newURL
.
Query
()
query
.
Set
(
"namespace"
,
namespace
)
newURL
.
RawQuery
=
query
.
Encode
()
}
return
h
.
selfLinker
.
SetSelfLink
(
obj
,
newURL
.
String
())
return
h
.
selfLinker
.
SetSelfLink
(
obj
,
newURL
.
String
())
}
}
...
...
pkg/runtime/interfaces.go
View file @
ef25520b
...
@@ -59,6 +59,8 @@ type SelfLinker interface {
...
@@ -59,6 +59,8 @@ type SelfLinker interface {
// Knowing Name is sometimes necessary to use a SelfLinker.
// Knowing Name is sometimes necessary to use a SelfLinker.
Name
(
obj
Object
)
(
string
,
error
)
Name
(
obj
Object
)
(
string
,
error
)
// Knowing Namespace is sometimes necessary to use a SelfLinker
Namespace
(
obj
Object
)
(
string
,
error
)
}
}
// All api types must support the Object interface. It's deliberately tiny so that this is not an onerous
// All api types must support the Object interface. It's deliberately tiny so that this is not an onerous
...
...
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