Skip to content

Commit 5cca449

Browse files
Furistocsweichel
authored andcommitted
Use checkout location during content init
1 parent b86d7f4 commit 5cca449

File tree

5 files changed

+42
-60
lines changed

5 files changed

+42
-60
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,22 @@ func PlaceWorkspaceReadyFile(ctx context.Context, wspath string, initsrc csapi.W
516516

517517
return nil
518518
}
519+
520+
func GetCheckoutLocationFromInitializer(init *csapi.WorkspaceInitializer) string {
521+
switch {
522+
case init.GetGit() != nil:
523+
return init.GetGit().CheckoutLocation
524+
case init.GetPrebuild() != nil && len(init.GetPrebuild().Git) > 0:
525+
return init.GetPrebuild().Git[0].CheckoutLocation
526+
case init.GetBackup() != nil:
527+
return init.GetBackup().CheckoutLocation
528+
case init.GetComposite() != nil:
529+
for _, c := range init.GetComposite().Initializer {
530+
loc := GetCheckoutLocationFromInitializer(c)
531+
if loc != "" {
532+
return loc
533+
}
534+
}
535+
}
536+
return ""
537+
}

components/ws-daemon/pkg/content/service.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (s *WorkspaceService) creator(req *api.InitWorkspaceRequest) session.Worksp
253253
return func(ctx context.Context, location string) (res *session.Workspace, err error) {
254254
return &session.Workspace{
255255
Location: location,
256-
CheckoutLocation: getCheckoutLocation(req),
256+
CheckoutLocation: wsinit.GetCheckoutLocationFromInitializer(req.Initializer),
257257
CreatedAt: time.Now(),
258258
Owner: req.Metadata.Owner,
259259
WorkspaceID: req.Metadata.MetaId,
@@ -273,24 +273,6 @@ func ServiceDirName(instanceID string) string {
273273
return instanceID + "-daemon"
274274
}
275275

276-
// getCheckoutLocation returns the first checkout location found of any Git initializer configured by this request
277-
func getCheckoutLocation(req *api.InitWorkspaceRequest) string {
278-
spec := req.Initializer.Spec
279-
if ir, ok := spec.(*csapi.WorkspaceInitializer_Git); ok {
280-
if ir.Git != nil {
281-
return ir.Git.CheckoutLocation
282-
}
283-
}
284-
if ir, ok := spec.(*csapi.WorkspaceInitializer_Prebuild); ok {
285-
if ir.Prebuild != nil {
286-
if len(ir.Prebuild.Git) > 0 {
287-
return ir.Prebuild.Git[0].CheckoutLocation
288-
}
289-
}
290-
}
291-
return ""
292-
}
293-
294276
// DisposeWorkspace cleans up a workspace, possibly after taking a final backup
295277
func (s *WorkspaceService) DisposeWorkspace(ctx context.Context, req *api.DisposeWorkspaceRequest) (resp *api.DisposeWorkspaceResponse, err error) {
296278
//nolint:ineffassign

components/ws-daemon/pkg/internal/session/workspace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (s *Workspace) UpdateGitStatus(ctx context.Context) (res *csapi.GitStatus,
268268

269269
loc = filepath.Join(loc, s.CheckoutLocation)
270270
if !git.IsWorkingCopy(loc) {
271-
log.WithField("loc", loc).WithFields(s.OWI()).Debug("did not find a Git working copy - not updating Git status")
271+
log.WithField("loc", loc).WithField("checkout location", s.CheckoutLocation).WithFields(s.OWI()).Debug("did not find a Git working copy - not updating Git status")
272272
return nil, nil
273273
}
274274

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

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/gitpod-io/gitpod/common-go/kubernetes"
2828
wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
2929
"github.com/gitpod-io/gitpod/common-go/tracing"
30-
csapi "github.com/gitpod-io/gitpod/content-service/api"
30+
content "github.com/gitpod-io/gitpod/content-service/pkg/initializer"
3131
regapi "github.com/gitpod-io/gitpod/registry-facade/api"
3232
"github.com/gitpod-io/gitpod/ws-manager/api"
3333
config "github.com/gitpod-io/gitpod/ws-manager/api/config"
@@ -608,9 +608,11 @@ func (m *Manager) createWorkspaceEnvironment(startContext *startWorkspaceContext
608608
return filepath.Join("/workspace", strings.TrimPrefix(segment, "/workspace"))
609609
}
610610

611+
repoRoot := content.GetCheckoutLocationFromInitializer(spec.Initializer)
612+
611613
// Envs that start with GITPOD_ are appended to the Terminal environments
612614
result := []corev1.EnvVar{}
613-
result = append(result, corev1.EnvVar{Name: "GITPOD_REPO_ROOT", Value: getWorkspaceRelativePath(startContext.CheckoutLocation)})
615+
result = append(result, corev1.EnvVar{Name: "GITPOD_REPO_ROOT", Value: getWorkspaceRelativePath(repoRoot)})
614616
result = append(result, corev1.EnvVar{Name: "GITPOD_CLI_APITOKEN", Value: startContext.CLIAPIKey})
615617
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_ID", Value: startContext.Request.Metadata.MetaId})
616618
result = append(result, corev1.EnvVar{Name: "GITPOD_INSTANCE_ID", Value: startContext.Request.Id})
@@ -743,25 +745,6 @@ func (m *Manager) createDefaultSecurityContext() (*corev1.SecurityContext, error
743745
return res, nil
744746
}
745747

746-
func getCheckoutLocationFromInitializer(init *csapi.WorkspaceInitializer) string {
747-
switch {
748-
case init.GetGit() != nil:
749-
return init.GetGit().CheckoutLocation
750-
case init.GetPrebuild() != nil && len(init.GetPrebuild().Git) > 0:
751-
return init.GetPrebuild().Git[0].CheckoutLocation
752-
case init.GetBackup() != nil:
753-
return init.GetBackup().CheckoutLocation
754-
case init.GetComposite() != nil:
755-
for _, c := range init.GetComposite().Initializer {
756-
loc := getCheckoutLocationFromInitializer(c)
757-
if loc != "" {
758-
return loc
759-
}
760-
}
761-
}
762-
return ""
763-
}
764-
765748
func (m *Manager) newStartWorkspaceContext(ctx context.Context, req *api.StartWorkspaceRequest) (res *startWorkspaceContext, err error) {
766749
// we deliberately do not shadow ctx here as we need the original context later to extract the TraceID
767750
span, ctx := tracing.FromContext(ctx, "newStartWorkspaceContext")
@@ -802,15 +785,14 @@ func (m *Manager) newStartWorkspaceContext(ctx context.Context, req *api.StartWo
802785
headlessLabel: fmt.Sprintf("%v", headless),
803786
markerLabel: "true",
804787
},
805-
CLIAPIKey: cliAPIKey,
806-
OwnerToken: ownerToken,
807-
Request: req,
808-
IDEPort: 23000,
809-
SupervisorPort: 22999,
810-
WorkspaceURL: workspaceURL,
811-
TraceID: traceID,
812-
Headless: headless,
813-
CheckoutLocation: getCheckoutLocationFromInitializer(req.Spec.Initializer),
788+
CLIAPIKey: cliAPIKey,
789+
OwnerToken: ownerToken,
790+
Request: req,
791+
IDEPort: 23000,
792+
SupervisorPort: 22999,
793+
WorkspaceURL: workspaceURL,
794+
TraceID: traceID,
795+
Headless: headless,
814796
}, nil
815797
}
816798

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,15 @@ type Manager struct {
6868
}
6969

7070
type startWorkspaceContext struct {
71-
Request *api.StartWorkspaceRequest `json:"request"`
72-
Labels map[string]string `json:"labels"`
73-
CLIAPIKey string `json:"cliApiKey"`
74-
OwnerToken string `json:"ownerToken"`
75-
IDEPort int32 `json:"idePort"`
76-
SupervisorPort int32 `json:"supervisorPort"`
77-
WorkspaceURL string `json:"workspaceURL"`
78-
TraceID string `json:"traceID"`
79-
Headless bool `json:"headless"`
80-
CheckoutLocation string `json:"checkoutLocation"`
71+
Request *api.StartWorkspaceRequest `json:"request"`
72+
Labels map[string]string `json:"labels"`
73+
CLIAPIKey string `json:"cliApiKey"`
74+
OwnerToken string `json:"ownerToken"`
75+
IDEPort int32 `json:"idePort"`
76+
SupervisorPort int32 `json:"supervisorPort"`
77+
WorkspaceURL string `json:"workspaceURL"`
78+
TraceID string `json:"traceID"`
79+
Headless bool `json:"headless"`
8180
}
8281

8382
const (

0 commit comments

Comments
 (0)