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
d267ab5f
Commit
d267ab5f
authored
Feb 02, 2016
by
nikhiljindal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving /apis handler to generic server
parent
ea5f1233
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
40 deletions
+66
-40
resourceListing.json
api/swagger-spec/resourceListing.json
+4
-4
genericapiserver.go
pkg/genericapiserver/genericapiserver.go
+36
-0
genericapiserver_test.go
pkg/genericapiserver/genericapiserver_test.go
+1
-0
master.go
pkg/master/master.go
+2
-17
master_test.go
pkg/master/master_test.go
+19
-19
thirdparty_controller.go
pkg/master/thirdparty_controller.go
+4
-0
No files found.
api/swagger-spec/resourceListing.json
View file @
d267ab5f
...
@@ -2,6 +2,10 @@
...
@@ -2,6 +2,10 @@
"swaggerVersion"
:
"1.2"
,
"swaggerVersion"
:
"1.2"
,
"apis"
:
[
"apis"
:
[
{
{
"path"
:
"/apis"
,
"description"
:
"get available API versions"
},
{
"path"
:
"/version"
,
"path"
:
"/version"
,
"description"
:
"git code version from which this is built"
"description"
:
"git code version from which this is built"
},
},
...
@@ -20,10 +24,6 @@
...
@@ -20,10 +24,6 @@
{
{
"path"
:
"/apis/extensions"
,
"path"
:
"/apis/extensions"
,
"description"
:
"get information of a group"
"description"
:
"get information of a group"
},
{
"path"
:
"/apis"
,
"description"
:
"get available API versions"
}
}
],
],
"apiVersion"
:
""
,
"apiVersion"
:
""
,
...
...
pkg/genericapiserver/genericapiserver.go
View file @
d267ab5f
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"net/http/pprof"
"net/http/pprof"
"path"
"path"
"regexp"
"regexp"
"sort"
"strconv"
"strconv"
"strings"
"strings"
"time"
"time"
...
@@ -301,6 +302,10 @@ type GenericAPIServer struct {
...
@@ -301,6 +302,10 @@ type GenericAPIServer struct {
ProxyTransport
http
.
RoundTripper
ProxyTransport
http
.
RoundTripper
KubernetesServiceNodePort
int
KubernetesServiceNodePort
int
// Map storing information about all groups to be exposed in discovery response.
// The map is from name to the group.
apiGroupsForDiscovery
map
[
string
]
unversioned
.
APIGroup
}
}
func
(
s
*
GenericAPIServer
)
StorageDecorator
()
generic
.
StorageDecorator
{
func
(
s
*
GenericAPIServer
)
StorageDecorator
()
generic
.
StorageDecorator
{
...
@@ -415,6 +420,7 @@ func New(c *Config) *GenericAPIServer {
...
@@ -415,6 +420,7 @@ func New(c *Config) *GenericAPIServer {
ExtraEndpointPorts
:
c
.
ExtraEndpointPorts
,
ExtraEndpointPorts
:
c
.
ExtraEndpointPorts
,
KubernetesServiceNodePort
:
c
.
KubernetesServiceNodePort
,
KubernetesServiceNodePort
:
c
.
KubernetesServiceNodePort
,
apiGroupsForDiscovery
:
map
[
string
]
unversioned
.
APIGroup
{},
}
}
var
handlerContainer
*
restful
.
Container
var
handlerContainer
*
restful
.
Container
...
@@ -543,6 +549,8 @@ func (s *GenericAPIServer) init(c *Config) {
...
@@ -543,6 +549,8 @@ func (s *GenericAPIServer) init(c *Config) {
}
else
{
}
else
{
s
.
InsecureHandler
=
handler
s
.
InsecureHandler
=
handler
}
}
s
.
installGroupsDiscoveryHandler
()
}
}
// Exposes the given group versions in API.
// Exposes the given group versions in API.
...
@@ -555,6 +563,25 @@ func (s *GenericAPIServer) InstallAPIGroups(groupsInfo []APIGroupInfo) error {
...
@@ -555,6 +563,25 @@ func (s *GenericAPIServer) InstallAPIGroups(groupsInfo []APIGroupInfo) error {
return
nil
return
nil
}
}
// Installs handler at /apis to list all group versions for discovery
func
(
s
*
GenericAPIServer
)
installGroupsDiscoveryHandler
()
{
apiserver
.
AddApisWebService
(
s
.
Serializer
,
s
.
HandlerContainer
,
s
.
APIGroupPrefix
,
func
()
[]
unversioned
.
APIGroup
{
// Return the list of supported groups in sorted order (to have a deterministic order).
groups
:=
[]
unversioned
.
APIGroup
{}
groupNames
:=
make
([]
string
,
len
(
s
.
apiGroupsForDiscovery
))
var
i
int
=
0
for
groupName
:=
range
s
.
apiGroupsForDiscovery
{
groupNames
[
i
]
=
groupName
i
++
}
sort
.
Strings
(
groupNames
)
for
_
,
groupName
:=
range
groupNames
{
groups
=
append
(
groups
,
s
.
apiGroupsForDiscovery
[
groupName
])
}
return
groups
})
}
func
(
s
*
GenericAPIServer
)
Run
(
options
*
ServerRunOptions
)
{
func
(
s
*
GenericAPIServer
)
Run
(
options
*
ServerRunOptions
)
{
// We serve on 2 ports. See docs/accessing_the_api.md
// We serve on 2 ports. See docs/accessing_the_api.md
secureLocation
:=
""
secureLocation
:=
""
...
@@ -692,12 +719,21 @@ func (s *GenericAPIServer) installAPIGroup(apiGroupInfo *APIGroupInfo) error {
...
@@ -692,12 +719,21 @@ func (s *GenericAPIServer) installAPIGroup(apiGroupInfo *APIGroupInfo) error {
Versions
:
apiVersionsForDiscovery
,
Versions
:
apiVersionsForDiscovery
,
PreferredVersion
:
preferedVersionForDiscovery
,
PreferredVersion
:
preferedVersionForDiscovery
,
}
}
s
.
AddAPIGroupForDiscovery
(
apiGroup
)
apiserver
.
AddGroupWebService
(
s
.
Serializer
,
s
.
HandlerContainer
,
apiPrefix
+
"/"
+
apiGroup
.
Name
,
apiGroup
)
apiserver
.
AddGroupWebService
(
s
.
Serializer
,
s
.
HandlerContainer
,
apiPrefix
+
"/"
+
apiGroup
.
Name
,
apiGroup
)
}
}
apiserver
.
InstallServiceErrorHandler
(
s
.
Serializer
,
s
.
HandlerContainer
,
s
.
NewRequestInfoResolver
(),
apiVersions
)
apiserver
.
InstallServiceErrorHandler
(
s
.
Serializer
,
s
.
HandlerContainer
,
s
.
NewRequestInfoResolver
(),
apiVersions
)
return
nil
return
nil
}
}
func
(
s
*
GenericAPIServer
)
AddAPIGroupForDiscovery
(
apiGroup
unversioned
.
APIGroup
)
{
s
.
apiGroupsForDiscovery
[
apiGroup
.
Name
]
=
apiGroup
}
func
(
s
*
GenericAPIServer
)
RemoveAPIGroupForDiscovery
(
groupName
string
)
{
delete
(
s
.
apiGroupsForDiscovery
,
groupName
)
}
func
(
s
*
GenericAPIServer
)
getAPIGroupVersion
(
apiGroupInfo
*
APIGroupInfo
,
groupVersion
unversioned
.
GroupVersion
,
apiPrefix
string
)
(
*
apiserver
.
APIGroupVersion
,
error
)
{
func
(
s
*
GenericAPIServer
)
getAPIGroupVersion
(
apiGroupInfo
*
APIGroupInfo
,
groupVersion
unversioned
.
GroupVersion
,
apiPrefix
string
)
(
*
apiserver
.
APIGroupVersion
,
error
)
{
storage
:=
make
(
map
[
string
]
rest
.
Storage
)
storage
:=
make
(
map
[
string
]
rest
.
Storage
)
for
k
,
v
:=
range
apiGroupInfo
.
VersionedResourcesStorageMap
[
groupVersion
.
Version
]
{
for
k
,
v
:=
range
apiGroupInfo
.
VersionedResourcesStorageMap
[
groupVersion
.
Version
]
{
...
...
pkg/genericapiserver/genericapiserver_test.go
View file @
d267ab5f
...
@@ -54,6 +54,7 @@ func TestNew(t *testing.T) {
...
@@ -54,6 +54,7 @@ func TestNew(t *testing.T) {
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyTLSClientConfig
=
&
tls
.
Config
{}
config
.
ProxyTLSClientConfig
=
&
tls
.
Config
{}
config
.
Serializer
=
api
.
Codecs
s
:=
New
(
&
config
)
s
:=
New
(
&
config
)
...
...
pkg/master/master.go
View file @
d267ab5f
...
@@ -241,23 +241,6 @@ func (m *Master) InstallAPIs(c *Config) {
...
@@ -241,23 +241,6 @@ func (m *Master) InstallAPIs(c *Config) {
if
err
:=
m
.
InstallAPIGroups
(
apiGroupsInfo
);
err
!=
nil
{
if
err
:=
m
.
InstallAPIGroups
(
apiGroupsInfo
);
err
!=
nil
{
glog
.
Fatalf
(
"Error in registering group versions: %v"
,
err
)
glog
.
Fatalf
(
"Error in registering group versions: %v"
,
err
)
}
}
// This should be done after all groups are registered
// TODO: replace the hardcoded "apis".
apiserver
.
AddApisWebService
(
m
.
Serializer
,
m
.
HandlerContainer
,
"/apis"
,
func
()
[]
unversioned
.
APIGroup
{
groups
:=
[]
unversioned
.
APIGroup
{}
for
ix
:=
range
allGroups
{
groups
=
append
(
groups
,
allGroups
[
ix
])
}
m
.
thirdPartyResourcesLock
.
Lock
()
defer
m
.
thirdPartyResourcesLock
.
Unlock
()
if
m
.
thirdPartyResources
!=
nil
{
for
key
:=
range
m
.
thirdPartyResources
{
groups
=
append
(
groups
,
m
.
thirdPartyResources
[
key
]
.
group
)
}
}
return
groups
})
}
}
func
(
m
*
Master
)
initV1ResourcesStorage
(
c
*
Config
)
{
func
(
m
*
Master
)
initV1ResourcesStorage
(
c
*
Config
)
{
...
@@ -446,6 +429,7 @@ func (m *Master) removeThirdPartyStorage(path string) error {
...
@@ -446,6 +429,7 @@ func (m *Master) removeThirdPartyStorage(path string) error {
return
err
return
err
}
}
delete
(
m
.
thirdPartyResources
,
path
)
delete
(
m
.
thirdPartyResources
,
path
)
m
.
RemoveAPIGroupForDiscovery
(
getThirdPartyGroupName
(
path
))
}
}
return
nil
return
nil
}
}
...
@@ -500,6 +484,7 @@ func (m *Master) addThirdPartyResourceStorage(path string, storage *thirdpartyre
...
@@ -500,6 +484,7 @@ func (m *Master) addThirdPartyResourceStorage(path string, storage *thirdpartyre
m
.
thirdPartyResourcesLock
.
Lock
()
m
.
thirdPartyResourcesLock
.
Lock
()
defer
m
.
thirdPartyResourcesLock
.
Unlock
()
defer
m
.
thirdPartyResourcesLock
.
Unlock
()
m
.
thirdPartyResources
[
path
]
=
thirdPartyEntry
{
storage
,
apiGroup
}
m
.
thirdPartyResources
[
path
]
=
thirdPartyEntry
{
storage
,
apiGroup
}
m
.
AddAPIGroupForDiscovery
(
apiGroup
)
}
}
// InstallThirdPartyResource installs a third party resource specified by 'rsrc'. When a resource is
// InstallThirdPartyResource installs a third party resource specified by 'rsrc'. When a resource is
...
...
pkg/master/master_test.go
View file @
d267ab5f
...
@@ -48,7 +48,6 @@ import (
...
@@ -48,7 +48,6 @@ import (
etcdtesting
"k8s.io/kubernetes/pkg/storage/etcd/testing"
etcdtesting
"k8s.io/kubernetes/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/intstr"
"github.com/emicklei/go-restful"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
"golang.org/x/net/context"
)
)
...
@@ -85,6 +84,8 @@ func newMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *ass
...
@@ -85,6 +84,8 @@ func newMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *ass
config
.
Serializer
=
api
.
Codecs
config
.
Serializer
=
api
.
Codecs
config
.
KubeletClient
=
client
.
FakeKubeletClient
{}
config
.
KubeletClient
=
client
.
FakeKubeletClient
{}
config
.
APIPrefix
=
"/api"
config
.
APIGroupPrefix
=
"/apis"
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyTLSClientConfig
=
&
tls
.
Config
{}
config
.
ProxyTLSClientConfig
=
&
tls
.
Config
{}
...
@@ -269,30 +270,28 @@ func TestDiscoveryAtAPIS(t *testing.T) {
...
@@ -269,30 +270,28 @@ func TestDiscoveryAtAPIS(t *testing.T) {
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
ex
pect
GroupName
:=
extensions
.
GroupName
ex
tensions
GroupName
:=
extensions
.
GroupName
ex
pect
Versions
:=
[]
unversioned
.
GroupVersionForDiscovery
{
ex
tensions
Versions
:=
[]
unversioned
.
GroupVersionForDiscovery
{
{
{
GroupVersion
:
testapi
.
Extensions
.
GroupVersion
()
.
String
(),
GroupVersion
:
testapi
.
Extensions
.
GroupVersion
()
.
String
(),
Version
:
testapi
.
Extensions
.
GroupVersion
()
.
Version
,
Version
:
testapi
.
Extensions
.
GroupVersion
()
.
Version
,
},
},
}
}
ex
pect
PreferredVersion
:=
unversioned
.
GroupVersionForDiscovery
{
ex
tensions
PreferredVersion
:=
unversioned
.
GroupVersionForDiscovery
{
GroupVersion
:
config
.
StorageVersions
[
extensions
.
GroupName
],
GroupVersion
:
config
.
StorageVersions
[
extensions
.
GroupName
],
Version
:
apiutil
.
GetVersion
(
config
.
StorageVersions
[
extensions
.
GroupName
]),
Version
:
apiutil
.
GetVersion
(
config
.
StorageVersions
[
extensions
.
GroupName
]),
}
}
assert
.
Equal
(
ex
pect
GroupName
,
groupList
.
Groups
[
0
]
.
Name
)
assert
.
Equal
(
ex
tensions
GroupName
,
groupList
.
Groups
[
0
]
.
Name
)
assert
.
Equal
(
ex
pect
Versions
,
groupList
.
Groups
[
0
]
.
Versions
)
assert
.
Equal
(
ex
tensions
Versions
,
groupList
.
Groups
[
0
]
.
Versions
)
assert
.
Equal
(
ex
pect
PreferredVersion
,
groupList
.
Groups
[
0
]
.
PreferredVersion
)
assert
.
Equal
(
ex
tensions
PreferredVersion
,
groupList
.
Groups
[
0
]
.
PreferredVersion
)
thirdPartyGV
:=
unversioned
.
GroupVersionForDiscovery
{
GroupVersion
:
"company.com/v1"
,
Version
:
"v1"
}
thirdPartyGV
:=
unversioned
.
GroupVersionForDiscovery
{
GroupVersion
:
"company.com/v1"
,
Version
:
"v1"
}
master
.
thirdPartyResources
[
"/apis/company.com/v1"
]
=
thirdPartyEntry
{
master
.
addThirdPartyResourceStorage
(
"/apis/company.com/v1"
,
nil
,
nil
,
unversioned
.
APIGroup
{
unversioned
.
APIGroup
{
Name
:
"company.com"
,
Name
:
"company.com"
,
Versions
:
[]
unversioned
.
GroupVersionForDiscovery
{
thirdPartyGV
},
Versions
:
[]
unversioned
.
GroupVersionForDiscovery
{
thirdPartyGV
},
PreferredVersion
:
thirdPartyGV
,
PreferredVersion
:
thirdPartyGV
,
},
})
}
resp
,
err
=
http
.
Get
(
server
.
URL
+
"/apis"
)
resp
,
err
=
http
.
Get
(
server
.
URL
+
"/apis"
)
if
!
assert
.
NoError
(
err
)
{
if
!
assert
.
NoError
(
err
)
{
...
@@ -309,10 +308,13 @@ func TestDiscoveryAtAPIS(t *testing.T) {
...
@@ -309,10 +308,13 @@ func TestDiscoveryAtAPIS(t *testing.T) {
thirdPartyGroupName
:=
"company.com"
thirdPartyGroupName
:=
"company.com"
thirdPartyExpectVersions
:=
[]
unversioned
.
GroupVersionForDiscovery
{
thirdPartyGV
}
thirdPartyExpectVersions
:=
[]
unversioned
.
GroupVersionForDiscovery
{
thirdPartyGV
}
assert
.
Equal
(
thirdPartyGroupName
,
groupList
.
Groups
[
1
]
.
Name
)
assert
.
Equal
(
2
,
len
(
groupList
.
Groups
))
assert
.
Equal
(
thirdPartyExpectVersions
,
groupList
.
Groups
[
1
]
.
Versions
)
assert
.
Equal
(
thirdPartyGroupName
,
groupList
.
Groups
[
0
]
.
Name
)
assert
.
Equal
(
thirdPartyGV
,
groupList
.
Groups
[
1
]
.
PreferredVersion
)
assert
.
Equal
(
thirdPartyExpectVersions
,
groupList
.
Groups
[
0
]
.
Versions
)
assert
.
Equal
(
thirdPartyGV
,
groupList
.
Groups
[
0
]
.
PreferredVersion
)
assert
.
Equal
(
extensionsGroupName
,
groupList
.
Groups
[
1
]
.
Name
)
assert
.
Equal
(
extensionsVersions
,
groupList
.
Groups
[
1
]
.
Versions
)
assert
.
Equal
(
extensionsPreferredVersion
,
groupList
.
Groups
[
1
]
.
PreferredVersion
)
}
}
var
versionsToTest
=
[]
string
{
"v1"
,
"v3"
}
var
versionsToTest
=
[]
string
{
"v1"
,
"v3"
}
...
@@ -333,9 +335,8 @@ type FooList struct {
...
@@ -333,9 +335,8 @@ type FooList struct {
}
}
func
initThirdParty
(
t
*
testing
.
T
,
version
string
)
(
*
Master
,
*
etcdtesting
.
EtcdTestServer
,
*
httptest
.
Server
,
*
assert
.
Assertions
)
{
func
initThirdParty
(
t
*
testing
.
T
,
version
string
)
(
*
Master
,
*
etcdtesting
.
EtcdTestServer
,
*
httptest
.
Server
,
*
assert
.
Assertions
)
{
master
,
etcdserver
,
_
,
assert
:=
setUp
(
t
)
master
,
etcdserver
,
_
,
assert
:=
newMaster
(
t
)
master
.
thirdPartyResources
=
map
[
string
]
thirdPartyEntry
{}
api
:=
&
extensions
.
ThirdPartyResource
{
api
:=
&
extensions
.
ThirdPartyResource
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo.company.com"
,
Name
:
"foo.company.com"
,
...
@@ -347,7 +348,6 @@ func initThirdParty(t *testing.T, version string) (*Master, *etcdtesting.EtcdTes
...
@@ -347,7 +348,6 @@ func initThirdParty(t *testing.T, version string) (*Master, *etcdtesting.EtcdTes
},
},
},
},
}
}
master
.
HandlerContainer
=
restful
.
NewContainer
()
master
.
thirdPartyStorage
=
etcdstorage
.
NewEtcdStorage
(
etcdserver
.
Client
,
testapi
.
Extensions
.
Codec
(),
etcdtest
.
PathPrefix
(),
false
)
master
.
thirdPartyStorage
=
etcdstorage
.
NewEtcdStorage
(
etcdserver
.
Client
,
testapi
.
Extensions
.
Codec
(),
etcdtest
.
PathPrefix
(),
false
)
if
!
assert
.
NoError
(
master
.
InstallThirdPartyResource
(
api
))
{
if
!
assert
.
NoError
(
master
.
InstallThirdPartyResource
(
api
))
{
...
@@ -355,7 +355,7 @@ func initThirdParty(t *testing.T, version string) (*Master, *etcdtesting.EtcdTes
...
@@ -355,7 +355,7 @@ func initThirdParty(t *testing.T, version string) (*Master, *etcdtesting.EtcdTes
}
}
server
:=
httptest
.
NewServer
(
master
.
HandlerContainer
.
ServeMux
)
server
:=
httptest
.
NewServer
(
master
.
HandlerContainer
.
ServeMux
)
return
&
master
,
etcdserver
,
server
,
assert
return
master
,
etcdserver
,
server
,
assert
}
}
func
TestInstallThirdPartyAPIList
(
t
*
testing
.
T
)
{
func
TestInstallThirdPartyAPIList
(
t
*
testing
.
T
)
{
...
...
pkg/master/thirdparty_controller.go
View file @
d267ab5f
...
@@ -37,6 +37,10 @@ func makeThirdPartyPath(group string) string {
...
@@ -37,6 +37,10 @@ func makeThirdPartyPath(group string) string {
return
thirdpartyprefix
+
"/"
+
group
return
thirdpartyprefix
+
"/"
+
group
}
}
func
getThirdPartyGroupName
(
path
string
)
string
{
return
strings
.
TrimPrefix
(
strings
.
TrimPrefix
(
path
,
thirdpartyprefix
),
"/"
)
}
// resourceInterface is the interface for the parts of the master that know how to add/remove
// resourceInterface is the interface for the parts of the master that know how to add/remove
// third party resources. Extracted into an interface for injection for testing.
// third party resources. Extracted into an interface for injection for testing.
type
resourceInterface
interface
{
type
resourceInterface
interface
{
...
...
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