Skip to content

Commit 8d98a4e

Browse files
committed
[supervisor] inflate all git repos
fixes [multi-repo] Shallow clones are not inflated #9021
1 parent 77d12d7 commit 8d98a4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+329
-63
lines changed

components/content-service/pkg/initializer/initializer.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -517,21 +517,24 @@ func PlaceWorkspaceReadyFile(ctx context.Context, wspath string, initsrc csapi.W
517517
return nil
518518
}
519519

520-
func GetCheckoutLocationFromInitializer(init *csapi.WorkspaceInitializer) string {
520+
func GetCheckoutLocationsFromInitializer(init *csapi.WorkspaceInitializer) []string {
521521
switch {
522522
case init.GetGit() != nil:
523-
return init.GetGit().CheckoutLocation
523+
return []string{init.GetGit().CheckoutLocation}
524524
case init.GetPrebuild() != nil && len(init.GetPrebuild().Git) > 0:
525-
return init.GetPrebuild().Git[0].CheckoutLocation
525+
var result = make([]string, len(init.GetPrebuild().Git))
526+
for i, c := range init.GetPrebuild().Git {
527+
result[i] = c.CheckoutLocation
528+
}
529+
return result
526530
case init.GetBackup() != nil:
527-
return init.GetBackup().CheckoutLocation
531+
return []string{init.GetBackup().CheckoutLocation}
528532
case init.GetComposite() != nil:
533+
var result []string
529534
for _, c := range init.GetComposite().Initializer {
530-
loc := GetCheckoutLocationFromInitializer(c)
531-
if loc != "" {
532-
return loc
533-
}
535+
result = append(result, GetCheckoutLocationsFromInitializer(c)...)
534536
}
537+
return result
535538
}
536-
return ""
539+
return nil
537540
}

components/content-service/pkg/initializer/initializer_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package initializer_test
77
import (
88
"context"
99
"fmt"
10+
"strings"
1011
"testing"
1112

1213
csapi "github.com/gitpod-io/gitpod/content-service/api"
@@ -29,6 +30,82 @@ func (f *RecordingInitializer) Run(ctx context.Context, mappings []archive.IDMap
2930
return csapi.WorkspaceInitFromOther, nil
3031
}
3132

33+
func TestGetCheckoutLocationsFromInitializer(t *testing.T) {
34+
35+
var init []*csapi.WorkspaceInitializer
36+
init = append(init, &csapi.WorkspaceInitializer{
37+
Spec: &csapi.WorkspaceInitializer_Git{
38+
Git: &csapi.GitInitializer{
39+
CheckoutLocation: "/foo",
40+
CloneTaget: "head",
41+
Config: &csapi.GitConfig{
42+
Authentication: csapi.GitAuthMethod_NO_AUTH,
43+
},
44+
RemoteUri: "somewhere-else",
45+
TargetMode: csapi.CloneTargetMode_LOCAL_BRANCH,
46+
},
47+
},
48+
})
49+
init = append(init, &csapi.WorkspaceInitializer{
50+
Spec: &csapi.WorkspaceInitializer_Git{
51+
Git: &csapi.GitInitializer{
52+
CheckoutLocation: "/bar",
53+
CloneTaget: "head",
54+
Config: &csapi.GitConfig{
55+
Authentication: csapi.GitAuthMethod_NO_AUTH,
56+
},
57+
RemoteUri: "somewhere-else",
58+
TargetMode: csapi.CloneTargetMode_LOCAL_BRANCH,
59+
},
60+
},
61+
})
62+
63+
tests := []struct {
64+
Name string
65+
Initializer *csapi.WorkspaceInitializer
66+
Expectation string
67+
}{
68+
{
69+
Name: "single git initializer",
70+
Initializer: &csapi.WorkspaceInitializer{
71+
Spec: &csapi.WorkspaceInitializer_Git{
72+
Git: &csapi.GitInitializer{
73+
CheckoutLocation: "/foo",
74+
CloneTaget: "head",
75+
Config: &csapi.GitConfig{
76+
Authentication: csapi.GitAuthMethod_NO_AUTH,
77+
},
78+
RemoteUri: "somewhere-else",
79+
TargetMode: csapi.CloneTargetMode_LOCAL_BRANCH,
80+
},
81+
},
82+
},
83+
Expectation: "/foo",
84+
},
85+
{
86+
Name: "multiple git initializer",
87+
Initializer: &csapi.WorkspaceInitializer{
88+
Spec: &csapi.WorkspaceInitializer_Composite{
89+
Composite: &csapi.CompositeInitializer{
90+
Initializer: init,
91+
},
92+
},
93+
},
94+
Expectation: "/foo,/bar",
95+
},
96+
}
97+
98+
for _, test := range tests {
99+
t.Run(test.Name, func(t *testing.T) {
100+
locations := strings.Join(initializer.GetCheckoutLocationsFromInitializer(test.Initializer), ",")
101+
if locations != test.Expectation {
102+
t.Errorf("expected %s, got %s", test.Expectation, locations)
103+
}
104+
})
105+
}
106+
107+
}
108+
32109
func TestCompositeInitializer(t *testing.T) {
33110
tests := []struct {
34111
Name string

components/supervisor/pkg/supervisor/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ type WorkspaceConfig struct {
196196
// is located. If there's no Git repo in this workspace, this will be empty.
197197
RepoRoot string `env:"GITPOD_REPO_ROOT"`
198198

199+
// RepoRoots is the comma seprated list of locations in the filesystem where Git repositories
200+
// are located. If there's no Git repo in this workspace, this will be empty.
201+
RepoRoots string `env:"GITPOD_REPO_ROOTS"`
202+
199203
// PreventMetadataAccess exits supervisor/stops the workspace if we can access Google Cloud
200204
// compute metadata from within the container.
201205
PreventMetadataAccess bool `env:"GITPOD_PREVENT_METADATA_ACCESS"`
@@ -460,6 +464,10 @@ func loadWorkspaceConfigFromEnv() (*WorkspaceConfig, error) {
460464
if err != nil {
461465
return nil, xerrors.Errorf("cannot load workspace config: %w", err)
462466
}
467+
//TODO(sefftinge) remove me after deployment (backward compatibility)
468+
if res.RepoRoots == "" {
469+
res.RepoRoots = res.RepoRoot
470+
}
463471

464472
return &res, nil
465473
}

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,23 @@ func Run(options ...RunOption) {
328328

329329
if !cfg.isHeadless() {
330330
go func() {
331-
<-cstate.ContentReady()
332-
333-
start := time.Now()
334-
defer func() {
335-
log.Debugf("unshallow of local repository took %v", time.Since(start))
336-
}()
337-
338-
cmd := runAsGitpodUser(exec.Command("git", "fetch", "--unshallow", "--tags"))
339-
cmd.Env = childProcEnvvars
340-
cmd.Dir = cfg.RepoRoot
341-
cmd.Stdout = os.Stdout
342-
cmd.Stderr = os.Stderr
343-
err := cmd.Run()
344-
if err != nil {
345-
log.WithError(err).Error("git fetch error")
331+
for _, repoRoot := range strings.Split(cfg.RepoRoots, ",") {
332+
<-cstate.ContentReady()
333+
334+
start := time.Now()
335+
defer func() {
336+
log.Debugf("unshallow of local repository took %v", time.Since(start))
337+
}()
338+
339+
cmd := runAsGitpodUser(exec.Command("git", "fetch", "--unshallow", "--tags"))
340+
cmd.Env = childProcEnvvars
341+
cmd.Dir = repoRoot
342+
cmd.Stdout = os.Stdout
343+
cmd.Stderr = os.Stderr
344+
err := cmd.Run()
345+
if err != nil {
346+
log.WithError(err).Error("git fetch error")
347+
}
346348
}
347349
}()
348350
}

components/ws-manager/pkg/manager/create.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,19 @@ func (m *Manager) createWorkspaceEnvironment(startContext *startWorkspaceContext
691691
return filepath.Join("/workspace", strings.TrimPrefix(segment, "/workspace"))
692692
}
693693

694-
repoRoot := content.GetCheckoutLocationFromInitializer(spec.Initializer)
694+
allRepoRoots := content.GetCheckoutLocationsFromInitializer(spec.Initializer)
695+
for i, root := range allRepoRoots {
696+
allRepoRoots[i] = getWorkspaceRelativePath(root)
697+
}
698+
var repoRoot string
699+
if len(allRepoRoots) > 0 {
700+
repoRoot = allRepoRoots[0]
701+
}
695702

696703
// Envs that start with GITPOD_ are appended to the Terminal environments
697704
result := []corev1.EnvVar{}
698-
result = append(result, corev1.EnvVar{Name: "GITPOD_REPO_ROOT", Value: getWorkspaceRelativePath(repoRoot)})
705+
result = append(result, corev1.EnvVar{Name: "GITPOD_REPO_ROOT", Value: repoRoot})
706+
result = append(result, corev1.EnvVar{Name: "GITPOD_REPO_ROOTS", Value: strings.Join(allRepoRoots, ",")})
699707
result = append(result, corev1.EnvVar{Name: "GITPOD_CLI_APITOKEN", Value: startContext.CLIAPIKey})
700708
result = append(result, corev1.EnvVar{Name: "GITPOD_OWNER_ID", Value: startContext.Request.Metadata.Owner})
701709
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_ID", Value: startContext.Request.Metadata.MetaId})

components/ws-manager/pkg/manager/testdata/cdwp_admission.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
"name": "GITPOD_REPO_ROOT",
7878
"value": "/workspace"
7979
},
80+
{
81+
"name": "GITPOD_REPO_ROOTS",
82+
"value": "/workspace"
83+
},
8084
{
8185
"name": "GITPOD_CLI_APITOKEN",
8286
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -264,4 +268,4 @@
264268
},
265269
"status": {}
266270
}
267-
}
271+
}

components/ws-manager/pkg/manager/testdata/cdwp_affinity.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
"name": "GITPOD_REPO_ROOT",
7878
"value": "/workspace"
7979
},
80+
{
81+
"name": "GITPOD_REPO_ROOTS",
82+
"value": "/workspace"
83+
},
8084
{
8185
"name": "GITPOD_CLI_APITOKEN",
8286
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -256,4 +260,4 @@
256260
},
257261
"status": {}
258262
}
259-
}
263+
}

