func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInfoGetter) { podCache := NewPodCache(podInfoGetter, m.podRegistry) go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*30) endpoints := servicecontroller.NewEndpointController(m.serviceRegistry, m.client) go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10) m.storage = map[string]apiserver.RESTStorage{ "pods": pod.NewREST(&pod.RESTConfig{ CloudProvider: cloud, PodCache: podCache, PodInfoGetter: podInfoGetter, Registry: m.podRegistry, }), "replicationControllers": controller.NewREST(m.controllerRegistry, m.podRegistry), "services": service.NewREST(m.serviceRegistry, cloud, m.minionRegistry), "endpoints": endpoint.NewREST(m.endpointRegistry), "minions": minion.NewREST(m.minionRegistry), // TODO: should appear only in scheduler API group. "bindings": binding.NewREST(m.bindingRegistry), } }
// init initializes master. func (m *Master) init(c *Config) { podCache := NewPodCache(c.KubeletClient, m.podRegistry) go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*30) var userContexts = handlers.NewUserRequestContext() var authenticator authenticator.Request if len(c.TokenAuthFile) != 0 { tokenAuthenticator, err := tokenfile.New(c.TokenAuthFile) if err != nil { glog.Fatalf("Unable to load the token authentication file '%s': %v", c.TokenAuthFile, err) } authenticator = bearertoken.New(tokenAuthenticator) } m.storage = map[string]apiserver.RESTStorage{ "pods": pod.NewREST(&pod.RESTConfig{ CloudProvider: c.Cloud, PodCache: podCache, PodInfoGetter: c.KubeletClient, Registry: m.podRegistry, Minions: m.client.Minions(), }), "replicationControllers": controller.NewREST(m.controllerRegistry, m.podRegistry), "services": service.NewREST(m.serviceRegistry, c.Cloud, m.minionRegistry, m.portalNet), "endpoints": endpoint.NewREST(m.endpointRegistry), "minions": minion.NewREST(m.minionRegistry), "events": event.NewREST(m.eventRegistry), // TODO: should appear only in scheduler API group. "bindings": binding.NewREST(m.bindingRegistry), } apiserver.NewAPIGroup(m.API_v1beta1()).InstallREST(m.mux, c.APIPrefix+"/v1beta1") apiserver.NewAPIGroup(m.API_v1beta2()).InstallREST(m.mux, c.APIPrefix+"/v1beta2") versionHandler := apiserver.APIVersionHandler("v1beta1", "v1beta2") m.mux.Handle(c.APIPrefix, versionHandler) apiserver.InstallSupport(m.mux) serversToValidate := m.getServersToValidate(c) apiserver.InstallValidator(m.mux, serversToValidate) if c.EnableLogsSupport { apiserver.InstallLogsSupport(m.mux) } if c.EnableUISupport { ui.InstallSupport(m.mux) } handler := http.Handler(m.mux.(*http.ServeMux)) if len(c.CorsAllowedOriginList) > 0 { allowedOriginRegexps, err := util.CompileRegexps(c.CorsAllowedOriginList) if err != nil { glog.Fatalf("Invalid CORS allowed origin, --cors_allowed_origins flag was set to %v - %v", strings.Join(c.CorsAllowedOriginList, ","), err) } handler = apiserver.CORS(handler, allowedOriginRegexps, nil, nil, "true") } m.InsecureHandler = handler attributeGetter := apiserver.NewRequestAttributeGetter(userContexts) handler = apiserver.WithAuthorizationCheck(handler, attributeGetter, m.authorizer) // Install Authenticator if authenticator != nil { handler = handlers.NewRequestAuthenticator(userContexts, authenticator, handlers.Unauthorized, handler) } m.mux.HandleFunc("/_whoami", handleWhoAmI(authenticator)) m.Handler = handler // TODO: Attempt clean shutdown? m.masterServices.Start() }
// init initializes master. func (m *Master) init(c *Config) { var userContexts = handlers.NewUserRequestContext() var authenticator = c.Authenticator nodeRESTStorage := minion.NewREST(m.minionRegistry) podCache := NewPodCache( m.nodeIPCache, c.KubeletClient, RESTStorageToNodes(nodeRESTStorage).Nodes(), m.podRegistry, ) go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*30) // TODO: Factor out the core API registration m.storage = map[string]apiserver.RESTStorage{ "pods": pod.NewREST(&pod.RESTConfig{ PodCache: podCache, Registry: m.podRegistry, }), "replicationControllers": controller.NewREST(m.controllerRegistry, m.podRegistry), "services": service.NewREST(m.serviceRegistry, c.Cloud, m.minionRegistry, m.portalNet), "endpoints": endpoint.NewREST(m.endpointRegistry), "minions": nodeRESTStorage, "nodes": nodeRESTStorage, "events": event.NewREST(m.eventRegistry), // TODO: should appear only in scheduler API group. "bindings": binding.NewREST(m.bindingRegistry), } apiVersions := []string{"v1beta1", "v1beta2"} if err := apiserver.NewAPIGroupVersion(m.api_v1beta1()).InstallREST(m.handlerContainer, c.APIPrefix, "v1beta1"); err != nil { glog.Fatalf("Unable to setup API v1beta1: %v", err) } if err := apiserver.NewAPIGroupVersion(m.api_v1beta2()).InstallREST(m.handlerContainer, c.APIPrefix, "v1beta2"); err != nil { glog.Fatalf("Unable to setup API v1beta2: %v", err) } if c.EnableV1Beta3 { if err := apiserver.NewAPIGroupVersion(m.api_v1beta3()).InstallREST(m.handlerContainer, c.APIPrefix, "v1beta3"); err != nil { glog.Fatalf("Unable to setup API v1beta3: %v", err) } apiVersions = []string{"v1beta1", "v1beta2", "v1beta3"} } apiserver.InstallSupport(m.handlerContainer, m.rootWebService) apiserver.AddApiWebService(m.handlerContainer, c.APIPrefix, apiVersions) // 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.HandleIndex) // TODO: use go-restful apiserver.InstallValidator(m.mux, func() map[string]apiserver.Server { return m.getServersToValidate(c) }) if c.EnableLogsSupport { apiserver.InstallLogsSupport(m.mux) } if c.EnableUISupport { ui.InstallSupport(m.mux, m.enableSwaggerSupport) } // TODO: install runtime/pprof handler // See github.com/emicklei/go-restful/blob/master/examples/restful-cpuprofiler-service.go handler := http.Handler(m.mux.(*http.ServeMux)) // TODO: handle CORS and auth using go-restful // See github.com/emicklei/go-restful/blob/master/examples/restful-CORS-filter.go, and // github.com/emicklei/go-restful/blob/master/examples/restful-basic-authentication.go if len(c.CorsAllowedOriginList) > 0 { allowedOriginRegexps, err := util.CompileRegexps(c.CorsAllowedOriginList) if err != nil { glog.Fatalf("Invalid CORS allowed origin, --cors_allowed_origins flag was set to %v - %v", strings.Join(c.CorsAllowedOriginList, ","), err) } handler = apiserver.CORS(handler, allowedOriginRegexps, nil, nil, "true") } m.InsecureHandler = handler attributeGetter := apiserver.NewRequestAttributeGetter(userContexts) handler = apiserver.WithAuthorizationCheck(handler, attributeGetter, m.authorizer) // Install Authenticator if authenticator != nil { handler = handlers.NewRequestAuthenticator(userContexts, authenticator, handlers.Unauthorized, handler) } // Install root web services m.handlerContainer.Add(m.rootWebService) // TODO: Make this optional? Consumers of master depend on this currently. m.Handler = handler if m.enableSwaggerSupport { m.InstallSwaggerAPI() } // TODO: Attempt clean shutdown? m.masterServices.Start() }
// init initializes master. func (m *Master) init(c *Config) { var userContexts = handlers.NewUserRequestContext() var authenticator = c.Authenticator ipCache := NewIPCache(c.Cloud, util.RealClock{}, 30*time.Second) podCache := NewPodCache( ipCache, c.KubeletClient, m.client.Minions(), m.podRegistry, ) go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*30) // TODO: Factor out the core API registration m.storage = map[string]apiserver.RESTStorage{ "pods": pod.NewREST(&pod.RESTConfig{ PodCache: podCache, Registry: m.podRegistry, }), "replicationControllers": controller.NewREST(m.controllerRegistry, m.podRegistry), "services": service.NewREST(m.serviceRegistry, c.Cloud, m.minionRegistry, m.portalNet), "endpoints": endpoint.NewREST(m.endpointRegistry), "minions": minion.NewREST(m.minionRegistry), "events": event.NewREST(m.eventRegistry), // TODO: should appear only in scheduler API group. "bindings": binding.NewREST(m.bindingRegistry), } apiserver.NewAPIGroupVersion(m.API_v1beta1()).InstallREST(m.handlerContainer, c.APIPrefix, "v1beta1") apiserver.NewAPIGroupVersion(m.API_v1beta2()).InstallREST(m.handlerContainer, c.APIPrefix, "v1beta2") // TODO: InstallREST should register each version automatically versionHandler := apiserver.APIVersionHandler("v1beta1", "v1beta2") m.rootWebService.Route(m.rootWebService.GET(c.APIPrefix).To(versionHandler)) apiserver.InstallSupport(m.handlerContainer, m.rootWebService) // TODO: use go-restful serversToValidate := m.getServersToValidate(c) apiserver.InstallValidator(m.mux, serversToValidate) if c.EnableLogsSupport { apiserver.InstallLogsSupport(m.mux) } if c.EnableUISupport { ui.InstallSupport(m.mux) } // TODO: install runtime/pprof handler // See github.com/emicklei/go-restful/blob/master/examples/restful-cpuprofiler-service.go handler := http.Handler(m.mux.(*http.ServeMux)) // TODO: handle CORS and auth using go-restful // See github.com/emicklei/go-restful/blob/master/examples/restful-CORS-filter.go, and // github.com/emicklei/go-restful/blob/master/examples/restful-basic-authentication.go if len(c.CorsAllowedOriginList) > 0 { allowedOriginRegexps, err := util.CompileRegexps(c.CorsAllowedOriginList) if err != nil { glog.Fatalf("Invalid CORS allowed origin, --cors_allowed_origins flag was set to %v - %v", strings.Join(c.CorsAllowedOriginList, ","), err) } handler = apiserver.CORS(handler, allowedOriginRegexps, nil, nil, "true") } m.InsecureHandler = handler attributeGetter := apiserver.NewRequestAttributeGetter(userContexts) handler = apiserver.WithAuthorizationCheck(handler, attributeGetter, m.authorizer) // Install Authenticator if authenticator != nil { handler = handlers.NewRequestAuthenticator(userContexts, authenticator, handlers.Unauthorized, handler) } // TODO: Remove temporary _whoami handler m.rootWebService.Route(m.rootWebService.GET("/_whoami").To(handleWhoAmI(authenticator))) // Install root web services m.handlerContainer.Add(m.rootWebService) // TODO: Make this optional? // Enable swagger UI and discovery API swaggerConfig := swagger.Config{ WebServices: m.handlerContainer.RegisteredWebServices(), // TODO: Parameterize the path? ApiPath: "/swaggerapi/", // TODO: Distribute UI javascript and enable the UI //SwaggerPath: "/swaggerui/", //SwaggerFilePath: "/srv/apiserver/swagger/dist" } swagger.RegisterSwaggerService(swaggerConfig, m.handlerContainer) m.Handler = handler // TODO: Attempt clean shutdown? m.masterServices.Start() }