Skip to content

Commit 85f7926

Browse files
CR's fixes
1 parent 546b7ae commit 85f7926

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

coderd/prebuilds/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package prebuilds
22

33
import (
44
"context"
5+
"errors"
56

67
"github.com/google/uuid"
78

89
"github.com/coder/coder/v2/coderd/database"
910
)
1011

12+
var ErrNoClaimablePrebuiltWorkspaces = errors.New("no claimable prebuilt workspaces found")
13+
1114
// ReconciliationOrchestrator manages the lifecycle of prebuild reconciliation.
1215
// It runs a continuous loop to check and reconcile prebuild states, and can be stopped gracefully.
1316
type ReconciliationOrchestrator interface {

coderd/workspaces.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ func createWorkspace(
639639
provisionerDaemons []database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow
640640
)
641641

642-
prebuilds := *api.PrebuildsClaimer.Load()
642+
prebuildsClaimer := *api.PrebuildsClaimer.Load()
643643

644644
err = api.Database.InTx(func(db database.Store) error {
645645
var (
@@ -650,8 +650,8 @@ func createWorkspace(
650650
// If a template preset was chosen, try claim a prebuilt workspace.
651651
if req.TemplateVersionPresetID != uuid.Nil {
652652
// Try and claim an eligible prebuild, if available.
653-
claimedWorkspace, err = claimPrebuild(ctx, prebuilds, db, api.Logger, req, owner)
654-
if err != nil {
653+
claimedWorkspace, err = claimPrebuild(ctx, prebuildsClaimer, db, api.Logger, req, owner)
654+
if err != nil && !errors.Is(err, prebuilds.ErrNoClaimablePrebuiltWorkspaces) {
655655
return xerrors.Errorf("claim prebuild: %w", err)
656656
}
657657
}
@@ -683,7 +683,7 @@ func createWorkspace(
683683
} else {
684684
// Prebuild found!
685685
workspaceID = claimedWorkspace.ID
686-
initiatorID = prebuilds.Initiator()
686+
initiatorID = prebuildsClaimer.Initiator()
687687
}
688688

689689
// We have to refetch the workspace for the joined in fields.
@@ -886,11 +886,6 @@ func claimPrebuild(ctx context.Context, claimer prebuilds.Claimer, db database.S
886886
return nil, xerrors.Errorf("claim prebuild: %w", err)
887887
}
888888

889-
// No prebuild available.
890-
if claimedID == nil {
891-
return nil, nil
892-
}
893-
894889
lookup, err := db.GetWorkspaceByID(prebuildsCtx, *claimedID)
895890
if err != nil {
896891
logger.Error(ctx, "unable to find claimed workspace by ID", slog.Error(err), slog.F("claimed_prebuild_id", (*claimedID).String()))

enterprise/coderd/prebuilds/claim.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"database/sql"
66
"errors"
7-
87
"github.com/google/uuid"
98
"golang.org/x/xerrors"
109

@@ -30,8 +29,7 @@ func (_ EnterpriseClaimer) Claim(
3029
switch {
3130
// No eligible prebuilds found
3231
case errors.Is(err, sql.ErrNoRows):
33-
// Exit, this will result in a nil prebuildID being returned, which is fine
34-
return nil, nil
32+
return nil, prebuilds.ErrNoClaimablePrebuiltWorkspaces
3533
default:
3634
return nil, xerrors.Errorf("claim prebuild for user %q: %w", userID.String(), err)
3735
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy