Skip to content

Commit 8fcec5e

Browse files
WVerlaekroboquat
authored andcommitted
[ws-manager-mk2] Fix workspace URL
1 parent eece193 commit 8fcec5e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

components/ws-manager-mk2/controllers/create.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ func createWorkspaceEnvironment(sctx *startWorkspaceContext) ([]corev1.EnvVar, e
565565
allRepoRoots[i] = getWorkspaceRelativePath(root)
566566
}
567567

568+
// Can't read the workspace URL from status yet, as the status likely hasn't
569+
// been set by the controller yet at this point. Therefore, manually construct
570+
// the URL to pass to the container env.
571+
wsUrl, err := config.RenderWorkspaceURL(sctx.Config.WorkspaceURLTemplate, sctx.Workspace.Name, sctx.Workspace.Spec.Ownership.WorkspaceID, sctx.Config.GitpodHostURL)
572+
if err != nil {
573+
return nil, fmt.Errorf("cannot render workspace URL: %w", err)
574+
}
575+
568576
// Envs that start with GITPOD_ are appended to the Terminal environments
569577
result := []corev1.EnvVar{}
570578
result = append(result, corev1.EnvVar{Name: "GITPOD_REPO_ROOT", Value: allRepoRoots[0]})
@@ -575,7 +583,7 @@ func createWorkspaceEnvironment(sctx *startWorkspaceContext) ([]corev1.EnvVar, e
575583
result = append(result, corev1.EnvVar{Name: "GITPOD_THEIA_PORT", Value: strconv.Itoa(int(sctx.IDEPort))})
576584
result = append(result, corev1.EnvVar{Name: "THEIA_WORKSPACE_ROOT", Value: getWorkspaceRelativePath(sctx.Workspace.Spec.WorkspaceLocation)})
577585
result = append(result, corev1.EnvVar{Name: "GITPOD_HOST", Value: sctx.Config.GitpodHostURL})
578-
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_URL", Value: sctx.Workspace.Status.URL})
586+
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_URL", Value: wsUrl})
579587
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_CLUSTER_HOST", Value: sctx.Config.WorkspaceClusterHost})
580588
result = append(result, corev1.EnvVar{Name: "THEIA_SUPERVISOR_ENDPOINT", Value: fmt.Sprintf(":%d", sctx.SupervisorPort)})
581589
// TODO(ak) remove THEIA_WEBVIEW_EXTERNAL_ENDPOINT and THEIA_MINI_BROWSER_HOST_PATTERN when Theia is removed
@@ -703,6 +711,9 @@ func newStartWorkspaceContext(ctx context.Context, cfg *config.Configuration, ws
703711
span, _ := tracing.FromContext(ctx, "newStartWorkspaceContext")
704712
defer tracing.FinishSpan(span, &err)
705713

714+
// Can't read ws.Status yet at this point (to e.g. get the headless status),
715+
// as it very likely hasn't been set yet by the controller.
716+
isHeadless := ws.Spec.Type != workspacev1.WorkspaceTypeRegular
706717
return &startWorkspaceContext{
707718
Labels: map[string]string{
708719
"app": "gitpod",
@@ -711,13 +722,13 @@ func newStartWorkspaceContext(ctx context.Context, cfg *config.Configuration, ws
711722
wsk8s.OwnerLabel: ws.Spec.Ownership.Owner,
712723
wsk8s.TypeLabel: strings.ToLower(string(ws.Spec.Type)),
713724
instanceIDLabel: ws.Name,
714-
headlessLabel: strconv.FormatBool(ws.Status.Headless),
725+
headlessLabel: strconv.FormatBool(isHeadless),
715726
},
716727
Config: cfg,
717728
Workspace: ws,
718729
IDEPort: 23000,
719730
SupervisorPort: 22999,
720-
Headless: ws.Status.Headless,
731+
Headless: isHeadless,
721732
}, nil
722733
}
723734

components/ws-manager-mk2/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func main() {
8787
Port: 9443,
8888
HealthProbeBindAddress: cfg.Health.Addr,
8989
LeaderElection: enableLeaderElection,
90-
LeaderElectionID: "ws-manager-mk2.gitpod.io",
90+
LeaderElectionID: "ws-manager-mk2-leader.gitpod.io",
9191
Namespace: cfg.Manager.Namespace,
9292
})
9393
if err != nil {

0 commit comments

Comments
 (0)