Skip to content

Commit

Permalink
Check for existing image builds
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Oct 11, 2021
1 parent 68c944f commit 529361c
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions components/ws-manager/pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,34 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
defer tracing.FinishSpan(span, &err)

// Make sure the objects we're about to create do not exist already
exists, err := m.workspaceExists(ctx, req.Id)
if err != nil {
return nil, xerrors.Errorf("cannot start workspace: %w", err)
}
if exists {
return nil, status.Error(codes.AlreadyExists, "workspace instance already exists")
switch req.Type {
case api.WorkspaceType_IMAGEBUILD:
wss, err := m.GetWorkspaces(ctx, &api.GetWorkspacesRequest{
MustMatch: &api.MetadataFilter{
Annotations: req.Metadata.Annotations,
},
})
if err != nil {
return nil, xerrors.Errorf("cannot start workspace: %w", err)
}

if len(wss.Status) >= 1 {
status := wss.Status[0]
return &api.StartWorkspaceResponse{
Url: status.Spec.Url,
OwnerToken: status.Metadata.Owner,
}, nil
}
default:
exists, err := m.workspaceExists(ctx, req.Id)
if err != nil {
return nil, xerrors.Errorf("cannot start workspace: %w", err)
}
if exists {
return nil, status.Error(codes.AlreadyExists, "workspace instance already exists")
}
}

span.LogKV("event", "workspace does not exist")
err = validateStartWorkspaceRequest(req)
if err != nil {
Expand Down

0 comments on commit 529361c

Please sign in to comment.