@@ -163,6 +163,7 @@ func (ir *ideRoutes) HandleSupervisorFrontendRoute(route *mux.Route) {
163
163
164
164
r := route .Subrouter ()
165
165
r .Use (logRouteHandlerHandler ("SupervisorIDEHostHandler" ))
166
+ r .Use (ir .workspaceMustExistHandler )
166
167
// strip the frontend prefix, just for good measure
167
168
r .Use (func (h http.Handler ) http.Handler {
168
169
return http .HandlerFunc (func (resp http.ResponseWriter , req * http.Request ) {
@@ -171,17 +172,27 @@ func (ir *ideRoutes) HandleSupervisorFrontendRoute(route *mux.Route) {
171
172
})
172
173
})
173
174
// always hit the blobserver to ensure that blob is downloaded
174
- r .NewRoute ().HandlerFunc (proxyPass (ir .Config , ir .InfoProvider , func (cfg * Config , _ WorkspaceInfoProvider , req * http.Request ) (* url.URL , error ) {
175
- return resolveSupervisorURL (cfg ), nil
175
+ r .NewRoute ().HandlerFunc (proxyPass (ir .Config , ir .InfoProvider , func (cfg * Config , infoProvider WorkspaceInfoProvider , req * http.Request ) (* url.URL , error ) {
176
+ info := getWorkspaceInfoFromContext (req .Context ())
177
+ return resolveSupervisorURL (cfg , info , req )
176
178
}, func (h * proxyPassConfig ) {
177
179
h .Transport = & blobserveTransport {
178
180
transport : h .Transport ,
179
181
Config : ir .Config .Config ,
180
182
resolveImage : func (t * blobserveTransport , req * http.Request ) string {
181
- var (
182
- image = ir .Config .Config .WorkspacePodConfig .SupervisorImage
183
- path = strings .TrimPrefix (req .URL .Path , "/" + image )
184
- )
183
+ info := getWorkspaceInfoFromContext (req .Context ())
184
+ if info == nil && len (ir .Config .Config .WorkspacePodConfig .SupervisorImage ) == 0 {
185
+ // no workspace information available - cannot resolve supervisor image
186
+ return ""
187
+ }
188
+
189
+ // use the config value for backwards compatibility when info.SupervisorImage is not set
190
+ image := ir .Config .Config .WorkspacePodConfig .SupervisorImage
191
+ if info != nil && len (info .SupervisorImage ) > 0 {
192
+ image = info .SupervisorImage
193
+ }
194
+
195
+ path := strings .TrimPrefix (req .URL .Path , "/" + image )
185
196
if path == "/worker-proxy.js" {
186
197
// worker must be served from the same origin
187
198
return ""
@@ -192,12 +203,23 @@ func (ir *ideRoutes) HandleSupervisorFrontendRoute(route *mux.Route) {
192
203
}))
193
204
}
194
205
195
- func resolveSupervisorURL (cfg * Config ) * url.URL {
206
+ func resolveSupervisorURL (cfg * Config , info * WorkspaceInfo , req * http.Request ) (* url.URL , error ) {
207
+ if info == nil && len (cfg .WorkspacePodConfig .SupervisorImage ) == 0 {
208
+ log .WithFields (log .OWI ("" , getWorkspaceCoords (req ).ID , "" )).Warn ("no workspace info available - cannot resolve supervisor route" )
209
+ return nil , xerrors .Errorf ("no workspace information available - cannot resolve supervisor route" )
210
+ }
211
+
212
+ // use the config value for backwards compatibility when info.SupervisorImage is not set
213
+ supervisorImage := cfg .WorkspacePodConfig .SupervisorImage
214
+ if info != nil && len (info .SupervisorImage ) > 0 {
215
+ supervisorImage = info .SupervisorImage
216
+ }
217
+
196
218
var dst url.URL
197
219
dst .Scheme = cfg .BlobServer .Scheme
198
220
dst .Host = cfg .BlobServer .Host
199
- dst .Path = "/" + cfg . WorkspacePodConfig . SupervisorImage
200
- return & dst
221
+ dst .Path = "/" + supervisorImage
222
+ return & dst , nil
201
223
}
202
224
203
225
type BlobserveInlineVars struct {
@@ -234,8 +256,13 @@ func (ir *ideRoutes) HandleRoot(route *mux.Route) {
234
256
// but it has to know exposed URLs in the context of current workspace cluster
235
257
// so first we ask blobserve to preload the supervisor image
236
258
// and if it is successful we pass exposed URLs to IDE and supervisor to blobserve for inlining
237
- supervisorURL := resolveSupervisorURL (t .Config ).String () + "/main.js"
238
- preloadSupervisorReq , err := http .NewRequest ("GET" , supervisorURL , nil )
259
+ supervisorURL , err := resolveSupervisorURL (t .Config , info , req )
260
+ if err != nil {
261
+ log .WithError (err ).Error ("could not preload supervisor" )
262
+ return image
263
+ }
264
+ supervisorURLString := supervisorURL .String () + "/main.js"
265
+ preloadSupervisorReq , err := http .NewRequest ("GET" , supervisorURLString , nil )
239
266
if err != nil {
240
267
log .WithField ("supervisorURL" , supervisorURL ).WithError (err ).Error ("could not preload supervisor" )
241
268
return image
@@ -251,9 +278,15 @@ func (ir *ideRoutes) HandleRoot(route *mux.Route) {
251
278
return image
252
279
}
253
280
281
+ // use the config value for backwards compatibility when info.SupervisorImage is not set
282
+ supervisorImage := t .Config .WorkspacePodConfig .SupervisorImage
283
+ if len (info .SupervisorImage ) > 0 {
284
+ supervisorImage = info .SupervisorImage
285
+ }
286
+
254
287
inlineVars := & BlobserveInlineVars {
255
288
IDE : t .asBlobserveURL (image , "" ),
256
- SupervisorImage : t .asBlobserveURL (t . Config . WorkspacePodConfig . SupervisorImage , "" ),
289
+ SupervisorImage : t .asBlobserveURL (supervisorImage , "" ),
257
290
}
258
291
inlinveVarsValue , err := json .Marshal (inlineVars )
259
292
if err != nil {
0 commit comments