Skip to content

[supervisor] cache default workspace image #18845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions components/supervisor/pkg/supervisor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,14 @@ type InfoService struct {
GitpodService serverapi.APIInterface

api.UnimplementedInfoServiceServer

cacheMu sync.RWMutex
cacheTimestamp time.Time
defaultWorkspaceImage string
}

var infoCacheDuration = 5 * time.Second

// RegisterGRPC registers the gRPC info service.
func (is *InfoService) RegisterGRPC(srv *grpc.Server) {
api.RegisterInfoServiceServer(srv, is)
Expand All @@ -659,20 +665,34 @@ func (is *InfoService) RegisterREST(mux *runtime.ServeMux, grpcEndpoint string)
return api.RegisterInfoServiceHandlerFromEndpoint(context.Background(), mux, grpcEndpoint, []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())})
}

func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) (defaultWorkspaceImage string) {
defaultWorkspaceImage = is.cfg.DefaultWorkspaceImage
if defaultWorkspaceImage == "" {
// TODO: delete-me, added for compatibility before server is deployed / rollback
defaultWorkspaceImage = "gitpod/workspace-full:latest"
func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) string {
is.cacheMu.RLock()

if time.Since(is.cacheTimestamp) < infoCacheDuration {
is.cacheMu.RUnlock()
return is.defaultWorkspaceImage
}
is.cacheMu.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This should not be necessary, right?


is.cacheMu.Lock()
defer is.cacheMu.Unlock()
defer func() {
is.cacheTimestamp = time.Now()
}()

if time.Since(is.cacheTimestamp) < infoCacheDuration {
return is.defaultWorkspaceImage
}

is.defaultWorkspaceImage = is.cfg.DefaultWorkspaceImage
if is.GitpodService == nil {
return
return is.defaultWorkspaceImage
}
wsImage, err := is.GitpodService.GetDefaultWorkspaceImage(ctx)
if err == nil {
defaultWorkspaceImage = wsImage
is.defaultWorkspaceImage = wsImage
}
return
return is.defaultWorkspaceImage
}

// WorkspaceInfo provides information about the workspace.
Expand Down