Skip to content

Commit b240799

Browse files
authored
refactor(cli): use codersdk for provisioner types (#9508)
This change removes one use of `coderd/database` from the slim binary and more correctly uses codersdk instead of database or provisionerd packages. No size change (yet). Ref: #9380
1 parent 39e3b04 commit b240799

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

cli/templatecreate.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ import (
1616

1717
"github.com/coder/coder/v2/cli/clibase"
1818
"github.com/coder/coder/v2/cli/cliui"
19-
"github.com/coder/coder/v2/coderd/database"
2019
"github.com/coder/coder/v2/coderd/util/ptr"
2120
"github.com/coder/coder/v2/codersdk"
22-
"github.com/coder/coder/v2/provisionerd"
2321
)
2422

2523
func (r *RootCmd) templateCreate() *clibase.Cmd {
@@ -111,7 +109,7 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
111109
Message: message,
112110
Client: client,
113111
Organization: organization,
114-
Provisioner: database.ProvisionerType(provisioner),
112+
Provisioner: codersdk.ProvisionerType(provisioner),
115113
FileID: resp.ID,
116114
ProvisionerTags: tags,
117115
VariablesFile: variablesFile,
@@ -224,7 +222,7 @@ type createValidTemplateVersionArgs struct {
224222
Message string
225223
Client *codersdk.Client
226224
Organization codersdk.Organization
227-
Provisioner database.ProvisionerType
225+
Provisioner codersdk.ProvisionerType
228226
FileID uuid.UUID
229227

230228
VariablesFile string
@@ -258,7 +256,7 @@ func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplat
258256
Message: args.Message,
259257
StorageMethod: codersdk.ProvisionerStorageMethodFile,
260258
FileID: args.FileID,
261-
Provisioner: codersdk.ProvisionerType(args.Provisioner),
259+
Provisioner: args.Provisioner,
262260
ProvisionerTags: args.ProvisionerTags,
263261
UserVariableValues: variableValues,
264262
}
@@ -284,7 +282,10 @@ func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplat
284282
})
285283
if err != nil {
286284
var jobErr *cliui.ProvisionerJobError
287-
if errors.As(err, &jobErr) && !provisionerd.IsMissingParameterErrorCode(string(jobErr.Code)) {
285+
if errors.As(err, &jobErr) && !codersdk.JobIsMissingParameterErrorCode(jobErr.Code) {
286+
return nil, err
287+
}
288+
if err != nil {
288289
return nil, err
289290
}
290291
}

cli/templatepush.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/coder/coder/v2/cli/clibase"
1515
"github.com/coder/coder/v2/cli/cliui"
16-
"github.com/coder/coder/v2/coderd/database"
1716
"github.com/coder/coder/v2/codersdk"
1817
"github.com/coder/coder/v2/provisionersdk"
1918
)
@@ -216,7 +215,7 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
216215
Message: message,
217216
Client: client,
218217
Organization: organization,
219-
Provisioner: database.ProvisionerType(provisioner),
218+
Provisioner: codersdk.ProvisionerType(provisioner),
220219
FileID: resp.ID,
221220
ProvisionerTags: tags,
222221
VariablesFile: variablesFile,

codersdk/provisionerdaemons.go

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"nhooyr.io/websocket"
1818

1919
"github.com/coder/coder/v2/provisionerd/proto"
20+
"github.com/coder/coder/v2/provisionerd/runner"
2021
"github.com/coder/coder/v2/provisionersdk"
2122
)
2223

@@ -72,6 +73,12 @@ const (
7273
RequiredTemplateVariables JobErrorCode = "REQUIRED_TEMPLATE_VARIABLES"
7374
)
7475

76+
// JobIsMissingParameterErrorCode returns whether the error is a missing parameter error.
77+
// This can indicate to consumers that they should check parameters.
78+
func JobIsMissingParameterErrorCode(code JobErrorCode) bool {
79+
return string(code) == runner.MissingParameterErrorCode
80+
}
81+
7582
// ProvisionerJob describes the job executed by the provisioning daemon.
7683
type ProvisionerJob struct {
7784
ID uuid.UUID `json:"id" format:"uuid"`

provisionerd/provisionerd.go

-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ import (
2929
"github.com/coder/retry"
3030
)
3131

32-
// IsMissingParameterErrorCode returns whether the error is a missing parameter error.
33-
// This can indicate to consumers that they should check parameters.
34-
func IsMissingParameterErrorCode(code string) bool {
35-
return code == runner.MissingParameterErrorCode
36-
}
37-
3832
// Dialer represents the function to create a daemon client connection.
3933
type Dialer func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error)
4034

0 commit comments

Comments
 (0)