Skip to content

Commit bee03a1

Browse files
authored
[supervisor] fix panic with runGP option (#18777)
* [supervisor] fix panic with runGP option * Check if `s` is nil to avoid adding guards outside
1 parent df155ad commit bee03a1

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

components/supervisor/pkg/serverapi/publicapi.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ func (s *Service) usePublicAPI(ctx context.Context) bool {
198198
}
199199

200200
func (s *Service) GetToken(ctx context.Context, query *gitpod.GetTokenSearchOptions) (res *gitpod.Token, err error) {
201+
if s == nil {
202+
return nil, errNotConnected
203+
}
201204
startTime := time.Now()
202205
usePublicApi := s.usePublicAPI(ctx)
203206
defer func() {
204207
s.apiMetrics.ProcessMetrics(usePublicApi, "GetToken", err, startTime)
205208
}()
206-
if s == nil {
207-
return nil, errNotConnected
208-
}
209209
if !usePublicApi {
210210
return s.gitpodService.GetToken(ctx, query)
211211
}
@@ -230,14 +230,14 @@ func (s *Service) GetToken(ctx context.Context, query *gitpod.GetTokenSearchOpti
230230
}
231231

232232
func (s *Service) UpdateGitStatus(ctx context.Context, status *gitpod.WorkspaceInstanceRepoStatus) (err error) {
233+
if s == nil {
234+
return errNotConnected
235+
}
233236
startTime := time.Now()
234237
usePublicApi := s.usePublicAPI(ctx)
235238
defer func() {
236239
s.apiMetrics.ProcessMetrics(usePublicApi, "UpdateGitStatus", err, startTime)
237240
}()
238-
if s == nil {
239-
return errNotConnected
240-
}
241241
workspaceID := s.cfg.WorkspaceID
242242
if !usePublicApi {
243243
return s.gitpodService.UpdateGitStatus(ctx, workspaceID, status)
@@ -263,14 +263,14 @@ func (s *Service) UpdateGitStatus(ctx context.Context, status *gitpod.WorkspaceI
263263
}
264264

265265
func (s *Service) OpenPort(ctx context.Context, port *gitpod.WorkspaceInstancePort) (res *gitpod.WorkspaceInstancePort, err error) {
266+
if s == nil {
267+
return nil, errNotConnected
268+
}
266269
startTime := time.Now()
267270
usePublicApi := s.usePublicAPI(ctx)
268271
defer func() {
269272
s.apiMetrics.ProcessMetrics(usePublicApi, "OpenPort", err, startTime)
270273
}()
271-
if s == nil {
272-
return nil, errNotConnected
273-
}
274274
workspaceID := s.cfg.WorkspaceID
275275
if !usePublicApi {
276276
return s.gitpodService.OpenPort(ctx, workspaceID, port)
@@ -304,14 +304,14 @@ func (s *Service) OpenPort(ctx context.Context, port *gitpod.WorkspaceInstancePo
304304
}
305305

306306
func (s *Service) GetDefaultWorkspaceImage(ctx context.Context) (image string, err error) {
307+
if s == nil {
308+
return "", errNotConnected
309+
}
307310
startTime := time.Now()
308311
usePublicApi := s.usePublicAPI(ctx)
309312
defer func() {
310313
s.apiMetrics.ProcessMetrics(usePublicApi, "GetDefaultWorkspaceImage", nil, startTime)
311314
}()
312-
if s == nil {
313-
return "", errNotConnected
314-
}
315315
workspaceID := s.cfg.WorkspaceID
316316
if !usePublicApi {
317317
resp, err := s.gitpodService.GetDefaultWorkspaceImage(ctx, &gitpod.GetDefaultWorkspaceImageParams{

components/supervisor/pkg/supervisor/services.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -659,16 +659,25 @@ func (is *InfoService) RegisterREST(mux *runtime.ServeMux, grpcEndpoint string)
659659
return api.RegisterInfoServiceHandlerFromEndpoint(context.Background(), mux, grpcEndpoint, []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())})
660660
}
661661

662-
// WorkspaceInfo provides information about the workspace.
663-
func (is *InfoService) WorkspaceInfo(ctx context.Context, req *api.WorkspaceInfoRequest) (*api.WorkspaceInfoResponse, error) {
664-
defaultWorkspaceImage, err := is.GitpodService.GetDefaultWorkspaceImage(ctx)
665-
if err != nil {
662+
func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) (defaultWorkspaceImage string) {
663+
defaultWorkspaceImage = is.cfg.DefaultWorkspaceImage
664+
if defaultWorkspaceImage == "" {
666665
// TODO: delete-me, added for compatibility before server is deployed / rollback
667-
defaultWorkspaceImage = is.cfg.DefaultWorkspaceImage
668-
if defaultWorkspaceImage == "" {
669-
defaultWorkspaceImage = "gitpod/workspace-full:latest"
670-
}
666+
defaultWorkspaceImage = "gitpod/workspace-full:latest"
667+
}
668+
if is.GitpodService == nil {
669+
return
671670
}
671+
wsImage, err := is.GitpodService.GetDefaultWorkspaceImage(ctx)
672+
if err == nil {
673+
defaultWorkspaceImage = wsImage
674+
}
675+
return
676+
}
677+
678+
// WorkspaceInfo provides information about the workspace.
679+
func (is *InfoService) WorkspaceInfo(ctx context.Context, req *api.WorkspaceInfoRequest) (*api.WorkspaceInfoResponse, error) {
680+
defaultWorkspaceImage := is.getDefaultWorkspaceImage(ctx)
672681
resp := &api.WorkspaceInfoResponse{
673682
CheckoutLocation: is.cfg.RepoRoot,
674683
InstanceId: is.cfg.WorkspaceInstanceID,

0 commit comments

Comments
 (0)