From 7a81518059ed38ba7a2fd6d878000fdebb4ee236 Mon Sep 17 00:00:00 2001 From: qiaozp <47812250+chivalryq@users.noreply.github.com> Date: Wed, 21 Jun 2023 09:57:11 +0800 Subject: [PATCH] Chore: remove acr image (#844) --- .github/workflows/release.yml | 7 ------- pkg/plugin/router/router.go | 14 ++++++++++---- pkg/plugin/router/router_test.go | 8 ++++---- pkg/plugin/types/plugin.go | 3 +++ pkg/server/server.go | 4 ++-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c716efdaf..00ee72cae 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,12 +30,6 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to Aliyun Container Registry (ACR) - uses: docker/login-action@v1 - with: - registry: acr.kubevela.net - username: "${{ secrets.ACR_USERNAME }}" - password: "${{ secrets.ACR_PASSWORD }}" - uses: docker/setup-qemu-action@v1 - uses: docker/setup-buildx-action@v1 with: @@ -53,5 +47,4 @@ jobs: VERSION=${{ steps.get_version.outputs.VERSION }} GOPROXY=https://proxy.golang.org tags: |- - acr.kubevela.net/oamdev/velaux:${{ steps.get_version.outputs.VERSION }} oamdev/velaux:${{ steps.get_version.outputs.VERSION }} diff --git a/pkg/plugin/router/router.go b/pkg/plugin/router/router.go index cd5be83d3..3fc46acce 100644 --- a/pkg/plugin/router/router.go +++ b/pkg/plugin/router/router.go @@ -48,11 +48,18 @@ func newDefaultRouter(h Handle, plugin *types.Plugin) *defaultRouter { return &defaultRouter{h: h, plugin: plugin} } -// GenerateHTTPRouter create and return the plugin backend router -func GenerateHTTPRouter(plugin *types.Plugin, pathPrefix string, h Handle) http.Handler { +// GetPluginHandler get the plugin backend router, if not exist, will create and cache it +func GetPluginHandler(plugin *types.Plugin, h Handle) http.Handler { if r, e := cachePluginRouter[plugin.PluginID()]; e { return r } + router := GeneratePluginHandler(plugin, h) + cachePluginRouter[plugin.PluginID()] = router + return router +} + +// GeneratePluginHandler create and return the plugin backend router +func GeneratePluginHandler(plugin *types.Plugin, h Handle) http.Handler { var router http.Handler if len(plugin.Routes) == 0 { klog.Warningf("plugin %s don't define the routes, will proxy all path requests and not check the permission.", plugin.PluginID()) @@ -60,7 +67,7 @@ func GenerateHTTPRouter(plugin *types.Plugin, pathPrefix string, h Handle) http. } else { r := httprouter.New() for _, route := range plugin.Routes { - routePath := path.Join(pathPrefix+"/:"+DefaultPluginResourceKey, route.Path) + routePath := path.Join(types.PluginProxyRoutePath+"/:"+DefaultPluginResourceKey, route.Path) method := route.Method if method == "" { method = "GET" @@ -72,6 +79,5 @@ func GenerateHTTPRouter(plugin *types.Plugin, pathPrefix string, h Handle) http. } router = r } - cachePluginRouter[plugin.PluginID()] = router return router } diff --git a/pkg/plugin/router/router_test.go b/pkg/plugin/router/router_test.go index dee71fce5..8ce5627b1 100644 --- a/pkg/plugin/router/router_test.go +++ b/pkg/plugin/router/router_test.go @@ -31,11 +31,11 @@ import ( func TestDefaultGenerateHTTPRouter(t *testing.T) { var res = &httptest.ResponseRecorder{} var req = &http.Request{Method: "GET", URL: &url.URL{Scheme: "http", Path: "/proxy/plugins/default-router/test", Host: "127.0.0.1"}} - defaultRouter := GenerateHTTPRouter(&types.Plugin{ + defaultRouter := GetPluginHandler(&types.Plugin{ JSONData: types.JSONData{ ID: "default-router", }, - }, "/proxy/plugins", func(w http.ResponseWriter, r1 *http.Request, p1 httprouter.Params, p2 *types.Plugin, r2 *types.Route) { + }, func(w http.ResponseWriter, r1 *http.Request, p1 httprouter.Params, p2 *types.Plugin, r2 *types.Route) { if r1.URL.Path == "/proxy/plugins/default-router/test" { w.WriteHeader(403) return @@ -50,7 +50,7 @@ func TestRouteGenerateHTTPRouter(t *testing.T) { var req = &http.Request{Method: "GET", URL: &url.URL{Scheme: "http", Path: "/proxy/plugins/route-router/nodes/t", Host: "127.0.0.1"}} var reqMethodNotAllow = &http.Request{Method: "PUT", URL: &url.URL{Scheme: "http", Path: "/proxy/plugins/route-router/nodes/t", Host: "127.0.0.1"}} var req404 = &http.Request{Method: "GET", URL: &url.URL{Scheme: "http", Path: "/proxy/plugins/route-router/nodes", Host: "127.0.0.1"}} - router := GenerateHTTPRouter(&types.Plugin{ + router := GetPluginHandler(&types.Plugin{ JSONData: types.JSONData{ ID: "route-router", Routes: []*types.Route{ @@ -64,7 +64,7 @@ func TestRouteGenerateHTTPRouter(t *testing.T) { }, }, }, - }, "/proxy/plugins", func(w http.ResponseWriter, r1 *http.Request, p1 httprouter.Params, p2 *types.Plugin, r2 *types.Route) { + }, func(w http.ResponseWriter, r1 *http.Request, p1 httprouter.Params, p2 *types.Plugin, r2 *types.Route) { assert.Equal(t, p1.ByName("node"), "t") assert.Equal(t, len(r2.ProxyHeaders), 1) assert.Equal(t, r2.ProxyHeaders[0].Name, "Authorization") diff --git a/pkg/plugin/types/plugin.go b/pkg/plugin/types/plugin.go index 8a346be06..5c79d07c3 100644 --- a/pkg/plugin/types/plugin.go +++ b/pkg/plugin/types/plugin.go @@ -20,6 +20,9 @@ import ( rbacv1 "k8s.io/api/rbac/v1" ) +// PluginProxyRoutePath the route prefix to request the plugin backend server. +const PluginProxyRoutePath = "/proxy/plugins/" + // Plugin VelaUX plugin model type Plugin struct { JSONData diff --git a/pkg/server/server.go b/pkg/server/server.go index f2f300b38..2b5ce45bc 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -73,7 +73,7 @@ const ( PluginPublicRoutePath = "/public/plugins/" // PluginProxyRoutePath the route prefix to request the plugin backend server. - PluginProxyRoutePath = "/proxy/plugins/" + PluginProxyRoutePath = plugintypes.PluginProxyRoutePath // DexRoutePath the route prefix to request the dex service DexRoutePath = "/dex" @@ -454,7 +454,7 @@ func (s *restServer) proxyPluginBackend(req *http.Request, res http.ResponseWrit return } // Register the plugin route - router.GenerateHTTPRouter(plugin, PluginProxyRoutePath, s.pluginBackendProxyHandler).ServeHTTP(res, req) + router.GetPluginHandler(plugin, s.pluginBackendProxyHandler).ServeHTTP(res, req) } func (s *restServer) pluginBackendProxyHandler(w http.ResponseWriter, r *http.Request, p httprouter.Params, plugin *plugintypes.Plugin, route *plugintypes.Route) {