Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita78f0fc

Browse files
refactor: use specific error for agpl and prebuilds (#17591)
Follow-up PR to#17458Addresses this discussion:#17458 (comment)
1 parent1da27a1 commita78f0fc

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

‎coderd/prebuilds/api.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import (
99
"github.com/coder/coder/v2/coderd/database"
1010
)
1111

12-
varErrNoClaimablePrebuiltWorkspaces=xerrors.New("no claimable prebuilt workspaces found")
12+
var (
13+
ErrNoClaimablePrebuiltWorkspaces=xerrors.New("no claimable prebuilt workspaces found")
14+
ErrAGPLDoesNotSupportPrebuiltWorkspaces=xerrors.New("prebuilt workspaces functionality is not supported under the AGPL license")
15+
)
1316

1417
// ReconciliationOrchestrator manages the lifecycle of prebuild reconciliation.
1518
// It runs a continuous loop to check and reconcile prebuild states, and can be stopped gracefully.

‎coderd/prebuilds/noop.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type NoopClaimer struct{}
2727

2828
func (NoopClaimer)Claim(context.Context, uuid.UUID,string, uuid.UUID) (*uuid.UUID,error) {
2929
// Not entitled to claim prebuilds in AGPL version.
30-
returnnil,ErrNoClaimablePrebuiltWorkspaces
30+
returnnil,ErrAGPLDoesNotSupportPrebuiltWorkspaces
3131
}
3232

3333
func (NoopClaimer)Initiator() uuid.UUID {

‎coderd/workspaces.go‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,28 @@ func createWorkspace(
650650
ifreq.TemplateVersionPresetID!=uuid.Nil {
651651
// Try and claim an eligible prebuild, if available.
652652
claimedWorkspace,err=claimPrebuild(ctx,prebuildsClaimer,db,api.Logger,req,owner)
653-
iferr!=nil&&!errors.Is(err,prebuilds.ErrNoClaimablePrebuiltWorkspaces) {
654-
returnxerrors.Errorf("claim prebuild: %w",err)
653+
// If claiming fails with an expected error (no claimable prebuilds or AGPL does not support prebuilds),
654+
// we fall back to creating a new workspace. Otherwise, propagate the unexpected error.
655+
iferr!=nil {
656+
isExpectedError:=errors.Is(err,prebuilds.ErrNoClaimablePrebuiltWorkspaces)||
657+
errors.Is(err,prebuilds.ErrAGPLDoesNotSupportPrebuiltWorkspaces)
658+
fields:= []any{
659+
slog.Error(err),
660+
slog.F("workspace_name",req.Name),
661+
slog.F("template_version_preset_id",req.TemplateVersionPresetID),
662+
}
663+
664+
if!isExpectedError {
665+
// if it's an unexpected error - use error log level
666+
api.Logger.Error(ctx,"failed to claim prebuilt workspace",fields...)
667+
668+
returnxerrors.Errorf("failed to claim prebuilt workspace: %w",err)
669+
}
670+
671+
// if it's an expected error - use warn log level
672+
api.Logger.Warn(ctx,"failed to claim prebuilt workspace",fields...)
673+
674+
// fall back to creating a new workspace
655675
}
656676
}
657677

‎enterprise/coderd/prebuilds/claim_test.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func TestClaimPrebuild(t *testing.T) {
111111
markPrebuildsClaimable:true,
112112
claimingErr:agplprebuilds.ErrNoClaimablePrebuiltWorkspaces,
113113
},
114+
"AGPL does not support prebuilds error is returned": {
115+
expectPrebuildClaimed:false,
116+
markPrebuildsClaimable:true,
117+
claimingErr:agplprebuilds.ErrAGPLDoesNotSupportPrebuiltWorkspaces,
118+
},
114119
"unexpected claiming error is returned": {
115120
expectPrebuildClaimed:false,
116121
markPrebuildsClaimable:true,
@@ -224,8 +229,11 @@ func TestClaimPrebuild(t *testing.T) {
224229
TemplateVersionPresetID:presets[0].ID,
225230
})
226231

232+
isNoPrebuiltWorkspaces:=errors.Is(tc.claimingErr,agplprebuilds.ErrNoClaimablePrebuiltWorkspaces)
233+
isUnsupported:=errors.Is(tc.claimingErr,agplprebuilds.ErrAGPLDoesNotSupportPrebuiltWorkspaces)
234+
227235
switch {
228-
casetc.claimingErr!=nil&&errors.Is(tc.claimingErr,agplprebuilds.ErrNoClaimablePrebuiltWorkspaces):
236+
casetc.claimingErr!=nil&&(isNoPrebuiltWorkspaces||isUnsupported):
229237
require.NoError(t,err)
230238
coderdtest.AwaitWorkspaceBuildJobCompleted(t,userClient,userWorkspace.LatestBuild.ID)
231239

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp