Skip to content

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

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 6 commits into from
May 27, 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
3 changes: 2 additions & 1 deletion .werft/jobs/build/deploy-to-preview-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ async function deployToDevWithInstaller(werft: Werft, jobConfig: JobConfig, depl
installer.postProcessing(installerSlices.INSTALLER_POST_PROCESSING)
installer.install(installerSlices.APPLY_INSTALL_MANIFESTS)
} catch (err) {
werft.fail(phases.DEPLOY, err)
exec(`cat ${installer.options.installerConfigPath}`, { slice: phases.DEPLOY });
werft.fail(phases.DEPLOY, err);
}

werft.log(installerSlices.DEPLOYMENT_WAITING, "Waiting until all pods are ready.");
Expand Down
9 changes: 9 additions & 0 deletions .werft/jobs/build/installer/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Installer {
this.options.werft.log(slice, "Adding extra configuration");
try {
this.getDevCustomValues(slice)
this.configureMetadata(slice)
this.configureContainerRegistry(slice)
this.configureDomain(slice)
this.configureWorkspaces(slice)
Expand Down Expand Up @@ -94,6 +95,14 @@ export class Installer {
exec(`yq m -i ${this.options.installerConfigPath} ${WORKSPACE_SIZE_CONFIG_PATH}`, { slice: slice });
}

private configureMetadata(slice: string): void {
exec(`cat <<EOF > shortname.yaml
metadata:
shortname: ""
EOF`)
exec(`yq m -ix ${this.options.installerConfigPath} shortname.yaml`, { slice: slice });
}

private configureContainerRegistry(slice: string): void {
exec(`yq w -i ${this.options.installerConfigPath} certificate.name ${this.options.proxySecretName}`, { slice: slice });
exec(`yq w -i ${this.options.installerConfigPath} containerRegistry.inCluster false`, { slice: slice });
Expand Down
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 != "" && ctx.Config.Metadata.InstallationShortname != configv1.InstallationShortNameOldDefault {
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
66 changes: 66 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,65 @@ 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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

},
{
Name: "Without an installation shortname",
Domain: "example.com",
InstallationShortname: "",
ExpectedWorkspaceUrlTemplate: "https://{{ .Prefix }}.ws.example.com",
ExpectedWorkspacePortURLTemplate: "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws.example.com",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrew-farries We need a test case "with 'default' as installation shortname" to cover all existing self-hosted installations out there I think. That will lead us to the comment above I think.

},
{
Name: "With old default installation shortname for existing self-hosted installations",
Domain: "example.com",
InstallationShortname: configv1.InstallationShortNameOldDefault,
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)
})
}
}
8 changes: 6 additions & 2 deletions install/installer/pkg/config/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (v version) Defaults(in interface{}) error {
cfg.Certificate.Name = "https-certificates"
cfg.Database.InCluster = pointer.Bool(true)
cfg.Metadata.Region = "local"
cfg.Metadata.InstallationShortname = "default" // TODO(gpl): we're tied to "default" here because that's what we put into static bridges in the past
cfg.Metadata.InstallationShortname = InstallationShortNameOldDefault // TODO(gpl): we're tied to "default" here because that's what we put into static bridges in the past
cfg.ObjectStorage.InCluster = pointer.Bool(true)
cfg.ObjectStorage.Resources = &Resources{
Requests: corev1.ResourceList{
Expand Down Expand Up @@ -117,9 +117,13 @@ type Metadata struct {
// Location for your objectStorage provider
Region string `json:"region" validate:"required"`
// InstallationShortname establishes the "identity" of the (application) cluster.
InstallationShortname string `json:"shortname" validate:"required"`
InstallationShortname string `json:"shortname"`
}

const (
InstallationShortNameOldDefault string = "default"
)

type Observability struct {
LogLevel LogLevel `json:"logLevel" validate:"required,log_level"`
Tracing *Tracing `json:"tracing,omitempty"`
Expand Down