Skip to content

Commit d35c919

Browse files
authored
[apiserversdk] use config.Middleware at most once (ray-project#3522)
Signed-off-by: Rueian <rueiancsie@gmail.com>
1 parent 5b76625 commit d35c919

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

apiserversdk/proxy.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ func NewMux(config MuxConfig) (*http.ServeMux, error) {
2222
if proxy.Transport, err = rest.TransportFor(config.KubernetesConfig); err != nil { // rest.TransportFor provides the auth to the K8s API server.
2323
return nil, err
2424
}
25-
if config.Middleware == nil {
26-
config.Middleware = func(handler http.Handler) http.Handler { return handler }
25+
var handler http.Handler = proxy
26+
if config.Middleware != nil {
27+
handler = config.Middleware(proxy)
2728
}
2829
mux := http.NewServeMux()
2930
// TODO: add template features to specify routes.
30-
mux.Handle("/apis/ray.io/v1/", config.Middleware(proxy)) // forward KubeRay CR requests.
31+
mux.Handle("/apis/ray.io/v1/", handler) // forward KubeRay CR requests.
3132
// TODO: add query filters to make sure only KubeRay events are queried.
32-
mux.Handle("/api/v1/namespaces/{namespace}/events", config.Middleware(proxy)) // allow querying KubeRay CR events.
33+
mux.Handle("/api/v1/namespaces/{namespace}/events", handler) // allow querying KubeRay CR events.
3334
// TODO: check whether the service belongs to KubeRay first.
34-
mux.Handle("/api/v1/namespaces/{namespace}/services/{service}/proxy", config.Middleware(proxy)) // allow accessing KubeRay dashboards and job submissions.
35+
mux.Handle("/api/v1/namespaces/{namespace}/services/{service}/proxy", handler) // allow accessing KubeRay dashboards and job submissions.
3536
return mux, nil
3637
}

0 commit comments

Comments
 (0)