mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
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
This commit is contained in:
committed by
GitHub
parent
39e3b049a5
commit
b240799f47
@ -16,10 +16,8 @@ import (
|
|||||||
|
|
||||||
"github.com/coder/coder/v2/cli/clibase"
|
"github.com/coder/coder/v2/cli/clibase"
|
||||||
"github.com/coder/coder/v2/cli/cliui"
|
"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/coderd/util/ptr"
|
||||||
"github.com/coder/coder/v2/codersdk"
|
"github.com/coder/coder/v2/codersdk"
|
||||||
"github.com/coder/coder/v2/provisionerd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *RootCmd) templateCreate() *clibase.Cmd {
|
func (r *RootCmd) templateCreate() *clibase.Cmd {
|
||||||
@ -111,7 +109,7 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
|
|||||||
Message: message,
|
Message: message,
|
||||||
Client: client,
|
Client: client,
|
||||||
Organization: organization,
|
Organization: organization,
|
||||||
Provisioner: database.ProvisionerType(provisioner),
|
Provisioner: codersdk.ProvisionerType(provisioner),
|
||||||
FileID: resp.ID,
|
FileID: resp.ID,
|
||||||
ProvisionerTags: tags,
|
ProvisionerTags: tags,
|
||||||
VariablesFile: variablesFile,
|
VariablesFile: variablesFile,
|
||||||
@ -224,7 +222,7 @@ type createValidTemplateVersionArgs struct {
|
|||||||
Message string
|
Message string
|
||||||
Client *codersdk.Client
|
Client *codersdk.Client
|
||||||
Organization codersdk.Organization
|
Organization codersdk.Organization
|
||||||
Provisioner database.ProvisionerType
|
Provisioner codersdk.ProvisionerType
|
||||||
FileID uuid.UUID
|
FileID uuid.UUID
|
||||||
|
|
||||||
VariablesFile string
|
VariablesFile string
|
||||||
@ -258,7 +256,7 @@ func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplat
|
|||||||
Message: args.Message,
|
Message: args.Message,
|
||||||
StorageMethod: codersdk.ProvisionerStorageMethodFile,
|
StorageMethod: codersdk.ProvisionerStorageMethodFile,
|
||||||
FileID: args.FileID,
|
FileID: args.FileID,
|
||||||
Provisioner: codersdk.ProvisionerType(args.Provisioner),
|
Provisioner: args.Provisioner,
|
||||||
ProvisionerTags: args.ProvisionerTags,
|
ProvisionerTags: args.ProvisionerTags,
|
||||||
UserVariableValues: variableValues,
|
UserVariableValues: variableValues,
|
||||||
}
|
}
|
||||||
@ -284,7 +282,10 @@ func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplat
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var jobErr *cliui.ProvisionerJobError
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
"github.com/coder/coder/v2/cli/clibase"
|
"github.com/coder/coder/v2/cli/clibase"
|
||||||
"github.com/coder/coder/v2/cli/cliui"
|
"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/codersdk"
|
||||||
"github.com/coder/coder/v2/provisionersdk"
|
"github.com/coder/coder/v2/provisionersdk"
|
||||||
)
|
)
|
||||||
@ -216,7 +215,7 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
|
|||||||
Message: message,
|
Message: message,
|
||||||
Client: client,
|
Client: client,
|
||||||
Organization: organization,
|
Organization: organization,
|
||||||
Provisioner: database.ProvisionerType(provisioner),
|
Provisioner: codersdk.ProvisionerType(provisioner),
|
||||||
FileID: resp.ID,
|
FileID: resp.ID,
|
||||||
ProvisionerTags: tags,
|
ProvisionerTags: tags,
|
||||||
VariablesFile: variablesFile,
|
VariablesFile: variablesFile,
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"nhooyr.io/websocket"
|
"nhooyr.io/websocket"
|
||||||
|
|
||||||
"github.com/coder/coder/v2/provisionerd/proto"
|
"github.com/coder/coder/v2/provisionerd/proto"
|
||||||
|
"github.com/coder/coder/v2/provisionerd/runner"
|
||||||
"github.com/coder/coder/v2/provisionersdk"
|
"github.com/coder/coder/v2/provisionersdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -72,6 +73,12 @@ const (
|
|||||||
RequiredTemplateVariables JobErrorCode = "REQUIRED_TEMPLATE_VARIABLES"
|
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.
|
// ProvisionerJob describes the job executed by the provisioning daemon.
|
||||||
type ProvisionerJob struct {
|
type ProvisionerJob struct {
|
||||||
ID uuid.UUID `json:"id" format:"uuid"`
|
ID uuid.UUID `json:"id" format:"uuid"`
|
||||||
|
@ -29,12 +29,6 @@ import (
|
|||||||
"github.com/coder/retry"
|
"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.
|
// Dialer represents the function to create a daemon client connection.
|
||||||
type Dialer func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error)
|
type Dialer func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user