Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make APIGroupPrefix constant: "/apis" #35034

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion federation/cmd/federation-apiserver/app/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func installCoreAPIs(s *options.ServerRunOptions, g *genericapiserver.GenericAPI
ParameterCodec: core.ParameterCodec,
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)
}
}
15 changes: 8 additions & 7 deletions pkg/genericapiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ import (
)

const (
// LegacyAPIPrefix is where the the legacy APIs will be located
LegacyAPIPrefix = "/api"
// DefaultLegacyAPIPrefix is where the the legacy APIs will be located.
DefaultLegacyAPIPrefix = "/api"

// APIGroupPrefix is where non-legacy API group will be located.
APIGroupPrefix = "/apis"
)

// Config is a structure used to configure a GenericAPIServer.
Expand Down Expand Up @@ -206,7 +209,7 @@ func NewConfig() *Config {
ServiceReadWritePort: 443,
RequestContextMapper: api.NewRequestContextMapper(),
BuildHandlerChainsFunc: DefaultBuildHandlerChain,
LegacyAPIGroupPrefixes: sets.NewString(LegacyAPIPrefix),
LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix),

EnableIndex: true,
EnableSwaggerSupport: true,
Expand Down Expand Up @@ -275,7 +278,6 @@ func (c *Config) ApplyOptions(options *options.ServerRunOptions) *Config {
c.InsecureServingInfo = insecureServingInfo
}

c.APIGroupPrefix = options.APIGroupPrefix
c.CorsAllowedOriginList = options.CorsAllowedOriginList
c.EnableGarbageCollection = options.EnableGarbageCollection
c.EnableProfiling = options.EnableProfiling
Expand Down Expand Up @@ -373,7 +375,6 @@ func (c completedConfig) New() (*GenericAPIServer, error) {
s := &GenericAPIServer{
ServiceClusterIPRange: c.ServiceClusterIPRange,
LoopbackClientConfig: c.LoopbackClientConfig,
apiPrefix: c.APIGroupPrefix,
legacyAPIGroupPrefixes: c.LegacyAPIGroupPrefixes,
admissionControl: c.AdmissionControl,
requestContextMapper: c.RequestContextMapper,
Expand Down Expand Up @@ -522,8 +523,8 @@ func DefaultAndValidateRunOptions(options *options.ServerRunOptions) {
}

func NewRequestInfoResolver(c *Config) *request.RequestInfoFactory {
apiPrefixes := sets.NewString(strings.Trim(c.APIGroupPrefix, "/")) // all possible API prefixes
legacyAPIPrefixes := sets.String{} // APIPrefixes that won't have groups (legacy)
apiPrefixes := sets.NewString(strings.Trim(APIGroupPrefix, "/")) // all possible API prefixes
legacyAPIPrefixes := sets.String{} // APIPrefixes that won't have groups (legacy)
for legacyAPIPrefix := range c.LegacyAPIGroupPrefixes {
apiPrefixes.Insert(strings.Trim(legacyAPIPrefix, "/"))
legacyAPIPrefixes.Insert(strings.Trim(legacyAPIPrefix, "/"))
Expand Down
9 changes: 3 additions & 6 deletions pkg/genericapiserver/genericapiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ type GenericAPIServer struct {
// TODO eventually we should be able to factor this out to take place during initialization.
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
// to InstallLegacyAPIGroup
legacyAPIGroupPrefixes sets.String
Expand Down Expand Up @@ -331,7 +328,7 @@ func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error {
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
}

Expand Down Expand Up @@ -360,7 +357,7 @@ func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error {
}

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
}
Expand Down Expand Up @@ -487,7 +484,7 @@ func (s *GenericAPIServer) InstallOpenAPI() {
// DynamicApisDiscovery returns a webservice serving api group discovery.
// Note: during the server runtime apiGroupsForDiscovery might change.
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()
defer s.apiGroupsForDiscoveryLock.RUnlock()

Expand Down
8 changes: 2 additions & 6 deletions pkg/genericapiserver/genericapiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.ProxyTLSClientConfig = &tls.Config{}
config.LegacyAPIGroupPrefixes = sets.NewString("/api")
config.APIGroupPrefix = "/apis"

return etcdServer, *config, assert.New(t)
}
Expand All @@ -81,7 +80,6 @@ func TestNew(t *testing.T) {
// Verify many of the variables match their config counterparts
assert.Equal(s.enableSwaggerSupport, config.EnableSwaggerSupport)
assert.Equal(s.legacyAPIGroupPrefixes, config.LegacyAPIGroupPrefixes)
assert.Equal(s.apiPrefix, config.APIGroupPrefix)
assert.Equal(s.admissionControl, config.AdmissionControl)
assert.Equal(s.RequestContextMapper(), config.RequestContextMapper)

Expand All @@ -106,7 +104,6 @@ func TestInstallAPIGroups(t *testing.T) {
defer etcdserver.Terminate(t)

config.LegacyAPIGroupPrefixes = sets.NewString("/apiPrefix")
config.APIGroupPrefix = "/apiGroupPrefix"

s, err := config.SkipComplete().New()
if err != nil {
Expand Down Expand Up @@ -145,9 +142,9 @@ func TestInstallAPIGroups(t *testing.T) {
// "/api/v1"
config.LegacyAPIGroupPrefixes.List()[0] + "/" + apiGroupMeta.GroupVersion.Version,
// "/apis/extensions"
config.APIGroupPrefix + "/" + extensionsGroupMeta.GroupVersion.Group,
APIGroupPrefix + "/" + extensionsGroupMeta.GroupVersion.Group,
// "/apis/extensions/v1beta1"
config.APIGroupPrefix + "/" + extensionsGroupMeta.GroupVersion.String(),
APIGroupPrefix + "/" + extensionsGroupMeta.GroupVersion.String(),
}
for _, path := range validPaths {
_, err := http.Get(server.URL + path)
Expand Down Expand Up @@ -224,7 +221,6 @@ func TestNotRestRoutesHaveAuth(t *testing.T) {
authz := mockAuthorizer{}

config.LegacyAPIGroupPrefixes = sets.NewString("/apiPrefix")
config.APIGroupPrefix = "/apiGroupPrefix"
config.Authorizer = &authz

config.EnableSwaggerUI = true
Expand Down
2 changes: 0 additions & 2 deletions pkg/genericapiserver/options/server_run_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ var AuthorizationModeChoices = []string{ModeAlwaysAllow, ModeAlwaysDeny, ModeABA

// ServerRunOptions contains the options while running a generic api server.
type ServerRunOptions struct {
APIGroupPrefix string
AdmissionControl string
AdmissionControlConfigFile string
AdvertiseAddress net.IP
Expand Down Expand Up @@ -123,7 +122,6 @@ type ServerRunOptions struct {

func NewServerRunOptions() *ServerRunOptions {
return &ServerRunOptions{
APIGroupPrefix: "/apis",
AdmissionControl: "AlwaysAdmit",
AnonymousAuth: true,
AuthorizationMode: "AlwaysAllow",
Expand Down
2 changes: 1 addition & 1 deletion pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/master/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource()
config.GenericConfig.PublicAddress = net.ParseIP("192.168.10.4")
config.GenericConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
config.GenericConfig.APIGroupPrefix = "/apis"
config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource()
config.GenericConfig.ProxyDialer = func(network, addr string) (net.Conn, error) { return nil, nil }
config.GenericConfig.ProxyTLSClientConfig = &tls.Config{}
Expand Down