diff --git a/pkg/controller/api.go b/pkg/controller/api.go index 1ccf7407..051b8043 100644 --- a/pkg/controller/api.go +++ b/pkg/controller/api.go @@ -191,7 +191,7 @@ func (api *API) GetSvcName(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, service.Name+"."+podNamespace) } -func (api *API) Serve(port int) { +func (api *API) GetHandler() http.Handler { r := mux.NewRouter() r.HandleFunc("/healthz", api.HealthHandler).Methods("GET") // Give a useful error message if an older CLI attempts to make a request @@ -270,9 +270,12 @@ func (api *API) Serve(port int) { r.Handle("/v2/apidocs.json", openAPI()).Methods("GET") - address := fmt.Sprintf(":%v", port) + return r +} +func (api *API) Serve(port int) { + address := fmt.Sprintf(":%v", port) api.logger.Info("server started", zap.Int("port", port)) - err := http.ListenAndServe(address, r) + err := http.ListenAndServe(address, api.GetHandler()) api.logger.Fatal("done listening", zap.Error(err)) } diff --git a/pkg/executor/api.go b/pkg/executor/api.go index 517cb949..a2d0f488 100644 --- a/pkg/executor/api.go +++ b/pkg/executor/api.go @@ -130,24 +130,27 @@ func (executor *Executor) healthHandler(w http.ResponseWriter, r *http.Request) w.WriteHeader(http.StatusOK) } +func (executor *Executor) GetHandler() http.Handler { + r := mux.NewRouter() + r.HandleFunc("/v2/getServiceForFunction", executor.getServiceForFunctionApi).Methods("POST") + r.HandleFunc("/v2/tapService", executor.tapService).Methods("POST") + r.HandleFunc("/healthz", executor.healthHandler).Methods("GET") + return r +} + func (executor *Executor) Serve(port int) { executor.logger.Info("starting executor", zap.Int("port", port)) ctx, cancel := context.WithCancel(context.Background()) defer cancel() + executor.ndm.Run(ctx) executor.gpm.Run(ctx) executor.cms.Run(ctx) - r := mux.NewRouter() - r.HandleFunc("/v2/getServiceForFunction", executor.getServiceForFunctionApi).Methods("POST") - r.HandleFunc("/v2/tapService", executor.tapService).Methods("POST") - r.HandleFunc("/healthz", executor.healthHandler).Methods("GET") - address := fmt.Sprintf(":%v", port) - err := http.ListenAndServe(address, &ochttp.Handler{ - Handler: r, + Handler: executor.GetHandler(), }) executor.logger.Fatal("done listening", zap.Error(err)) }