Skip to content

[ws-manager-mk2] Fix workspace URL not set in env #16407

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 1 commit into from
Feb 15, 2023
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
17 changes: 14 additions & 3 deletions components/ws-manager-mk2/controllers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@ func createWorkspaceEnvironment(sctx *startWorkspaceContext) ([]corev1.EnvVar, e
allRepoRoots[i] = getWorkspaceRelativePath(root)
}

// Can't read the workspace URL from status yet, as the status likely hasn't
// been set by the controller yet at this point. Therefore, manually construct
// the URL to pass to the container env.
wsUrl, err := config.RenderWorkspaceURL(sctx.Config.WorkspaceURLTemplate, sctx.Workspace.Name, sctx.Workspace.Spec.Ownership.WorkspaceID, sctx.Config.GitpodHostURL)
if err != nil {
return nil, fmt.Errorf("cannot render workspace URL: %w", err)
}

// Envs that start with GITPOD_ are appended to the Terminal environments
result := []corev1.EnvVar{}
result = append(result, corev1.EnvVar{Name: "GITPOD_REPO_ROOT", Value: allRepoRoots[0]})
Expand All @@ -575,7 +583,7 @@ func createWorkspaceEnvironment(sctx *startWorkspaceContext) ([]corev1.EnvVar, e
result = append(result, corev1.EnvVar{Name: "GITPOD_THEIA_PORT", Value: strconv.Itoa(int(sctx.IDEPort))})
result = append(result, corev1.EnvVar{Name: "THEIA_WORKSPACE_ROOT", Value: getWorkspaceRelativePath(sctx.Workspace.Spec.WorkspaceLocation)})
result = append(result, corev1.EnvVar{Name: "GITPOD_HOST", Value: sctx.Config.GitpodHostURL})
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_URL", Value: sctx.Workspace.Status.URL})
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_URL", Value: wsUrl})
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_CLUSTER_HOST", Value: sctx.Config.WorkspaceClusterHost})
result = append(result, corev1.EnvVar{Name: "THEIA_SUPERVISOR_ENDPOINT", Value: fmt.Sprintf(":%d", sctx.SupervisorPort)})
// TODO(ak) remove THEIA_WEBVIEW_EXTERNAL_ENDPOINT and THEIA_MINI_BROWSER_HOST_PATTERN when Theia is removed
Expand Down Expand Up @@ -703,6 +711,9 @@ func newStartWorkspaceContext(ctx context.Context, cfg *config.Configuration, ws
span, _ := tracing.FromContext(ctx, "newStartWorkspaceContext")
defer tracing.FinishSpan(span, &err)

// Can't read ws.Status yet at this point (to e.g. get the headless status),
// as it very likely hasn't been set yet by the controller.
isHeadless := ws.Spec.Type != workspacev1.WorkspaceTypeRegular
return &startWorkspaceContext{
Labels: map[string]string{
"app": "gitpod",
Expand All @@ -711,13 +722,13 @@ func newStartWorkspaceContext(ctx context.Context, cfg *config.Configuration, ws
wsk8s.OwnerLabel: ws.Spec.Ownership.Owner,
wsk8s.TypeLabel: strings.ToLower(string(ws.Spec.Type)),
instanceIDLabel: ws.Name,
headlessLabel: strconv.FormatBool(ws.Status.Headless),
headlessLabel: strconv.FormatBool(isHeadless),
},
Config: cfg,
Workspace: ws,
IDEPort: 23000,
SupervisorPort: 22999,
Headless: ws.Status.Headless,
Headless: isHeadless,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion components/ws-manager-mk2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
Port: 9443,
HealthProbeBindAddress: cfg.Health.Addr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "ws-manager-mk2.gitpod.io",
LeaderElectionID: "ws-manager-mk2-leader.gitpod.io",
Copy link
Member Author

Choose a reason for hiding this comment

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

this ID shows up as a ConfigMap, including leader makes it more obvious that the configmap is used for leader-election

Namespace: cfg.Manager.Namespace,
})
if err != nil {
Expand Down