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
94b8554c
Commit
94b8554c
authored
Feb 14, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21033 from nikhiljindal/swaggerspecInGenericServer
Auto commit by PR queue bot
parents
62258cab
e2bffac2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
10 deletions
+45
-10
apiserver.go
examples/apiserver/apiserver.go
+5
-4
apiserver_test.go
examples/apiserver/apiserver_test.go
+36
-0
genericapiserver.go
pkg/genericapiserver/genericapiserver.go
+4
-1
master.go
pkg/master/master.go
+0
-5
No files found.
examples/apiserver/apiserver.go
View file @
94b8554c
...
...
@@ -48,10 +48,11 @@ func newStorageDestinations(groupName string, groupMeta *apimachinery.GroupMeta)
func
Run
()
error
{
config
:=
genericapiserver
.
Config
{
EnableIndex
:
true
,
APIPrefix
:
"/api"
,
APIGroupPrefix
:
"/apis"
,
Serializer
:
api
.
Codecs
,
EnableIndex
:
true
,
EnableSwaggerSupport
:
true
,
APIPrefix
:
"/api"
,
APIGroupPrefix
:
"/apis"
,
Serializer
:
api
.
Codecs
,
}
s
,
err
:=
genericapiserver
.
New
(
&
config
)
if
err
!=
nil
{
...
...
examples/apiserver/apiserver_test.go
View file @
94b8554c
...
...
@@ -34,6 +34,11 @@ var serverIP = "http://localhost:8080"
var
groupVersion
=
v1
.
SchemeGroupVersion
var
groupVersionForDiscovery
=
unversioned
.
GroupVersionForDiscovery
{
GroupVersion
:
groupVersion
.
String
(),
Version
:
groupVersion
.
Version
,
}
func
TestRun
(
t
*
testing
.
T
)
{
go
func
()
{
if
err
:=
Run
();
err
!=
nil
{
...
...
@@ -43,6 +48,8 @@ func TestRun(t *testing.T) {
if
err
:=
waitForApiserverUp
();
err
!=
nil
{
t
.
Fatalf
(
"%v"
,
err
)
}
testSwaggerSpec
(
t
)
testAPIGroupList
(
t
)
testAPIGroup
(
t
)
testAPIResourceList
(
t
)
}
...
...
@@ -63,6 +70,9 @@ func readResponse(serverURL string) ([]byte, error) {
return
nil
,
fmt
.
Errorf
(
"Error in fetching %s: %v"
,
serverURL
,
err
)
}
defer
response
.
Body
.
Close
()
if
response
.
StatusCode
!=
http
.
StatusOK
{
return
nil
,
fmt
.
Errorf
(
"unexpected status: %d for URL: %s, expected status: %d"
,
response
.
StatusCode
,
serverURL
,
http
.
StatusOK
)
}
contents
,
err
:=
ioutil
.
ReadAll
(
response
.
Body
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error reading response from %s: %v"
,
serverURL
,
err
)
...
...
@@ -70,6 +80,32 @@ func readResponse(serverURL string) ([]byte, error) {
return
contents
,
nil
}
func
testSwaggerSpec
(
t
*
testing
.
T
)
{
serverURL
:=
serverIP
+
"/swaggerapi"
_
,
err
:=
readResponse
(
serverURL
)
if
err
!=
nil
{
t
.
Fatalf
(
"%v"
,
err
)
}
}
func
testAPIGroupList
(
t
*
testing
.
T
)
{
serverURL
:=
serverIP
+
"/apis"
contents
,
err
:=
readResponse
(
serverURL
)
if
err
!=
nil
{
t
.
Fatalf
(
"%v"
,
err
)
}
var
apiGroupList
unversioned
.
APIGroupList
err
=
json
.
Unmarshal
(
contents
,
&
apiGroupList
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error in unmarshalling response from server %s: %v"
,
serverURL
,
err
)
}
assert
.
Equal
(
t
,
1
,
len
(
apiGroupList
.
Groups
))
assert
.
Equal
(
t
,
apiGroupList
.
Groups
[
0
]
.
Name
,
groupVersion
.
Group
)
assert
.
Equal
(
t
,
1
,
len
(
apiGroupList
.
Groups
[
0
]
.
Versions
))
assert
.
Equal
(
t
,
apiGroupList
.
Groups
[
0
]
.
Versions
[
0
],
groupVersionForDiscovery
)
assert
.
Equal
(
t
,
apiGroupList
.
Groups
[
0
]
.
PreferredVersion
,
groupVersionForDiscovery
)
}
func
testAPIGroup
(
t
*
testing
.
T
)
{
serverURL
:=
serverIP
+
"/apis/testgroup"
contents
,
err
:=
readResponse
(
serverURL
)
...
...
pkg/genericapiserver/genericapiserver.go
View file @
94b8554c
...
...
@@ -563,6 +563,9 @@ func (s *GenericAPIServer) InstallAPIGroups(groupsInfo []APIGroupInfo) error {
return
err
}
}
if
s
.
enableSwaggerSupport
{
s
.
InstallSwaggerAPI
()
}
return
nil
}
...
...
@@ -778,7 +781,7 @@ func (s *GenericAPIServer) newAPIGroupVersion(groupMeta apimachinery.GroupMeta,
}
// InstallSwaggerAPI installs the /swaggerapi/ endpoint to allow schema discovery
// and traversal.
It is optional to allow consumers of the Kubernetes GenericAPIServer to
// and traversal. It is optional to allow consumers of the Kubernetes GenericAPIServer to
// register their own web services into the Kubernetes mux prior to initialization
// of swagger, so that other resource types show up in the documentation.
func
(
s
*
GenericAPIServer
)
InstallSwaggerAPI
()
{
...
...
pkg/master/master.go
View file @
94b8554c
...
...
@@ -153,11 +153,6 @@ func New(c *Config) (*Master, error) {
}
m
.
InstallAPIs
(
c
)
// TODO: Move this to generic api server.
if
c
.
EnableSwaggerSupport
{
m
.
InstallSwaggerAPI
()
}
// TODO: Attempt clean shutdown?
if
m
.
enableCoreControllers
{
m
.
NewBootstrapController
()
.
Start
()
...
...
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