Skip to content

Commit 171e95e

Browse files
felladrinAndrea Falzettiakosyakov
committed
supervisor: improve run-gp by disabling some features from supervisor
Co-authored-by: Andrea Falzetti <andrea@gitpod.io> Co-authored-by: Anton Kosyakov <anton@gitpod.io>
1 parent b19357f commit 171e95e

File tree

5 files changed

+114
-20
lines changed

5 files changed

+114
-20
lines changed

components/supervisor/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
supervisor

components/supervisor/cmd/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var runCmd = &cobra.Command{
2323
Short: "starts the supervisor",
2424

2525
Run: func(cmd *cobra.Command, args []string) {
26-
log.Init(ServiceName, Version, true, os.Getenv("SUPERVISOR_DEBUG_ENABLE") == "true")
26+
log.Init(ServiceName, Version, !runOpts.RunGP, os.Getenv("SUPERVISOR_DEBUG_ENABLE") == "true")
2727
common_grpc.SetupLogging()
2828
supervisor.Version = Version
2929
supervisor.Run(supervisor.WithRunGP(runOpts.RunGP))

components/supervisor/hot-swap.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
# Licensed under the GNU Affero General Public License (AGPL).
4+
# See License.AGPL.txt in the project root for license information.
5+
6+
set -Eeuo pipefail
7+
8+
# This script swaps the backend startup endpoint with a built one
9+
# in a workspace and restarts the JB backend.
10+
11+
component=${PWD##*/}
12+
workspaceUrl=$(echo "${1}" |sed -e "s/\/$//")
13+
echo "URL: $workspaceUrl"
14+
15+
workspaceDesc=$(gpctl workspaces describe "$workspaceUrl" -o=json)
16+
17+
podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)
18+
echo "Pod: $podName"
19+
20+
workspaceId=$(echo "$workspaceDesc" | jq .metadata.meta_id -r)
21+
echo "ID: $workspaceId"
22+
23+
clusterHost=$(kubectl exec -it "$podName" -- printenv GITPOD_WORKSPACE_CLUSTER_HOST |sed -e "s/\s//g")
24+
echo "Cluster Host: $clusterHost"
25+
26+
# prepare ssh
27+
ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)
28+
sshConfig="./ssh-config"
29+
echo "Host $workspaceId" > "$sshConfig"
30+
echo " Hostname \"$workspaceId.ssh.$clusterHost\"" >> "$sshConfig"
31+
echo " User \"$workspaceId#$ownerToken\"" >> "$sshConfig"
32+
33+
# build
34+
go build .
35+
echo "$component built"
36+
37+
# upload
38+
uploadDest="/.supervisor/$component"
39+
echo "Upload Dest: $uploadDest"
40+
ssh -F "$sshConfig" "$workspaceId" "sudo chmod 777 $uploadDest && sudo rm $uploadDest"
41+
scp -F "$sshConfig" -r "./supervisor" "$workspaceId":"$uploadDest"
42+
echo "Swap complete"
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
# Licensed under the GNU Affero General Public License (AGPL).
4+
# See License.AGPL.txt in the project root for license information.
5+
6+
set -Eeuo pipefail
7+
8+
# This script swaps the backend startup endpoint with a built one
9+
# in a workspace and restarts the JB backend.
10+
11+
component=${PWD##*/}
12+
13+
# build
14+
go build .
15+
echo "$component built"
16+
17+
sudo rm /.supervisor/supervisor
18+
sudo mv ./"$component" /.supervisor
19+
echo "Local Swap complete"

components/supervisor/pkg/supervisor/supervisor.go

+51-19
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,18 @@ func Run(options ...RunOption) {
191191
configureGit(cfg, childProcEnvvars)
192192

193193
tokenService := NewInMemoryTokenService()
194-
tkns, err := cfg.GetTokens(true)
195-
if err != nil {
196-
log.WithError(err).Warn("cannot prepare tokens")
197-
}
198-
for i := range tkns {
199-
_, err = tokenService.SetToken(context.Background(), &tkns[i].SetTokenRequest)
194+
195+
if !opts.RunGP {
196+
tkns, err := cfg.GetTokens(true)
200197
if err != nil {
201198
log.WithError(err).Warn("cannot prepare tokens")
202199
}
200+
for i := range tkns {
201+
_, err = tokenService.SetToken(context.Background(), &tkns[i].SetTokenRequest)
202+
if err != nil {
203+
log.WithError(err).Warn("cannot prepare tokens")
204+
}
205+
}
203206
}
204207

205208
tunneledPortsService := ports.NewTunneledPortsService(cfg.DebugEnable)
@@ -238,29 +241,41 @@ func Run(options ...RunOption) {
238241
desktopIdeReady *ideReadyState = nil
239242

240243
cstate = NewInMemoryContentState(cfg.RepoRoot)
244+
gitpodService serverapi.APIInterface
245+
246+
notificationService = NewNotificationService()
247+
)
248+
249+
if !opts.RunGP {
241250
gitpodService = serverapi.NewServerApiService(ctx, &serverapi.ServiceConfig{
242251
Host: host,
243252
Endpoint: endpoint,
244253
InstanceID: cfg.WorkspaceInstanceID,
245254
WorkspaceID: cfg.WorkspaceID,
246255
SupervisorVersion: Version,
247256
}, tokenService)
257+
}
248258

249-
notificationService = NewNotificationService()
250-
)
251259
if cfg.DesktopIDE != nil {
252260
desktopIdeReady = &ideReadyState{cond: sync.NewCond(&sync.Mutex{})}
253261
}
254-
if !cfg.isHeadless() {
262+
if !cfg.isHeadless() && !opts.RunGP {
255263
go trackReadiness(ctx, gitpodService, cfg, cstate, ideReady, desktopIdeReady)
256264
}
257265
tokenService.provider[KindGit] = []tokenProvider{NewGitTokenProvider(gitpodService, cfg.WorkspaceConfig, notificationService)}
258266

259267
gitpodConfigService := config.NewConfigService(cfg.RepoRoot+"/.gitpod.yml", cstate.ContentReady(), log.Log)
260268
go gitpodConfigService.Watch(ctx)
261269

270+
var exposedPorts ports.ExposedPortsInterface
271+
272+
if !opts.RunGP {
273+
exposedPorts = createExposedPortsImpl(cfg, gitpodService)
274+
}
275+
276+
// createExposedPortsImpl(cfg, gitpodService)
262277
portMgmt := ports.NewManager(
263-
createExposedPortsImpl(cfg, gitpodService),
278+
exposedPorts,
264279
&ports.PollingServedPortsObserver{
265280
RefreshInterval: 2 * time.Second,
266281
},
@@ -270,7 +285,10 @@ func Run(options ...RunOption) {
270285
)
271286

272287
topService := NewTopService()
273-
topService.Observe(ctx)
288+
289+
if !opts.RunGP {
290+
topService.Observe(ctx)
291+
}
274292

275293
supervisorMetrics := metrics.NewMetrics()
276294
var metricsReporter *metrics.GrpcMetricsReporter
@@ -353,17 +371,28 @@ func Run(options ...RunOption) {
353371
wg sync.WaitGroup
354372
shutdown = make(chan ShutdownReason, 1)
355373
)
356-
wg.Add(1)
357-
go startContentInit(ctx, cfg, &wg, cstate, supervisorMetrics)
374+
375+
if !opts.RunGP {
376+
wg.Add(1)
377+
go startContentInit(ctx, cfg, &wg, cstate, supervisorMetrics)
378+
}
379+
358380
wg.Add(1)
359381
go startAPIEndpoint(ctx, cfg, &wg, apiServices, tunneledPortsService, metricsReporter, apiEndpointOpts...)
360-
wg.Add(1)
361-
go startSSHServer(ctx, cfg, &wg, childProcEnvvars)
382+
383+
if !opts.RunGP {
384+
wg.Add(1)
385+
go startSSHServer(ctx, cfg, &wg, childProcEnvvars)
386+
}
387+
362388
wg.Add(1)
363389
tasksSuccessChan := make(chan taskSuccess, 1)
364390
go taskManager.Run(ctx, &wg, tasksSuccessChan)
365-
wg.Add(1)
366-
go socketActivationForDocker(ctx, &wg, termMux)
391+
392+
if !opts.RunGP {
393+
wg.Add(1)
394+
go socketActivationForDocker(ctx, &wg, termMux)
395+
}
367396

368397
if cfg.isHeadless() {
369398
wg.Add(1)
@@ -897,7 +926,7 @@ func prepareIDELaunch(cfg *Config, ideConfig *IDEConfig, childProcEnvvars []stri
897926
// of envvars. If envvars is nil, os.Environ() is used.
898927
//
899928
// Beware: if config contains an OTS URL the results may differ on subsequent calls.
900-
func buildChildProcEnv(cfg *Config, envvars []string) []string {
929+
func buildChildProcEnv(cfg *Config, envvars []string, runGP bool) []string {
901930
if envvars == nil {
902931
envvars = os.Environ()
903932
}
@@ -917,7 +946,10 @@ func buildChildProcEnv(cfg *Config, envvars []string) []string {
917946

918947
envs[nme] = val
919948
}
920-
envs["SUPERVISOR_ADDR"] = fmt.Sprintf("localhost:%d", cfg.APIEndpointPort)
949+
950+
if !runGP {
951+
envs["SUPERVISOR_ADDR"] = fmt.Sprintf("localhost:%d", cfg.APIEndpointPort)
952+
}
921953

922954
if cfg.EnvvarOTS != "" {
923955
es, err := downloadEnvvarOTS(cfg.EnvvarOTS)

0 commit comments

Comments
 (0)