components/ws-manager/pkg/manager/testdata/cdwp_class.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
"name": "GITPOD_REPO_ROOT",
7878
"value": "/workspace"
7979
},
80+
{
81+
"name": "GITPOD_REPO_ROOTS",
82+
"value": "/workspace"
83+
},
8084
{
8185
"name": "GITPOD_CLI_APITOKEN",
8286
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"

components/ws-manager/pkg/manager/testdata/cdwp_class_notfound.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
"name": "GITPOD_REPO_ROOT",
7878
"value": "/workspace"
7979
},
80+
{
81+
"name": "GITPOD_REPO_ROOTS",
82+
"value": "/workspace"
83+
},
8084
{
8185
"name": "GITPOD_CLI_APITOKEN",
8286
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"

components/ws-manager/pkg/manager/testdata/cdwp_customcerts.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
"name": "GITPOD_REPO_ROOT",
9090
"value": "/workspace"
9191
},
92+
{
93+
"name": "GITPOD_REPO_ROOTS",
94+
"value": "/workspace"
95+
},
9296
{
9397
"name": "GITPOD_CLI_APITOKEN",
9498
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -278,4 +282,4 @@
278282
},
279283
"status": {}
280284
}
281-
}
285+
}

components/ws-manager/pkg/manager/testdata/cdwp_empty_resource_req.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
"name": "GITPOD_REPO_ROOT",
7878
"value": "/workspace"
7979
},
80+
{
81+
"name": "GITPOD_REPO_ROOTS",
82+
"value": "/workspace"
83+
},
8084
{
8185
"name": "GITPOD_CLI_APITOKEN",
8286
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -254,4 +258,4 @@
254258
},
255259
"status": {}
256260
}
257-
}
261+
}

