Turn APIGroupPrefix into a constant

pull/6/head
Dr. Stefan Schimanski 2016-10-18 14:12:24 +02:00
parent c900a0ed7b
commit 08d4fa5c4f
7 changed files with 15 additions and 24 deletions

View File

@ -65,7 +65,7 @@ func installCoreAPIs(s *options.ServerRunOptions, g *genericapiserver.GenericAPI
ParameterCodec: core.ParameterCodec, ParameterCodec: core.ParameterCodec,
NegotiatedSerializer: core.Codecs, NegotiatedSerializer: core.Codecs,
} }
if err := g.InstallLegacyAPIGroup(genericapiserver.LegacyAPIPrefix, &apiGroupInfo); err != nil { if err := g.InstallLegacyAPIGroup(genericapiserver.DefaultLegacyAPIPrefix, &apiGroupInfo); err != nil {
glog.Fatalf("Error in registering group version: %+v.\n Error: %v\n", apiGroupInfo, err) glog.Fatalf("Error in registering group version: %+v.\n Error: %v\n", apiGroupInfo, err)
} }
} }

View File

@ -59,8 +59,11 @@ import (
) )
const ( const (
// LegacyAPIPrefix is where the the legacy APIs will be located // DefaultLegacyAPIPrefix is where the the legacy APIs will be located.
LegacyAPIPrefix = "/api" DefaultLegacyAPIPrefix = "/api"
// APIGroupPrefix is where non-legacy API group will be located.
APIGroupPrefix = "/apis"
) )
// Config is a structure used to configure a GenericAPIServer. // Config is a structure used to configure a GenericAPIServer.
@ -206,7 +209,7 @@ func NewConfig() *Config {
ServiceReadWritePort: 443, ServiceReadWritePort: 443,
RequestContextMapper: api.NewRequestContextMapper(), RequestContextMapper: api.NewRequestContextMapper(),
BuildHandlerChainsFunc: DefaultBuildHandlerChain, BuildHandlerChainsFunc: DefaultBuildHandlerChain,
LegacyAPIGroupPrefixes: sets.NewString(LegacyAPIPrefix), LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix),
EnableIndex: true, EnableIndex: true,
EnableSwaggerSupport: true, EnableSwaggerSupport: true,
@ -275,7 +278,6 @@ func (c *Config) ApplyOptions(options *options.ServerRunOptions) *Config {
c.InsecureServingInfo = insecureServingInfo c.InsecureServingInfo = insecureServingInfo
} }
c.APIGroupPrefix = options.APIGroupPrefix
c.CorsAllowedOriginList = options.CorsAllowedOriginList c.CorsAllowedOriginList = options.CorsAllowedOriginList
c.EnableGarbageCollection = options.EnableGarbageCollection c.EnableGarbageCollection = options.EnableGarbageCollection
c.EnableProfiling = options.EnableProfiling c.EnableProfiling = options.EnableProfiling
@ -373,7 +375,6 @@ func (c completedConfig) New() (*GenericAPIServer, error) {
s := &GenericAPIServer{ s := &GenericAPIServer{
ServiceClusterIPRange: c.ServiceClusterIPRange, ServiceClusterIPRange: c.ServiceClusterIPRange,
LoopbackClientConfig: c.LoopbackClientConfig, LoopbackClientConfig: c.LoopbackClientConfig,
apiPrefix: c.APIGroupPrefix,
legacyAPIGroupPrefixes: c.LegacyAPIGroupPrefixes, legacyAPIGroupPrefixes: c.LegacyAPIGroupPrefixes,
admissionControl: c.AdmissionControl, admissionControl: c.AdmissionControl,
requestContextMapper: c.RequestContextMapper, requestContextMapper: c.RequestContextMapper,
@ -522,8 +523,8 @@ func DefaultAndValidateRunOptions(options *options.ServerRunOptions) {
} }
func NewRequestInfoResolver(c *Config) *request.RequestInfoFactory { func NewRequestInfoResolver(c *Config) *request.RequestInfoFactory {
apiPrefixes := sets.NewString(strings.Trim(c.APIGroupPrefix, "/")) // all possible API prefixes apiPrefixes := sets.NewString(strings.Trim(APIGroupPrefix, "/")) // all possible API prefixes
legacyAPIPrefixes := sets.String{} // APIPrefixes that won't have groups (legacy) legacyAPIPrefixes := sets.String{} // APIPrefixes that won't have groups (legacy)
for legacyAPIPrefix := range c.LegacyAPIGroupPrefixes { for legacyAPIPrefix := range c.LegacyAPIGroupPrefixes {
apiPrefixes.Insert(strings.Trim(legacyAPIPrefix, "/")) apiPrefixes.Insert(strings.Trim(legacyAPIPrefix, "/"))
legacyAPIPrefixes.Insert(strings.Trim(legacyAPIPrefix, "/")) legacyAPIPrefixes.Insert(strings.Trim(legacyAPIPrefix, "/"))

View File

@ -101,9 +101,6 @@ type GenericAPIServer struct {
// TODO eventually we should be able to factor this out to take place during initialization. // TODO eventually we should be able to factor this out to take place during initialization.
enableSwaggerSupport bool enableSwaggerSupport bool
// apiPrefix is the prefix where API groups live, usually /apis
apiPrefix string
// legacyAPIGroupPrefixes is used to set up URL parsing for authorization and for validating requests // legacyAPIGroupPrefixes is used to set up URL parsing for authorization and for validating requests
// to InstallLegacyAPIGroup // to InstallLegacyAPIGroup
legacyAPIGroupPrefixes sets.String legacyAPIGroupPrefixes sets.String
@ -331,7 +328,7 @@ func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error {
return fmt.Errorf("cannot register handler with an empty version for %#v", *apiGroupInfo) return fmt.Errorf("cannot register handler with an empty version for %#v", *apiGroupInfo)
} }
if err := s.installAPIResources(s.apiPrefix, apiGroupInfo); err != nil { if err := s.installAPIResources(APIGroupPrefix, apiGroupInfo); err != nil {
return err return err
} }
@ -360,7 +357,7 @@ func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error {
} }
s.AddAPIGroupForDiscovery(apiGroup) s.AddAPIGroupForDiscovery(apiGroup)
s.HandlerContainer.Add(apiserver.NewGroupWebService(s.Serializer, s.apiPrefix+"/"+apiGroup.Name, apiGroup)) s.HandlerContainer.Add(apiserver.NewGroupWebService(s.Serializer, APIGroupPrefix+"/"+apiGroup.Name, apiGroup))
return nil return nil
} }
@ -487,7 +484,7 @@ func (s *GenericAPIServer) InstallOpenAPI() {
// DynamicApisDiscovery returns a webservice serving api group discovery. // DynamicApisDiscovery returns a webservice serving api group discovery.
// Note: during the server runtime apiGroupsForDiscovery might change. // Note: during the server runtime apiGroupsForDiscovery might change.
func (s *GenericAPIServer) DynamicApisDiscovery() *restful.WebService { func (s *GenericAPIServer) DynamicApisDiscovery() *restful.WebService {
return apiserver.NewApisWebService(s.Serializer, s.apiPrefix, func(req *restful.Request) []unversioned.APIGroup { return apiserver.NewApisWebService(s.Serializer, APIGroupPrefix, func(req *restful.Request) []unversioned.APIGroup {
s.apiGroupsForDiscoveryLock.RLock() s.apiGroupsForDiscoveryLock.RLock()
defer s.apiGroupsForDiscoveryLock.RUnlock() defer s.apiGroupsForDiscoveryLock.RUnlock()

View File

@ -57,7 +57,6 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, *assert.Assertion
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.LegacyAPIGroupPrefixes = sets.NewString("/api") config.LegacyAPIGroupPrefixes = sets.NewString("/api")
config.APIGroupPrefix = "/apis"
return etcdServer, *config, assert.New(t) return etcdServer, *config, assert.New(t)
} }
@ -81,7 +80,6 @@ func TestNew(t *testing.T) {
// Verify many of the variables match their config counterparts // Verify many of the variables match their config counterparts
assert.Equal(s.enableSwaggerSupport, config.EnableSwaggerSupport) assert.Equal(s.enableSwaggerSupport, config.EnableSwaggerSupport)
assert.Equal(s.legacyAPIGroupPrefixes, config.LegacyAPIGroupPrefixes) assert.Equal(s.legacyAPIGroupPrefixes, config.LegacyAPIGroupPrefixes)
assert.Equal(s.apiPrefix, config.APIGroupPrefix)
assert.Equal(s.admissionControl, config.AdmissionControl) assert.Equal(s.admissionControl, config.AdmissionControl)
assert.Equal(s.RequestContextMapper(), config.RequestContextMapper) assert.Equal(s.RequestContextMapper(), config.RequestContextMapper)
@ -106,7 +104,6 @@ func TestInstallAPIGroups(t *testing.T) {
defer etcdserver.Terminate(t) defer etcdserver.Terminate(t)
config.LegacyAPIGroupPrefixes = sets.NewString("/apiPrefix") config.LegacyAPIGroupPrefixes = sets.NewString("/apiPrefix")
config.APIGroupPrefix = "/apiGroupPrefix"
s, err := config.SkipComplete().New() s, err := config.SkipComplete().New()
if err != nil { if err != nil {
@ -145,9 +142,9 @@ func TestInstallAPIGroups(t *testing.T) {
// "/api/v1" // "/api/v1"
config.LegacyAPIGroupPrefixes.List()[0] + "/" + apiGroupMeta.GroupVersion.Version, config.LegacyAPIGroupPrefixes.List()[0] + "/" + apiGroupMeta.GroupVersion.Version,
// "/apis/extensions" // "/apis/extensions"
config.APIGroupPrefix + "/" + extensionsGroupMeta.GroupVersion.Group, APIGroupPrefix + "/" + extensionsGroupMeta.GroupVersion.Group,
// "/apis/extensions/v1beta1" // "/apis/extensions/v1beta1"
config.APIGroupPrefix + "/" + extensionsGroupMeta.GroupVersion.String(), APIGroupPrefix + "/" + extensionsGroupMeta.GroupVersion.String(),
} }
for _, path := range validPaths { for _, path := range validPaths {
_, err := http.Get(server.URL + path) _, err := http.Get(server.URL + path)
@ -224,7 +221,6 @@ func TestNotRestRoutesHaveAuth(t *testing.T) {
authz := mockAuthorizer{} authz := mockAuthorizer{}
config.LegacyAPIGroupPrefixes = sets.NewString("/apiPrefix") config.LegacyAPIGroupPrefixes = sets.NewString("/apiPrefix")
config.APIGroupPrefix = "/apiGroupPrefix"
config.Authorizer = &authz config.Authorizer = &authz
config.EnableSwaggerUI = true config.EnableSwaggerUI = true

View File

@ -55,7 +55,6 @@ var AuthorizationModeChoices = []string{ModeAlwaysAllow, ModeAlwaysDeny, ModeABA
// ServerRunOptions contains the options while running a generic api server. // ServerRunOptions contains the options while running a generic api server.
type ServerRunOptions struct { type ServerRunOptions struct {
APIGroupPrefix string
AdmissionControl string AdmissionControl string
AdmissionControlConfigFile string AdmissionControlConfigFile string
AdvertiseAddress net.IP AdvertiseAddress net.IP
@ -123,7 +122,6 @@ type ServerRunOptions struct {
func NewServerRunOptions() *ServerRunOptions { func NewServerRunOptions() *ServerRunOptions {
return &ServerRunOptions{ return &ServerRunOptions{
APIGroupPrefix: "/apis",
AdmissionControl: "AlwaysAdmit", AdmissionControl: "AlwaysAdmit",
AnonymousAuth: true, AnonymousAuth: true,
AuthorizationMode: "AlwaysAllow", AuthorizationMode: "AlwaysAllow",

View File

@ -265,7 +265,7 @@ func (m *Master) InstallLegacyAPI(c *Config, restOptionsGetter genericapiserver.
} }
} }
if err := m.GenericAPIServer.InstallLegacyAPIGroup(genericapiserver.LegacyAPIPrefix, &apiGroupInfo); err != nil { if err := m.GenericAPIServer.InstallLegacyAPIGroup(genericapiserver.DefaultLegacyAPIPrefix, &apiGroupInfo); err != nil {
glog.Fatalf("Error in registering group versions: %v", err) glog.Fatalf("Error in registering group versions: %v", err)
} }
} }

View File

@ -90,7 +90,6 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource() config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource()
config.GenericConfig.PublicAddress = net.ParseIP("192.168.10.4") config.GenericConfig.PublicAddress = net.ParseIP("192.168.10.4")
config.GenericConfig.LegacyAPIGroupPrefixes = sets.NewString("/api") config.GenericConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
config.GenericConfig.APIGroupPrefix = "/apis"
config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource() config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource()
config.GenericConfig.ProxyDialer = func(network, addr string) (net.Conn, error) { return nil, nil } config.GenericConfig.ProxyDialer = func(network, addr string) (net.Conn, error) { return nil, nil }
config.GenericConfig.ProxyTLSClientConfig = &tls.Config{} config.GenericConfig.ProxyTLSClientConfig = &tls.Config{}