diff --git a/pkg/server/handler/apiserver.go b/pkg/server/handler/apiserver.go index aaf1a65..ca830da 100644 --- a/pkg/server/handler/apiserver.go +++ b/pkg/server/handler/apiserver.go @@ -48,9 +48,9 @@ func New(cfg *rest.Config, sf schema.Factory, authMiddleware auth.Middleware, ne APIRoot: w(a.apiHandler(apiRoot)), } if routerFunc == nil { - return a.server, router.Routes(handlers), nil + return a.server, rewriteLocalCluster(router.Routes(handlers)), nil } - return a.server, routerFunc(handlers), nil + return a.server, rewriteLocalCluster(routerFunc(handlers)), nil } type apiServer struct { diff --git a/pkg/server/handler/handlers.go b/pkg/server/handler/handlers.go index 0b4fa3e..cc46b02 100644 --- a/pkg/server/handler/handlers.go +++ b/pkg/server/handler/handlers.go @@ -1,6 +1,9 @@ package handler import ( + "net/http" + "strings" + "github.com/gorilla/mux" "github.com/rancher/apiserver/pkg/types" "github.com/rancher/steve/pkg/attributes" @@ -35,3 +38,15 @@ func k8sAPI(sf schema.Factory, apiOp *types.APIRequest) { func apiRoot(sf schema.Factory, apiOp *types.APIRequest) { apiOp.Type = "apiRoot" } + +func rewriteLocalCluster(next http.Handler) http.Handler { + return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + if strings.HasPrefix(req.URL.Path, "/k8s/clusters/local") { + req.URL.Path = strings.TrimPrefix(req.URL.Path, "/k8s/clusters/local") + if req.URL.Path == "" { + req.URL.Path = "/" + } + } + next.ServeHTTP(rw, req) + }) +}