Skip to content

[installer, ws-manager]: Use installation shortname in URL templates #10127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions install/installer/pkg/components/ws-manager/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
59 changes: 59 additions & 0 deletions install/installer/pkg/components/ws-manager/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
})
}
}