Skip to content

feat: implement claiming of prebuilt workspaces #17458

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 38 commits into from
Apr 24, 2025
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8b9e30d
feat: implement claiming of prebuilt workspaces
evgeniy-scherbina Apr 17, 2025
d9497df
Merge branch 'main' of github.com:/coder/coder into yevhenii/512-clai…
dannykopping Apr 22, 2025
217e46f
Reverting unncessary changes
dannykopping Apr 21, 2025
c459533
Refactoring
dannykopping Apr 22, 2025
f905219
Removing unnecessary field
dannykopping Apr 22, 2025
8266338
make fmt
dannykopping Apr 22, 2025
4098ed7
CR's fixes
evgeniy-scherbina Apr 22, 2025
50d23e4
CR's fixes
evgeniy-scherbina Apr 22, 2025
546b7ae
Update coderd/workspaces.go
evgeniy-scherbina Apr 22, 2025
85f7926
CR's fixes
evgeniy-scherbina Apr 22, 2025
ee9908c
CR's fixes
evgeniy-scherbina Apr 22, 2025
70bf179
CR's fixes
evgeniy-scherbina Apr 22, 2025
7a72d03
CR's fixes
evgeniy-scherbina Apr 22, 2025
b246589
fix tests by updating noop.go
evgeniy-scherbina Apr 22, 2025
ff8d3de
Merge branch 'main' of github.com:/coder/coder into yevhenii/512-clai…
dannykopping Apr 23, 2025
fcdbba8
test: add failure testcase scenario
evgeniy-scherbina Apr 23, 2025
e7b7f80
refactor: revert interface changes
evgeniy-scherbina Apr 23, 2025
e7455db
refactor: simplify signature of claim method
evgeniy-scherbina Apr 23, 2025
077d7f0
refactor: CR's fixes
evgeniy-scherbina Apr 23, 2025
0d426c7
Merge remote-tracking branch 'origin/main' into yevhenii/512-claim-pr…
evgeniy-scherbina Apr 23, 2025
663a8c0
refactor: CR's fixes
evgeniy-scherbina Apr 23, 2025
bc31fac
refactor: make lint
evgeniy-scherbina Apr 23, 2025
087bd20
refactor: fix linter
evgeniy-scherbina Apr 23, 2025
9f66169
refactor: remove PrebuildsOrchestrator context from claim tests
evgeniy-scherbina Apr 23, 2025
7f25f24
refactor: don't fail test in a goroutine
evgeniy-scherbina Apr 23, 2025
ff9eeb4
docs: fix ssh coder example in testing-templates doc (#17550)
EdwardAngert Apr 23, 2025
31b873f
fix: add websocket close handling (#17548)
jaaydenh Apr 23, 2025
4fe770d
ci: move go install tools to separate action (#17552)
ethanndickson Apr 24, 2025
8d8fc99
chore(dogfood): allow provider minor version updates (#17554)
matifali Apr 24, 2025
af32325
fix(examples/templates/docker-devcontainer): update folder path and p…
Aericio Apr 24, 2025
0826e8a
feat: enable masking password inputs instead of blocking echo (#17469)
ibetitsmike Apr 24, 2025
cbb6c12
fix(examples/templates/kubernetes-devcontainer): update coder provide…
matifali Apr 24, 2025
e466844
docs: add automatic release calendar updates in docs (#17531)
matifali Apr 24, 2025
f24557b
chore(dogfood): add windsurf module (#17558)
matifali Apr 24, 2025
fa65564
Merge branch 'main' of github.com:/coder/coder into yevhenii/512-clai…
dannykopping Apr 24, 2025
53b38d7
fix: use userCtx instead of prebuildCtx for claiming prebuild
evgeniy-scherbina Apr 24, 2025
6c41e03
refactor: CR's fixes
evgeniy-scherbina Apr 24, 2025
9173e9a
CR's fixes
evgeniy-scherbina Apr 24, 2025
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
Prev Previous commit
Next Next commit
CR's fixes
  • Loading branch information
evgeniy-scherbina committed Apr 22, 2025
commit 50d23e4780a863f90a2c36192285febb2dd97302
49 changes: 16 additions & 33 deletions enterprise/coderd/prebuilds/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,42 @@
"database/sql"
"errors"

"github.com/coder/coder/v2/coderd/prebuilds"

"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/prebuilds"
)

type EnterpriseClaimer struct{}

func (_ EnterpriseClaimer) Claim(

Check failure on line 17 in enterprise/coderd/prebuilds/claim.go

View workflow job for this annotation

GitHub Actions / lint

receiver-naming: receiver name should not be an underscore, omit the name if it is unused (revive)
ctx context.Context,
store database.Store,
userID uuid.UUID,
name string,
presetID uuid.UUID,
) (*uuid.UUID, error) {
var prebuildID *uuid.UUID
err := store.InTx(func(db database.Store) error {
// TODO: do we need this?
//// Ensure no other replica can claim a prebuild for this user simultaneously.
// err := store.AcquireLock(ctx, database.GenLockID(fmt.Sprintf("prebuild-user-claim-%s", userID.String())))
// if err != nil {
// return xerrors.Errorf("acquire claim lock for user %q: %w", userID.String(), err)
//}

result, err := db.ClaimPrebuiltWorkspace(ctx, database.ClaimPrebuiltWorkspaceParams{
NewUserID: userID,
NewName: name,
PresetID: presetID,
})
if err != nil {
switch {
// No eligible prebuilds found
case errors.Is(err, sql.ErrNoRows):
// Exit, this will result in a nil prebuildID being returned, which is fine
return nil
default:
return xerrors.Errorf("claim prebuild for user %q: %w", userID.String(), err)
}
}

prebuildID = &result.ID

return nil
}, &database.TxOptions{
TxIdentifier: "prebuild-claim",
result, err := store.ClaimPrebuiltWorkspace(ctx, database.ClaimPrebuiltWorkspaceParams{
NewUserID: userID,
NewName: name,
PresetID: presetID,
})
if err != nil {
switch {
// No eligible prebuilds found
case errors.Is(err, sql.ErrNoRows):
// Exit, this will result in a nil prebuildID being returned, which is fine
return nil, nil
default:
return nil, xerrors.Errorf("claim prebuild for user %q: %w", userID.String(), err)
}
}

return prebuildID, err
return &result.ID, nil
}

func (_ EnterpriseClaimer) Initiator() uuid.UUID {

Check failure on line 43 in enterprise/coderd/prebuilds/claim.go

View workflow job for this annotation

GitHub Actions / lint

receiver-naming: receiver name should not be an underscore, omit the name if it is unused (revive)
return prebuilds.SystemUserID
}

Expand Down
Loading