From b5e4209ebc8ae99a1232d4ea10757236c9ec6c74 Mon Sep 17 00:00:00 2001 From: Tasko Olevski Date: Fri, 24 Mar 2023 00:01:18 +0100 Subject: [PATCH] feat(app): show git urls and registry domains --- cmd/revproxy/config.go | 13 ++++++------ cmd/revproxy/main.go | 6 ++++++ cmd/revproxy/main_test.go | 20 +++++++++++++++---- .../templates/deployment-revproxy.yaml | 2 ++ helm-chart/renku-gateway/values.yaml | 2 ++ 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cmd/revproxy/config.go b/cmd/revproxy/config.go index 0964f1b3..3147bf71 100644 --- a/cmd/revproxy/config.go +++ b/cmd/revproxy/config.go @@ -26,12 +26,13 @@ type metricsConfig struct { } type revProxyConfig struct { - RenkuBaseURL *url.URL `mapstructure:"renku_base_url"` - AllowOrigin []string `mapstructure:"allow_origin"` - ExternalGitlabURL *url.URL `mapstructure:"external_gitlab_url"` - RenkuServices renkuServicesConfig `mapstructure:",squash"` - Metrics metricsConfig `mapstructure:",squash"` - Port int + RenkuBaseURL *url.URL `mapstructure:"renku_base_url"` + AllowOrigin []string `mapstructure:"allow_origin"` + ExternalGitlabURL *url.URL `mapstructure:"external_gitlab_url"` + DefaultImageRegistryHost string `mapstructure:"default_image_registry_host"` + RenkuServices renkuServicesConfig `mapstructure:",squash"` + Metrics metricsConfig `mapstructure:",squash"` + Port int } func parseStringAsURL() mapstructure.DecodeHookFuncType { diff --git a/cmd/revproxy/main.go b/cmd/revproxy/main.go index 452c31ce..b7e69da3 100644 --- a/cmd/revproxy/main.go +++ b/cmd/revproxy/main.go @@ -78,6 +78,12 @@ func setupServer(config revProxyConfig) *echo.Echo { return c.JSON(http.StatusOK, map[string]string{"status": "ok"}) }) + // Config endpoints + configAPI := e.Group("/api/config") + configAPI.GET("/imageRegistries", func(c echo.Context) error { + return c.JSON(http.StatusOK, map[string]string{"default": config.DefaultImageRegistryHost}) + }) + return e } diff --git a/cmd/revproxy/main_test.go b/cmd/revproxy/main_test.go index 196f8fcd..7bb4a4f3 100644 --- a/cmd/revproxy/main_test.go +++ b/cmd/revproxy/main_test.go @@ -61,10 +61,11 @@ func setupTestAuthServer(ID string, responseHeaders map[string]string, responseS return srv, url } -func setupTestRevproxy(upstreamServerURL *url.URL, authURL *url.URL, externalGitlabURL *url.URL) (*echo.Echo, *url.URL) { +func setupTestRevproxy(upstreamServerURL *url.URL, authURL *url.URL, externalGitlabURL *url.URL, defaultImageRegsitryHost string) (*echo.Echo, *url.URL) { config := revProxyConfig{ RenkuBaseURL: upstreamServerURL, ExternalGitlabURL: externalGitlabURL, + DefaultImageRegistryHost: defaultImageRegsitryHost, Port: 8080, RenkuServices: renkuServicesConfig{ Notebooks: upstreamServerURL, @@ -124,7 +125,8 @@ func ParametrizedRouteTest(scenario TestCase) func(*testing.T) { gitlab, gitlabURL = setupTestUpstream("gitlab", requestTracker) defer gitlab.Close() } - proxy, proxyURL := setupTestRevproxy(upstreamURL, authURL, gitlabURL) + imageRegistryHost := "registry.dev.renku.ch" + proxy, proxyURL := setupTestRevproxy(upstreamURL, authURL, gitlabURL, imageRegistryHost) defer upstream.Close() defer proxy.Close() defer auth.Close() @@ -155,10 +157,10 @@ func ParametrizedRouteTest(scenario TestCase) func(*testing.T) { for hdrKey, hdrValue := range scenario.Expected.ResponseHeaders { assert.Equal(t, hdrValue, res.Header.Get(hdrKey)) } - if scenario.Expected.Path != "" { + if scenario.Expected.Path != "" && len(reqs) > 0 { assert.Equal(t, scenario.Expected.Path, reqs[len(reqs)-1].URL.EscapedPath()) } - if len(scenario.QueryParams) > 0 { + if len(scenario.QueryParams) > 0 && len(reqs) > 0 { assert.Equal(t, reqURLQuery.Encode(), reqs[len(reqs)-1].URL.RawQuery) } } @@ -334,6 +336,16 @@ func TestInternalSvcRoutes(t *testing.T) { ExternalGitlab: false, Expected: TestResults{Path: "/gitlab/api/v4/projects/some.username%2Ftest-project", VisitedServerIDs: []string{"auth", "upstream"}}, }, + { + Path: "/api/config/gitRepositories", + ExternalGitlab: false, + Expected: TestResults{Path: "/api/config/gitRepositories"}, + }, + { + Path: "/api/config/gitRepositories", + ExternalGitlab: false, + Expected: TestResults{Path: "/api/config/gitRepositories"}, + }, } for _, testCase := range testCases { // Test names show up poorly in vscode if the name contains "/" diff --git a/helm-chart/renku-gateway/templates/deployment-revproxy.yaml b/helm-chart/renku-gateway/templates/deployment-revproxy.yaml index 75866fab..de14ff2a 100644 --- a/helm-chart/renku-gateway/templates/deployment-revproxy.yaml +++ b/helm-chart/renku-gateway/templates/deployment-revproxy.yaml @@ -59,6 +59,8 @@ spec: value: {{ .Values.core.hostname | default (printf "http://%s-core" .Release.Name ) | quote }} - name: REVPROXY_RENKU_SERVICES_AUTH value: {{ printf "http://%s-gateway-auth" .Release.Name }} + - name: REVPROXY_DEFAULT_IMAGE_REGISTRY_HOST + value: {{ .Values.global.gitlab.registryDomain | quote }} - name: REVPROXY_PORT value: "8080" - name: REVPROXY_METRICS_ENABLED diff --git a/helm-chart/renku-gateway/values.yaml b/helm-chart/renku-gateway/values.yaml index 0db42cf7..0951ba7c 100644 --- a/helm-chart/renku-gateway/values.yaml +++ b/helm-chart/renku-gateway/values.yaml @@ -21,6 +21,8 @@ global: ## Must contain a leading slash, use "/" for root path. gitlab: urlPrefix: /gitlab + ## The domain of the gitlab image registry (i.e. registry.dev.renku.ch) + registryDomain: gateway: ## Client secret of the renku client application registered in keycloak. ## Should be set to a proper value (i.e. by using openssl rand -hex 32) for production.