From 42175b433ab25ee42140b5c6f84cc542bf69ecc7 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Fri, 30 Jan 2015 18:53:04 -0500 Subject: [PATCH] Make master index optional when master is used in other contexts OpenShift provides a default URL at the root that shows the UI. The provided flag makes loading the index handler optional for now. --- pkg/master/master.go | 31 +++++++++++++++++++------------ pkg/master/server/server.go | 1 + pkg/standalone/standalone.go | 1 + test/integration/auth_test.go | 8 ++++++++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/pkg/master/master.go b/pkg/master/master.go index cc81000fa52..6aadae1bef5 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -65,17 +65,21 @@ import ( // Config is a structure used to configure a Master. type Config struct { - Client *client.Client - Cloud cloudprovider.Interface - EtcdHelper tools.EtcdHelper - EventTTL time.Duration - MinionRegexp string - KubeletClient client.KubeletClient - PortalNet *net.IPNet - EnableLogsSupport bool - EnableUISupport bool - EnableSwaggerSupport bool - EnableV1Beta3 bool + Client *client.Client + Cloud cloudprovider.Interface + EtcdHelper tools.EtcdHelper + EventTTL time.Duration + MinionRegexp string + KubeletClient client.KubeletClient + PortalNet *net.IPNet + EnableLogsSupport bool + EnableUISupport bool + // allow downstream consumers to disable swagger + EnableSwaggerSupport bool + // allow v1beta3 to be conditionally enabled + EnableV1Beta3 bool + // allow downstream consumers to disable the index route + EnableIndex bool APIPrefix string CorsAllowedOriginList util.StringList Authenticator authenticator.Request @@ -384,7 +388,10 @@ func (m *Master) init(c *Config) { // Register root handler. // We do not register this using restful Webservice since we do not want to surface this in api docs. - m.mux.HandleFunc("/", apiserver.IndexHandler(m.handlerContainer, m.muxHelper)) + // Allow master to be embedded in contexts which already have something registered at the root + if c.EnableIndex { + m.mux.HandleFunc("/", apiserver.IndexHandler(m.handlerContainer, m.muxHelper)) + } // TODO: use go-restful apiserver.InstallValidator(m.muxHelper, func() map[string]apiserver.Server { return m.getServersToValidate(c) }) diff --git a/pkg/master/server/server.go b/pkg/master/server/server.go index 9c95dfd4d53..cf4e8efaad9 100644 --- a/pkg/master/server/server.go +++ b/pkg/master/server/server.go @@ -247,6 +247,7 @@ func (s *APIServer) Run(_ []string) error { EnableLogsSupport: s.EnableLogsSupport, EnableUISupport: true, EnableSwaggerSupport: true, + EnableIndex: true, APIPrefix: s.APIPrefix, CorsAllowedOriginList: s.CorsAllowedOriginList, ReadOnlyPort: s.ReadOnlyPort, diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index 2696f86ea95..1d847bc9419 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -103,6 +103,7 @@ func RunApiServer(cl *client.Client, etcdClient tools.EtcdClient, addr string, p }, EnableLogsSupport: false, EnableSwaggerSupport: true, + EnableIndex: true, APIPrefix: "/api", Authorizer: apiserver.NewAlwaysAllowAuthorizer(), diff --git a/test/integration/auth_test.go b/test/integration/auth_test.go index a2ca1471291..d09e7e8be2d 100644 --- a/test/integration/auth_test.go +++ b/test/integration/auth_test.go @@ -302,6 +302,7 @@ func TestAuthModeAlwaysAllow(t *testing.T) { KubeletClient: client.FakeKubeletClient{}, EnableLogsSupport: false, EnableUISupport: false, + EnableIndex: true, APIPrefix: "/api", Authorizer: apiserver.NewAlwaysAllowAuthorizer(), AdmissionControl: admit.NewAlwaysAdmit(), @@ -353,6 +354,7 @@ func TestAuthModeAlwaysDeny(t *testing.T) { KubeletClient: client.FakeKubeletClient{}, EnableLogsSupport: false, EnableUISupport: false, + EnableIndex: true, APIPrefix: "/api", Authorizer: apiserver.NewAlwaysDenyAuthorizer(), AdmissionControl: admit.NewAlwaysAdmit(), @@ -418,6 +420,7 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) { KubeletClient: client.FakeKubeletClient{}, EnableLogsSupport: false, EnableUISupport: false, + EnableIndex: true, APIPrefix: "/api", Authenticator: getTestTokenAuth(), Authorizer: allowAliceAuthorizer{}, @@ -478,6 +481,7 @@ func TestBobIsForbidden(t *testing.T) { KubeletClient: client.FakeKubeletClient{}, EnableLogsSupport: false, EnableUISupport: false, + EnableIndex: true, APIPrefix: "/api", Authenticator: getTestTokenAuth(), Authorizer: allowAliceAuthorizer{}, @@ -538,6 +542,7 @@ func TestUnknownUserIsUnauthorized(t *testing.T) { KubeletClient: client.FakeKubeletClient{}, EnableLogsSupport: false, EnableUISupport: false, + EnableIndex: true, APIPrefix: "/api", Authenticator: getTestTokenAuth(), Authorizer: allowAliceAuthorizer{}, @@ -617,6 +622,7 @@ func TestNamespaceAuthorization(t *testing.T) { KubeletClient: client.FakeKubeletClient{}, EnableLogsSupport: false, EnableUISupport: false, + EnableIndex: true, APIPrefix: "/api", Authenticator: getTestTokenAuth(), Authorizer: a, @@ -701,6 +707,7 @@ func TestKindAuthorization(t *testing.T) { KubeletClient: client.FakeKubeletClient{}, EnableLogsSupport: false, EnableUISupport: false, + EnableIndex: true, APIPrefix: "/api", Authenticator: getTestTokenAuth(), Authorizer: a, @@ -779,6 +786,7 @@ func TestReadOnlyAuthorization(t *testing.T) { KubeletClient: client.FakeKubeletClient{}, EnableLogsSupport: false, EnableUISupport: false, + EnableIndex: true, APIPrefix: "/api", Authenticator: getTestTokenAuth(), Authorizer: a,