From d9160553f9bff18072b9e7b3f26f295fcdaa0c02 Mon Sep 17 00:00:00 2001 From: Todd Treece <360020+toddtreece@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:05:50 -0400 Subject: [PATCH] K8s: Remove /k8s/ prefix (#75959) --- pkg/services/grafana-apiserver/README.md | 2 +- pkg/services/grafana-apiserver/service.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/services/grafana-apiserver/README.md b/pkg/services/grafana-apiserver/README.md index 4a076d520b7..4c68a3a2ce6 100644 --- a/pkg/services/grafana-apiserver/README.md +++ b/pkg/services/grafana-apiserver/README.md @@ -40,4 +40,4 @@ kubectl api-resources ### Grafana API Access -The Kubernetes compatible API can be accessed using existing Grafana AuthN at: [http://localhost:3000/k8s/apis/](http://localhost:3000/k8s/apis/). +The Kubernetes compatible API can be accessed using existing Grafana AuthN at: [http://localhost:3000/apis](http://localhost:3000/apis). diff --git a/pkg/services/grafana-apiserver/service.go b/pkg/services/grafana-apiserver/service.go index a8409f6b65b..8935ed09e33 100644 --- a/pkg/services/grafana-apiserver/service.go +++ b/pkg/services/grafana-apiserver/service.go @@ -6,7 +6,6 @@ import ( "net" "path" "strconv" - "strings" "github.com/go-logr/logr" "github.com/grafana/dskit/services" @@ -126,7 +125,7 @@ func ProvideService( // TODO: this is very hacky // We need to register the routes in ProvideService to make sure // the routes are registered before the Grafana HTTP server starts. - s.rr.Group("/k8s", func(k8sRoute routing.RouteRegister) { + proxyHandler := func(k8sRoute routing.RouteRegister) { handler := func(c *contextmodel.ReqContext) { if s.handler == nil { c.Resp.WriteHeader(404) @@ -141,7 +140,10 @@ func ProvideService( } k8sRoute.Any("/", middleware.ReqSignedIn, handler) k8sRoute.Any("/*", middleware.ReqSignedIn, handler) - }) + } + + s.rr.Group("/apis", proxyHandler) + s.rr.Group("/openapi", proxyHandler) return s, nil } @@ -277,7 +279,6 @@ func (s *service) start(ctx context.Context) error { // TODO: this is a hack. see note in ProvideService s.handler = func(c *contextmodel.ReqContext) { req := c.Req - req.URL.Path = strings.TrimPrefix(req.URL.Path, "/k8s") if req.URL.Path == "" { req.URL.Path = "/" }