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
a84fa79a
Commit
a84fa79a
authored
Jun 26, 2015
by
Cesar Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use versioned objects for GET and CONNECT operations
parent
c5bffaaf
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
296 additions
and
5 deletions
+296
-5
v1.json
api/swagger-spec/v1.json
+216
-0
api_installer.go
pkg/apiserver/api_installer.go
+10
-3
apiserver_test.go
pkg/apiserver/apiserver_test.go
+70
-2
No files found.
api/swagger-spec/v1.json
View file @
a84fa79a
This diff is collapsed.
Click to expand it.
pkg/apiserver/api_installer.go
View file @
a84fa79a
...
@@ -205,6 +205,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -205,6 +205,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
versionedStatus
:=
indirectArbitraryPointer
(
versionedStatusPtr
)
versionedStatus
:=
indirectArbitraryPointer
(
versionedStatusPtr
)
var
(
var
(
getOptions
runtime
.
Object
getOptions
runtime
.
Object
versionedGetOptions
runtime
.
Object
getOptionsKind
string
getOptionsKind
string
getSubpath
bool
getSubpath
bool
getSubpathKey
string
getSubpathKey
string
...
@@ -215,11 +216,16 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -215,11 +216,16 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
versionedGetOptions
,
err
=
a
.
group
.
Creater
.
New
(
serverVersion
,
getOptionsKind
)
if
err
!=
nil
{
return
err
}
isGetter
=
true
isGetter
=
true
}
}
var
(
var
(
connectOptions
runtime
.
Object
connectOptions
runtime
.
Object
versionedConnectOptions
runtime
.
Object
connectOptionsKind
string
connectOptionsKind
string
connectSubpath
bool
connectSubpath
bool
connectSubpathKey
string
connectSubpathKey
string
...
@@ -231,6 +237,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -231,6 +237,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
versionedConnectOptions
,
err
=
a
.
group
.
Creater
.
New
(
serverVersion
,
connectOptionsKind
)
}
}
}
}
...
@@ -390,7 +397,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -390,7 +397,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Returns
(
http
.
StatusOK
,
"OK"
,
versionedObject
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
versionedObject
)
.
Writes
(
versionedObject
)
Writes
(
versionedObject
)
if
isGetterWithOptions
{
if
isGetterWithOptions
{
if
err
:=
addObjectParams
(
ws
,
route
,
g
etOptions
);
err
!=
nil
{
if
err
:=
addObjectParams
(
ws
,
route
,
versionedG
etOptions
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
@@ -561,8 +568,8 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -561,8 +568,8 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Produces
(
"*/*"
)
.
Produces
(
"*/*"
)
.
Consumes
(
"*/*"
)
.
Consumes
(
"*/*"
)
.
Writes
(
"string"
)
Writes
(
"string"
)
if
c
onnectOptions
!=
nil
{
if
versionedC
onnectOptions
!=
nil
{
if
err
:=
addObjectParams
(
ws
,
route
,
c
onnectOptions
);
err
!=
nil
{
if
err
:=
addObjectParams
(
ws
,
route
,
versionedC
onnectOptions
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
...
pkg/apiserver/apiserver_test.go
View file @
a84fa79a
...
@@ -255,8 +255,8 @@ func (*SimpleRoot) IsAnAPIObject() {}
...
@@ -255,8 +255,8 @@ func (*SimpleRoot) IsAnAPIObject() {}
type
SimpleGetOptions
struct
{
type
SimpleGetOptions
struct
{
api
.
TypeMeta
`json:",inline"`
api
.
TypeMeta
`json:",inline"`
Param1
string
`json:"param1"`
Param1
string
`json:"param1"
description:"description for param1"
`
Param2
string
`json:"param2"`
Param2
string
`json:"param2"
description:"description for param2"
`
Path
string
`json:"atAPath"`
Path
string
`json:"atAPath"`
}
}
...
@@ -1078,6 +1078,47 @@ func TestGetBinary(t *testing.T) {
...
@@ -1078,6 +1078,47 @@ func TestGetBinary(t *testing.T) {
}
}
}
}
func
validateSimpleGetOptionsParams
(
t
*
testing
.
T
,
route
*
restful
.
Route
)
{
// Validate name and description
expectedParams
:=
map
[
string
]
string
{
"param1"
:
"description for param1"
,
"param2"
:
"description for param2"
,
"atAPath"
:
""
,
}
for
_
,
p
:=
range
route
.
ParameterDocs
{
data
:=
p
.
Data
()
if
desc
,
exists
:=
expectedParams
[
data
.
Name
];
exists
{
if
desc
!=
data
.
Description
{
t
.
Errorf
(
"unexpected description for parameter %s: %s
\n
"
,
data
.
Name
,
data
.
Description
)
}
delete
(
expectedParams
,
data
.
Name
)
}
}
if
len
(
expectedParams
)
>
0
{
t
.
Errorf
(
"did not find all expected parameters: %#v"
,
expectedParams
)
}
}
func
TestGetWithOptionsRouteParams
(
t
*
testing
.
T
)
{
storage
:=
map
[
string
]
rest
.
Storage
{}
simpleStorage
:=
GetWithOptionsRESTStorage
{
SimpleRESTStorage
:
&
SimpleRESTStorage
{},
}
storage
[
"simple"
]
=
&
simpleStorage
handler
:=
handle
(
storage
)
ws
:=
handler
.
(
*
defaultAPIServer
)
.
container
.
RegisteredWebServices
()
if
len
(
ws
)
==
0
{
t
.
Fatal
(
"no web services registered"
)
}
routes
:=
ws
[
0
]
.
Routes
()
for
i
:=
range
routes
{
if
routes
[
i
]
.
Method
==
"GET"
&&
routes
[
i
]
.
Operation
==
"readNamespacedSimple"
{
validateSimpleGetOptionsParams
(
t
,
&
routes
[
i
])
break
}
}
}
func
TestGetWithOptions
(
t
*
testing
.
T
)
{
func
TestGetWithOptions
(
t
*
testing
.
T
)
{
storage
:=
map
[
string
]
rest
.
Storage
{}
storage
:=
map
[
string
]
rest
.
Storage
{}
simpleStorage
:=
GetWithOptionsRESTStorage
{
simpleStorage
:=
GetWithOptionsRESTStorage
{
...
@@ -1292,6 +1333,33 @@ func TestConnect(t *testing.T) {
...
@@ -1292,6 +1333,33 @@ func TestConnect(t *testing.T) {
}
}
}
}
func
TestConnectWithOptionsRouteParams
(
t
*
testing
.
T
)
{
connectStorage
:=
&
ConnecterRESTStorage
{
connectHandler
:
&
SimpleConnectHandler
{},
emptyConnectOptions
:
&
SimpleGetOptions
{},
}
storage
:=
map
[
string
]
rest
.
Storage
{
"simple"
:
&
SimpleRESTStorage
{},
"simple/connect"
:
connectStorage
,
}
handler
:=
handle
(
storage
)
ws
:=
handler
.
(
*
defaultAPIServer
)
.
container
.
RegisteredWebServices
()
if
len
(
ws
)
==
0
{
t
.
Fatal
(
"no web services registered"
)
}
routes
:=
ws
[
0
]
.
Routes
()
for
i
:=
range
routes
{
switch
routes
[
i
]
.
Operation
{
case
"connectGetNamespacedSimpleConnect"
:
case
"connectPostNamespacedSimpleConnect"
:
case
"connectPutNamespacedSimpleConnect"
:
case
"connectDeleteNamespacedSimpleConnect"
:
validateSimpleGetOptionsParams
(
t
,
&
routes
[
i
])
}
}
}
func
TestConnectWithOptions
(
t
*
testing
.
T
)
{
func
TestConnectWithOptions
(
t
*
testing
.
T
)
{
responseText
:=
"Hello World"
responseText
:=
"Hello World"
itemID
:=
"theID"
itemID
:=
"theID"
...
...
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