components/ws-manager/pkg/manager/testdata/cdwp_envvars.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
"name": "GITPOD_REPO_ROOT",
7878
"value": "/workspace"
7979
},
80+
{
81+
"name": "GITPOD_REPO_ROOTS",
82+
"value": "/workspace"
83+
},
8084
{
8185
"name": "GITPOD_CLI_APITOKEN",
8286
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -293,4 +297,4 @@
293297
},
294298
"status": {}
295299
}
296-
}
300+
}

components/ws-manager/pkg/manager/testdata/cdwp_fixedresources.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
"name": "GITPOD_REPO_ROOT",
7979
"value": "/workspace"
8080
},
81+
{
82+
"name": "GITPOD_REPO_ROOTS",
83+
"value": "/workspace"
84+
},
8185
{
8286
"name": "GITPOD_CLI_APITOKEN",
8387
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -261,4 +265,4 @@
261265
},
262266
"status": {}
263267
}
264-
}
268+
}

components/ws-manager/pkg/manager/testdata/cdwp_fullworkspacebackup.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"name": "GITPOD_REPO_ROOT",
7373
"value": "/workspace"
7474
},
75+
{
76+
"name": "GITPOD_REPO_ROOTS",
77+
"value": "/workspace"
78+
},
7579
{
7680
"name": "GITPOD_CLI_APITOKEN",
7781
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -250,4 +254,4 @@
250254
},
251255
"status": {}
252256
}
253-
}
257+
}

components/ws-manager/pkg/manager/testdata/cdwp_imagebuild.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
"name": "GITPOD_REPO_ROOT",
9090
"value": "/workspace"
9191
},
92+
{
93+
"name": "GITPOD_REPO_ROOTS",
94+
"value": "/workspace"
95+
},
9296
{
9397
"name": "GITPOD_CLI_APITOKEN",
9498
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -282,4 +286,4 @@
282286
},
283287
"status": {}
284288
}
285-
}
289+
}

components/ws-manager/pkg/manager/testdata/cdwp_imagebuild_template.golden

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
"name": "GITPOD_REPO_ROOT",
9090
"value": "/workspace"
9191
},
92+
{
93+
"name": "GITPOD_REPO_ROOTS",
94+
"value": "/workspace"
95+
},
9296
{
9397
"name": "GITPOD_CLI_APITOKEN",
9498
"value": "Ab=5=rRA*9:C'T{;RRB\u003e]vK2p6`fFfrS"
@@ -282,4 +286,4 @@
282286
},
283287
"status": {}
284288
}
285-
}
289+
}

0 commit comments

Comments
 (0)