Skip to content

refactor(cli): use codersdk for provisioner types #9508

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 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
refactor(cli): use codersdk for provisioner types
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
  • Loading branch information
mafredri committed Sep 4, 2023
commit eeeebbb681a83f89f7ba95b4a1de758edc1a899e
11 changes: 6 additions & 5 deletions cli/templatecreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import (

"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/provisionerd"
)

func (r *RootCmd) templateCreate() *clibase.Cmd {
Expand Down Expand Up @@ -111,7 +109,7 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
Message: message,
Client: client,
Organization: organization,
Provisioner: database.ProvisionerType(provisioner),
Provisioner: codersdk.ProvisionerType(provisioner),
FileID: resp.ID,
ProvisionerTags: tags,
VariablesFile: variablesFile,
Expand Down Expand Up @@ -224,7 +222,7 @@ type createValidTemplateVersionArgs struct {
Message string
Client *codersdk.Client
Organization codersdk.Organization
Provisioner database.ProvisionerType
Provisioner codersdk.ProvisionerType
FileID uuid.UUID

VariablesFile string
Expand Down Expand Up @@ -284,7 +282,10 @@ func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplat
})
if err != nil {
var jobErr *cliui.ProvisionerJobError
if errors.As(err, &jobErr) && !provisionerd.IsMissingParameterErrorCode(string(jobErr.Code)) {
if errors.As(err, &jobErr) && !codersdk.JobIsMissingParameterErrorCode(jobErr.Code) {
return nil, err
}
if err != nil {
return nil, err
}
}
Expand Down
3 changes: 1 addition & 2 deletions cli/templatepush.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/provisionersdk"
)
Expand Down Expand Up @@ -216,7 +215,7 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
Message: message,
Client: client,
Organization: organization,
Provisioner: database.ProvisionerType(provisioner),
Provisioner: codersdk.ProvisionerType(provisioner),
FileID: resp.ID,
ProvisionerTags: tags,
VariablesFile: variablesFile,
Expand Down
7 changes: 7 additions & 0 deletions codersdk/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"nhooyr.io/websocket"

"github.com/coder/coder/v2/provisionerd/proto"
"github.com/coder/coder/v2/provisionerd/runner"
"github.com/coder/coder/v2/provisionersdk"
)

Expand Down Expand Up @@ -72,6 +73,12 @@ const (
RequiredTemplateVariables JobErrorCode = "REQUIRED_TEMPLATE_VARIABLES"
)

// JobIsMissingParameterErrorCode returns whether the error is a missing parameter error.
// This can indicate to consumers that they should check parameters.
func JobIsMissingParameterErrorCode(code JobErrorCode) bool {
return string(code) == runner.MissingParameterErrorCode
}

// ProvisionerJob describes the job executed by the provisioning daemon.
type ProvisionerJob struct {
ID uuid.UUID `json:"id" format:"uuid"`
Expand Down
6 changes: 0 additions & 6 deletions provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ import (
"github.com/coder/retry"
)

// IsMissingParameterErrorCode returns whether the error is a missing parameter error.
// This can indicate to consumers that they should check parameters.
func IsMissingParameterErrorCode(code string) bool {
return code == runner.MissingParameterErrorCode
}

// Dialer represents the function to create a daemon client connection.
type Dialer func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error)

Expand Down