Skip to content

Commit ff2966a

Browse files
committed
Make workspace runtime explicit
1 parent be75a5d commit ff2966a

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

components/supervisor/pkg/supervisor/config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,29 @@ type WorkspaceConfig struct {
334334

335335
// ContentInitializer - if set - will run the content initializer instead of waiting for the ready file
336336
ContentInitializer string `env:"SUPERVISOR_CONTENT_INITIALIZER"`
337+
338+
// WorkspaceRuntime configures the runtime supervisor is running in
339+
WorkspaceRuntime WorkspaceRuntime `env:"SUPERVISOR_WORKSPACE_RUNTIME,default=container"`
340+
}
341+
342+
type WorkspaceRuntime string
343+
344+
const (
345+
WorkspaceRuntimeContainer WorkspaceRuntime = "container"
346+
WorkspaceRuntimeNextgen WorkspaceRuntime = "nextgen"
347+
WorkspaceRuntimeRunGP WorkspaceRuntime = "rungp"
348+
)
349+
350+
func (rt *WorkspaceRuntime) UnmarshalEnvironmentValue(data string) error {
351+
switch WorkspaceRuntime(data) {
352+
case WorkspaceRuntimeContainer, WorkspaceRuntimeNextgen, WorkspaceRuntimeRunGP:
353+
// everything's fine
354+
default:
355+
return fmt.Errorf("unknown workspace runtime: %s", data)
356+
}
357+
358+
*rt = WorkspaceRuntime(data)
359+
return nil
337360
}
338361

339362
// WorkspaceGitpodToken is a list of tokens that should be added to supervisor's token service.

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ func Run(options ...RunOption) {
181181
return
182182
}
183183

184+
// Note(cw): legacy rungp behaviour
185+
if opts.RunGP {
186+
cfg.WorkspaceRuntime = WorkspaceRuntimeRunGP
187+
}
188+
184189
// BEWARE: we can only call buildChildProcEnv once, because it might download env vars from a one-time-secret
185190
// URL, which would fail if we tried another time.
186191
childProcEnvvars = buildChildProcEnv(cfg, nil, opts.RunGP)
@@ -200,7 +205,7 @@ func Run(options ...RunOption) {
200205

201206
tokenService := NewInMemoryTokenService()
202207

203-
if !opts.RunGP {
208+
if cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP {
204209
tkns, err := cfg.GetTokens(true)
205210
if err != nil {
206211
log.WithError(err).Warn("cannot prepare tokens")
@@ -264,7 +269,7 @@ func Run(options ...RunOption) {
264269
notificationService = NewNotificationService()
265270
)
266271

267-
if !opts.RunGP {
272+
if cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP {
268273
gitpodService = serverapi.NewServerApiService(ctx, &serverapi.ServiceConfig{
269274
Host: host,
270275
Endpoint: endpoint,
@@ -279,7 +284,7 @@ func Run(options ...RunOption) {
279284
if cfg.GetDesktopIDE() != nil {
280285
desktopIdeReady = &ideReadyState{cond: sync.NewCond(&sync.Mutex{})}
281286
}
282-
if !cfg.isHeadless() && !opts.RunGP && !cfg.isDebugWorkspace() {
287+
if !cfg.isHeadless() && cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP && !cfg.isDebugWorkspace() {
283288
go trackReadiness(ctx, telemetry, cfg, cstate, ideReady, desktopIdeReady)
284289
}
285290
tokenService.provider[KindGit] = []tokenProvider{NewGitTokenProvider(gitpodService, cfg.WorkspaceConfig, notificationService)}
@@ -289,7 +294,7 @@ func Run(options ...RunOption) {
289294

290295
var exposedPorts ports.ExposedPortsInterface
291296

292-
if !opts.RunGP {
297+
if cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP {
293298
exposedPorts = createExposedPortsImpl(cfg, gitpodService)
294299
}
295300

@@ -304,18 +309,18 @@ func Run(options ...RunOption) {
304309
)
305310

306311
topService := NewTopService()
307-
if !opts.RunGP {
312+
if cfg.WorkspaceRuntime == WorkspaceRuntimeContainer {
308313
topService.Observe(ctx)
309314
}
310315

311-
if !cfg.isHeadless() && !opts.RunGP {
316+
if !cfg.isHeadless() && cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP {
312317
go analyseConfigChanges(ctx, cfg, telemetry, gitpodConfigService)
313318
go analysePerfChanges(ctx, cfg, telemetry, topService)
314319
}
315320

316321
supervisorMetrics := metrics.NewMetrics()
317322
var metricsReporter *metrics.GrpcMetricsReporter
318-
if !opts.RunGP && !cfg.isDebugWorkspace() && !strings.Contains("ephemeral", cfg.WorkspaceClusterHost) {
323+
if cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP && !cfg.isDebugWorkspace() && !strings.Contains("ephemeral", cfg.WorkspaceClusterHost) {
319324
_, gitpodHost, err := cfg.GitpodAPIEndpoint()
320325
if err != nil {
321326
log.WithError(err).Error("grpc metrics: failed to parse gitpod host")
@@ -355,7 +360,7 @@ func Run(options ...RunOption) {
355360

356361
gitStatusWg := &sync.WaitGroup{}
357362
gitStatusCtx, stopGitStatus := context.WithCancel(ctx)
358-
if !cfg.isPrebuild() && !cfg.isHeadless() && !opts.RunGP && !cfg.isDebugWorkspace() {
363+
if !cfg.isPrebuild() && !cfg.isHeadless() && cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP && !cfg.isDebugWorkspace() {
359364
gitStatusWg.Add(1)
360365
gitStatusService := &GitStatusService{
361366
cfg: cfg,
@@ -406,7 +411,7 @@ func Run(options ...RunOption) {
406411
shutdown = make(chan ShutdownReason, 1)
407412
)
408413

409-
if opts.RunGP {
414+
if cfg.WorkspaceRuntime == WorkspaceRuntimeRunGP {
410415
cstate.MarkContentReady(csapi.WorkspaceInitFromOther)
411416
} else if cfg.isDebugWorkspace() {
412417
cstate.MarkContentReady(cfg.GetDebugWorkspaceContentSource())
@@ -425,15 +430,15 @@ func Run(options ...RunOption) {
425430
tasksSuccessChan := make(chan taskSuccess, 1)
426431
go taskManager.Run(ctx, &wg, tasksSuccessChan)
427432

428-
if !opts.RunGP {
433+
if cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP {
429434
wg.Add(1)
430435
go socketActivationForDocker(ctx, &wg, termMux, cfg, telemetry, notificationService, cstate)
431436
}
432437

433438
if cfg.isHeadless() {
434439
wg.Add(1)
435440
go stopWhenTasksAreDone(ctx, &wg, shutdown, tasksSuccessChan)
436-
} else if !opts.RunGP {
441+
} else if cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP {
437442
wg.Add(1)
438443
go portMgmt.Run(ctx, &wg)
439444
}
@@ -449,7 +454,7 @@ func Run(options ...RunOption) {
449454
}()
450455
}
451456

452-
if !cfg.isPrebuild() && !opts.RunGP && !cfg.isDebugWorkspace() {
457+
if !cfg.isPrebuild() && cfg.WorkspaceRuntime != WorkspaceRuntimeRunGP && !cfg.isDebugWorkspace() {
453458
go func() {
454459
for _, repoRoot := range strings.Split(cfg.RepoRoots, ",") {
455460
<-cstate.ContentReady()

0 commit comments

Comments
 (0)