From 5a4f78f5ee6a67e2d06a11afddd9f5e633bef7c2 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Thu, 19 May 2022 11:37:03 +0000 Subject: [PATCH 1/2] Append installation shortname to url templates This matches how these URLs were constructed in the old helm chart: https://github.com/gitpod-io/gitpod/blob/2f988c93499926bd34d6728defbd9d9c0964797e/chart/templates/ws-manager-configmap.yaml#L74-L75 --- install/installer/pkg/components/ws-manager/configmap.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/install/installer/pkg/components/ws-manager/configmap.go b/install/installer/pkg/components/ws-manager/configmap.go index 252711ce2fe076..129698b3370f1f 100644 --- a/install/installer/pkg/components/ws-manager/configmap.go +++ b/install/installer/pkg/components/ws-manager/configmap.go @@ -113,6 +113,11 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { return nil, err } + installationShortNameSuffix := "" + if ctx.Config.Metadata.InstallationShortname != "" { + installationShortNameSuffix = "-" + ctx.Config.Metadata.InstallationShortname + } + wsmcfg := config.ServiceConfiguration{ Manager: config.Configuration{ Namespace: ctx.Namespace, @@ -137,8 +142,8 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { InitProbe: config.InitProbeConfiguration{ Timeout: (1 * time.Second).String(), }, - WorkspaceURLTemplate: fmt.Sprintf("https://{{ .Prefix }}.ws.%s", ctx.Config.Domain), - WorkspacePortURLTemplate: fmt.Sprintf("https://{{ .WorkspacePort }}-{{ .Prefix }}.ws.%s", ctx.Config.Domain), + WorkspaceURLTemplate: fmt.Sprintf("https://{{ .Prefix }}.ws%s.%s", installationShortNameSuffix, ctx.Config.Domain), + WorkspacePortURLTemplate: fmt.Sprintf("https://{{ .WorkspacePort }}-{{ .Prefix }}.ws%s.%s", installationShortNameSuffix, ctx.Config.Domain), WorkspaceHostPath: wsdaemon.HostWorkingArea, Timeouts: config.WorkspaceTimeoutConfiguration{ AfterClose: timeoutAfterClose, From 0f8e528f7b38c6cdf9d3a3e14045adcfb1acd6dd Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Thu, 19 May 2022 11:57:18 +0000 Subject: [PATCH 2/2] Add test for workspace URL templates --- .../components/ws-manager/configmap_test.go | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/install/installer/pkg/components/ws-manager/configmap_test.go b/install/installer/pkg/components/ws-manager/configmap_test.go index eb0c6e59599ba5..b9ab0e7adddf15 100644 --- a/install/installer/pkg/components/ws-manager/configmap_test.go +++ b/install/installer/pkg/components/ws-manager/configmap_test.go @@ -5,12 +5,16 @@ package wsmanager import ( + "encoding/json" "testing" "github.com/gitpod-io/gitpod/installer/pkg/common" + "github.com/gitpod-io/gitpod/installer/pkg/config/v1" configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1" + "github.com/gitpod-io/gitpod/installer/pkg/config/versions" wsmancfg "github.com/gitpod-io/gitpod/ws-manager/api/config" "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" @@ -133,3 +137,58 @@ func TestBuildWorkspaceTemplates(t *testing.T) { }) } } + +func TestWorkspaceURLTemplates(t *testing.T) { + tests := []struct { + Name string + Domain string + InstallationShortname string + ExpectedWorkspaceUrlTemplate string + ExpectedWorkspacePortURLTemplate string + }{ + { + Name: "With an installation shortname", + Domain: "example.com", + InstallationShortname: "eu02", + ExpectedWorkspaceUrlTemplate: "https://{{ .Prefix }}.ws-eu02.example.com", + ExpectedWorkspacePortURLTemplate: "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws-eu02.example.com", + }, + { + Name: "Without an installation shortname", + Domain: "example.com", + InstallationShortname: "", + ExpectedWorkspaceUrlTemplate: "https://{{ .Prefix }}.ws.example.com", + ExpectedWorkspacePortURLTemplate: "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws.example.com", + }, + } + + for _, test := range tests { + t.Run(test.Name, func(t *testing.T) { + ctx, err := common.NewRenderContext(config.Config{ + Domain: test.Domain, + Metadata: configv1.Metadata{ + InstallationShortname: test.InstallationShortname, + }, + ObjectStorage: configv1.ObjectStorage{ + InCluster: pointer.Bool(true), + }, + }, versions.Manifest{}, "test_namespace") + require.NoError(t, err) + + objs, err := configmap(ctx) + require.NoError(t, err) + + cfgmap, ok := objs[0].(*corev1.ConfigMap) + require.Truef(t, ok, "configmap function did not return a configmap") + + configJson, ok := cfgmap.Data["config.json"] + require.Truef(t, ok, "configmap data did not contain %q key", "config.json") + + serviceConfig := wsmancfg.ServiceConfiguration{} + json.Unmarshal([]byte(configJson), &serviceConfig) + + require.Equal(t, test.ExpectedWorkspaceUrlTemplate, serviceConfig.Manager.WorkspaceURLTemplate) + require.Equal(t, test.ExpectedWorkspacePortURLTemplate, serviceConfig.Manager.WorkspacePortURLTemplate) + }) + } +}