@@ -565,6 +565,14 @@ func createWorkspaceEnvironment(sctx *startWorkspaceContext) ([]corev1.EnvVar, e
565
565
allRepoRoots [i ] = getWorkspaceRelativePath (root )
566
566
}
567
567
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
+
568
576
// Envs that start with GITPOD_ are appended to the Terminal environments
569
577
result := []corev1.EnvVar {}
570
578
result = append (result , corev1.EnvVar {Name : "GITPOD_REPO_ROOT" , Value : allRepoRoots [0 ]})
@@ -575,7 +583,7 @@ func createWorkspaceEnvironment(sctx *startWorkspaceContext) ([]corev1.EnvVar, e
575
583
result = append (result , corev1.EnvVar {Name : "GITPOD_THEIA_PORT" , Value : strconv .Itoa (int (sctx .IDEPort ))})
576
584
result = append (result , corev1.EnvVar {Name : "THEIA_WORKSPACE_ROOT" , Value : getWorkspaceRelativePath (sctx .Workspace .Spec .WorkspaceLocation )})
577
585
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 })
579
587
result = append (result , corev1.EnvVar {Name : "GITPOD_WORKSPACE_CLUSTER_HOST" , Value : sctx .Config .WorkspaceClusterHost })
580
588
result = append (result , corev1.EnvVar {Name : "THEIA_SUPERVISOR_ENDPOINT" , Value : fmt .Sprintf (":%d" , sctx .SupervisorPort )})
581
589
// 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
703
711
span , _ := tracing .FromContext (ctx , "newStartWorkspaceContext" )
704
712
defer tracing .FinishSpan (span , & err )
705
713
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
706
717
return & startWorkspaceContext {
707
718
Labels : map [string ]string {
708
719
"app" : "gitpod" ,
@@ -711,13 +722,13 @@ func newStartWorkspaceContext(ctx context.Context, cfg *config.Configuration, ws
711
722
wsk8s .OwnerLabel : ws .Spec .Ownership .Owner ,
712
723
wsk8s .TypeLabel : strings .ToLower (string (ws .Spec .Type )),
713
724
instanceIDLabel : ws .Name ,
714
- headlessLabel : strconv .FormatBool (ws . Status . Headless ),
725
+ headlessLabel : strconv .FormatBool (isHeadless ),
715
726
},
716
727
Config : cfg ,
717
728
Workspace : ws ,
718
729
IDEPort : 23000 ,
719
730
SupervisorPort : 22999 ,
720
- Headless : ws . Status . Headless ,
731
+ Headless : isHeadless ,
721
732
}, nil
722
733
}
723
734
0 commit comments