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
5a971f04
Commit
5a971f04
authored
Mar 04, 2019
by
Haowei Cai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apiserver: make endpoint webservice builder helpers public
parent
979bef15
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
18 deletions
+18
-18
installer.go
staging/src/k8s.io/apiserver/pkg/endpoints/installer.go
+17
-17
installer_test.go
staging/src/k8s.io/apiserver/pkg/endpoints/installer_test.go
+1
-1
No files found.
staging/src/k8s.io/apiserver/pkg/endpoints/installer.go
View file @
5a971f04
...
@@ -611,12 +611,12 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -611,12 +611,12 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Returns
(
http
.
StatusOK
,
"OK"
,
producedObject
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
producedObject
)
.
Writes
(
producedObject
)
Writes
(
producedObject
)
if
isGetterWithOptions
{
if
isGetterWithOptions
{
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedGetOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedGetOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
}
if
isExporter
{
if
isExporter
{
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedExportOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedExportOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
}
...
@@ -638,7 +638,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -638,7 +638,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Produces
(
append
(
storageMeta
.
ProducesMIMETypes
(
action
.
Verb
),
allMediaTypes
...
)
...
)
.
Produces
(
append
(
storageMeta
.
ProducesMIMETypes
(
action
.
Verb
),
allMediaTypes
...
)
...
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
versionedList
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
versionedList
)
.
Writes
(
versionedList
)
Writes
(
versionedList
)
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedListOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedListOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
switch
{
switch
{
...
@@ -674,7 +674,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -674,7 +674,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Returns
(
http
.
StatusCreated
,
"Created"
,
producedObject
)
.
Returns
(
http
.
StatusCreated
,
"Created"
,
producedObject
)
.
Reads
(
defaultVersionedObject
)
.
Reads
(
defaultVersionedObject
)
.
Writes
(
producedObject
)
Writes
(
producedObject
)
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedUpdateOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedUpdateOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
...
@@ -702,7 +702,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -702,7 +702,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Returns
(
http
.
StatusOK
,
"OK"
,
producedObject
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
producedObject
)
.
Reads
(
metav1
.
Patch
{})
.
Reads
(
metav1
.
Patch
{})
.
Writes
(
producedObject
)
Writes
(
producedObject
)
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedPatchOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedPatchOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
...
@@ -715,7 +715,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -715,7 +715,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
handler
=
restfulCreateResource
(
creater
,
reqScope
,
admit
)
handler
=
restfulCreateResource
(
creater
,
reqScope
,
admit
)
}
}
handler
=
metrics
.
InstrumentRouteFunc
(
action
.
Verb
,
group
,
version
,
resource
,
subresource
,
requestScope
,
metrics
.
APIServerComponent
,
handler
)
handler
=
metrics
.
InstrumentRouteFunc
(
action
.
Verb
,
group
,
version
,
resource
,
subresource
,
requestScope
,
metrics
.
APIServerComponent
,
handler
)
article
:=
g
etArticleForNoun
(
kind
,
" "
)
article
:=
G
etArticleForNoun
(
kind
,
" "
)
doc
:=
"create"
+
article
+
kind
doc
:=
"create"
+
article
+
kind
if
isSubresource
{
if
isSubresource
{
doc
=
"create "
+
subresource
+
" of"
+
article
+
kind
doc
=
"create "
+
subresource
+
" of"
+
article
+
kind
...
@@ -732,13 +732,13 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -732,13 +732,13 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Returns
(
http
.
StatusAccepted
,
"Accepted"
,
producedObject
)
.
Returns
(
http
.
StatusAccepted
,
"Accepted"
,
producedObject
)
.
Reads
(
defaultVersionedObject
)
.
Reads
(
defaultVersionedObject
)
.
Writes
(
producedObject
)
Writes
(
producedObject
)
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedCreateOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedCreateOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
routes
=
append
(
routes
,
route
)
routes
=
append
(
routes
,
route
)
case
"DELETE"
:
// Delete a resource.
case
"DELETE"
:
// Delete a resource.
article
:=
g
etArticleForNoun
(
kind
,
" "
)
article
:=
G
etArticleForNoun
(
kind
,
" "
)
doc
:=
"delete"
+
article
+
kind
doc
:=
"delete"
+
article
+
kind
if
isSubresource
{
if
isSubresource
{
doc
=
"delete "
+
subresource
+
" of"
+
article
+
kind
doc
=
"delete "
+
subresource
+
" of"
+
article
+
kind
...
@@ -755,7 +755,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -755,7 +755,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
if
isGracefulDeleter
{
if
isGracefulDeleter
{
route
.
Reads
(
versionedDeleterObject
)
route
.
Reads
(
versionedDeleterObject
)
route
.
ParameterNamed
(
"body"
)
.
Required
(
false
)
route
.
ParameterNamed
(
"body"
)
.
Required
(
false
)
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedDeleteOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedDeleteOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
}
...
@@ -774,7 +774,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -774,7 +774,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Produces
(
append
(
storageMeta
.
ProducesMIMETypes
(
action
.
Verb
),
mediaTypes
...
)
...
)
.
Produces
(
append
(
storageMeta
.
ProducesMIMETypes
(
action
.
Verb
),
mediaTypes
...
)
...
)
.
Writes
(
versionedStatus
)
.
Writes
(
versionedStatus
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
versionedStatus
)
Returns
(
http
.
StatusOK
,
"OK"
,
versionedStatus
)
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedListOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedListOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
...
@@ -794,7 +794,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -794,7 +794,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Produces
(
allMediaTypes
...
)
.
Produces
(
allMediaTypes
...
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
versionedWatchEvent
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
versionedWatchEvent
)
.
Writes
(
versionedWatchEvent
)
Writes
(
versionedWatchEvent
)
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedListOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedListOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
...
@@ -814,7 +814,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -814,7 +814,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Produces
(
allMediaTypes
...
)
.
Produces
(
allMediaTypes
...
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
versionedWatchEvent
)
.
Returns
(
http
.
StatusOK
,
"OK"
,
versionedWatchEvent
)
.
Writes
(
versionedWatchEvent
)
Writes
(
versionedWatchEvent
)
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedListOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedListOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
...
@@ -838,7 +838,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -838,7 +838,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Consumes
(
"*/*"
)
.
Consumes
(
"*/*"
)
.
Writes
(
connectProducedObject
)
Writes
(
connectProducedObject
)
if
versionedConnectOptions
!=
nil
{
if
versionedConnectOptions
!=
nil
{
if
err
:=
a
ddObjectParams
(
ws
,
route
,
versionedConnectOptions
);
err
!=
nil
{
if
err
:=
A
ddObjectParams
(
ws
,
route
,
versionedConnectOptions
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
}
...
@@ -907,13 +907,13 @@ func addParams(route *restful.RouteBuilder, params []*restful.Parameter) {
...
@@ -907,13 +907,13 @@ func addParams(route *restful.RouteBuilder, params []*restful.Parameter) {
}
}
}
}
//
a
ddObjectParams converts a runtime.Object into a set of go-restful Param() definitions on the route.
//
A
ddObjectParams converts a runtime.Object into a set of go-restful Param() definitions on the route.
// The object must be a pointer to a struct; only fields at the top level of the struct that are not
// The object must be a pointer to a struct; only fields at the top level of the struct that are not
// themselves interfaces or structs are used; only fields with a json tag that is non empty (the standard
// themselves interfaces or structs are used; only fields with a json tag that is non empty (the standard
// Go JSON behavior for omitting a field) become query parameters. The name of the query parameter is
// Go JSON behavior for omitting a field) become query parameters. The name of the query parameter is
// the JSON field name. If a description struct tag is set on the field, that description is used on the
// the JSON field name. If a description struct tag is set on the field, that description is used on the
// query parameter. In essence, it converts a standard JSON top level object into a query param schema.
// query parameter. In essence, it converts a standard JSON top level object into a query param schema.
func
a
ddObjectParams
(
ws
*
restful
.
WebService
,
route
*
restful
.
RouteBuilder
,
obj
interface
{})
error
{
func
A
ddObjectParams
(
ws
*
restful
.
WebService
,
route
*
restful
.
RouteBuilder
,
obj
interface
{})
error
{
sv
,
err
:=
conversion
.
EnforcePtr
(
obj
)
sv
,
err
:=
conversion
.
EnforcePtr
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -1015,8 +1015,8 @@ func splitSubresource(path string) (string, string, error) {
...
@@ -1015,8 +1015,8 @@ func splitSubresource(path string) (string, string, error) {
return
resource
,
subresource
,
nil
return
resource
,
subresource
,
nil
}
}
//
g
etArticleForNoun returns the article needed for the given noun.
//
G
etArticleForNoun returns the article needed for the given noun.
func
g
etArticleForNoun
(
noun
string
,
padding
string
)
string
{
func
G
etArticleForNoun
(
noun
string
,
padding
string
)
string
{
if
noun
[
len
(
noun
)
-
2
:
]
!=
"ss"
&&
noun
[
len
(
noun
)
-
1
:
]
==
"s"
{
if
noun
[
len
(
noun
)
-
2
:
]
!=
"ss"
&&
noun
[
len
(
noun
)
-
1
:
]
==
"s"
{
// Plurals don't have an article.
// Plurals don't have an article.
// Don't catch words like class
// Don't catch words like class
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/installer_test.go
View file @
5a971f04
...
@@ -82,7 +82,7 @@ func TestGetArticleForNoun(t *testing.T) {
...
@@ -82,7 +82,7 @@ func TestGetArticleForNoun(t *testing.T) {
},
},
}
}
for
_
,
tt
:=
range
tests
{
for
_
,
tt
:=
range
tests
{
if
got
:=
g
etArticleForNoun
(
tt
.
noun
,
tt
.
padding
);
got
!=
tt
.
want
{
if
got
:=
G
etArticleForNoun
(
tt
.
noun
,
tt
.
padding
);
got
!=
tt
.
want
{
t
.
Errorf
(
"%q. GetArticleForNoun() = %v, want %v"
,
tt
.
noun
,
got
,
tt
.
want
)
t
.
Errorf
(
"%q. GetArticleForNoun() = %v, want %v"
,
tt
.
noun
,
got
,
tt
.
want
)
}
}
}
}
...
...
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