From 0c7ddb0ab4bcac344a2d818cf11ad91574700311 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 4 Sep 2024 12:56:07 +0100 Subject: [PATCH 1/2] feat(cli): add --debug-provisioner argument --- cli/delete.go | 14 ++++++++++--- cli/parameter.go | 17 ++++++++++++++++ cli/restart.go | 18 ++++++++++++----- cli/ssh.go | 4 ++-- cli/start.go | 25 ++++++++++++++++-------- cli/stop.go | 11 +++++++++-- cli/testdata/coder_delete_--help.golden | 5 +++++ cli/testdata/coder_restart_--help.golden | 5 +++++ cli/testdata/coder_start_--help.golden | 5 +++++ cli/testdata/coder_stop_--help.golden | 5 +++++ cli/testdata/coder_update_--help.golden | 5 +++++ cli/update.go | 9 ++++++--- docs/reference/cli/delete.md | 8 ++++++++ docs/reference/cli/restart.md | 8 ++++++++ docs/reference/cli/start.md | 8 ++++++++ docs/reference/cli/stop.md | 8 ++++++++ docs/reference/cli/update.md | 8 ++++++++ scripts/develop.sh | 2 +- 18 files changed, 141 insertions(+), 24 deletions(-) diff --git a/cli/delete.go b/cli/delete.go index 174205afe2be2..60cffd82ea937 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -11,7 +11,10 @@ import ( // nolint func (r *RootCmd) deleteWorkspace() *serpent.Command { - var orphan bool + var ( + orphan bool + buildDebug buildDebugFlags + ) client := new(codersdk.Client) cmd := &serpent.Command{ Annotations: workspaceCommand, @@ -40,11 +43,15 @@ func (r *RootCmd) deleteWorkspace() *serpent.Command { } var state []byte - build, err := client.CreateWorkspaceBuild(inv.Context(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{ + req := codersdk.CreateWorkspaceBuildRequest{ Transition: codersdk.WorkspaceTransitionDelete, ProvisionerState: state, Orphan: orphan, - }) + } + if buildDebug.provisioner { + req.LogLevel = codersdk.ProvisionerLogLevelDebug + } + build, err := client.CreateWorkspaceBuild(inv.Context(), workspace.ID, req) if err != nil { return err } @@ -71,5 +78,6 @@ func (r *RootCmd) deleteWorkspace() *serpent.Command { }, cliui.SkipPromptOption(), } + cmd.Options = append(cmd.Options, buildDebug.cliOptions()...) return cmd } diff --git a/cli/parameter.go b/cli/parameter.go index e9b1ca581a5f5..eedffe48d18b9 100644 --- a/cli/parameter.go +++ b/cli/parameter.go @@ -127,3 +127,20 @@ func parseParameterMapFile(parameterFile string) (map[string]string, error) { } return parameterMap, nil } + +// buildDebugFlags contains options relating to troubleshooting build issues. +type buildDebugFlags struct { + provisioner bool +} + +func (bdf *buildDebugFlags) cliOptions() []serpent.Option { + return []serpent.Option{ + { + Flag: "debug-provisioner", + Description: `Sets the provisioner log level to debug. +This will print additional information about the build process. +This is useful for troubleshooting build issues.`, + Value: serpent.BoolOf(&bdf.provisioner), + }, + } +} diff --git a/cli/restart.go b/cli/restart.go index 54ce658f8f0dc..2ee19cd35e79e 100644 --- a/cli/restart.go +++ b/cli/restart.go @@ -14,7 +14,10 @@ import ( ) func (r *RootCmd) restart() *serpent.Command { - var parameterFlags workspaceParameterFlags + var ( + parameterFlags workspaceParameterFlags + debugFlags buildDebugFlags + ) client := new(codersdk.Client) cmd := &serpent.Command{ @@ -35,7 +38,7 @@ func (r *RootCmd) restart() *serpent.Command { return err } - startReq, err := buildWorkspaceStartRequest(inv, client, workspace, parameterFlags, WorkspaceRestart) + startReq, err := buildWorkspaceStartRequest(inv, client, workspace, parameterFlags, debugFlags, WorkspaceRestart) if err != nil { return err } @@ -48,9 +51,13 @@ func (r *RootCmd) restart() *serpent.Command { return err } - build, err := client.CreateWorkspaceBuild(ctx, workspace.ID, codersdk.CreateWorkspaceBuildRequest{ + wbr := codersdk.CreateWorkspaceBuildRequest{ Transition: codersdk.WorkspaceTransitionStop, - }) + } + if debugFlags.provisioner { + wbr.LogLevel = codersdk.ProvisionerLogLevelDebug + } + build, err := client.CreateWorkspaceBuild(ctx, workspace.ID, wbr) if err != nil { return err } @@ -65,7 +72,7 @@ func (r *RootCmd) restart() *serpent.Command { // workspaces with the active version. if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusForbidden { _, _ = fmt.Fprintln(inv.Stdout, "Unable to restart the workspace with the template version from the last build. Policy may require you to restart with the current active template version.") - build, err = startWorkspace(inv, client, workspace, parameterFlags, WorkspaceUpdate) + build, err = startWorkspace(inv, client, workspace, parameterFlags, debugFlags, WorkspaceUpdate) if err != nil { return xerrors.Errorf("start workspace with active template version: %w", err) } @@ -87,6 +94,7 @@ func (r *RootCmd) restart() *serpent.Command { } cmd.Options = append(cmd.Options, parameterFlags.allOptions()...) + cmd.Options = append(cmd.Options, debugFlags.cliOptions()...) return cmd } diff --git a/cli/ssh.go b/cli/ssh.go index 1d75f1015e242..43da928f64c3f 100644 --- a/cli/ssh.go +++ b/cli/ssh.go @@ -649,9 +649,9 @@ func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client * // It's possible for a workspace build to fail due to the template requiring starting // workspaces with the active version. _, _ = fmt.Fprintf(inv.Stderr, "Workspace was stopped, starting workspace to allow connecting to %q...\n", workspace.Name) - _, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, WorkspaceStart) + _, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, buildDebugFlags{}, WorkspaceStart) if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusForbidden { - _, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, WorkspaceUpdate) + _, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, buildDebugFlags{}, WorkspaceUpdate) if err != nil { return codersdk.Workspace{}, codersdk.WorkspaceAgent{}, xerrors.Errorf("start workspace with active template version: %w", err) } diff --git a/cli/start.go b/cli/start.go index 89f15b95c42f3..8836bc43fa08b 100644 --- a/cli/start.go +++ b/cli/start.go @@ -13,7 +13,10 @@ import ( ) func (r *RootCmd) start() *serpent.Command { - var parameterFlags workspaceParameterFlags + var ( + parameterFlags workspaceParameterFlags + debugFlags buildDebugFlags + ) client := new(codersdk.Client) cmd := &serpent.Command{ @@ -45,12 +48,12 @@ func (r *RootCmd) start() *serpent.Command { ) build = workspace.LatestBuild default: - build, err = startWorkspace(inv, client, workspace, parameterFlags, WorkspaceStart) + build, err = startWorkspace(inv, client, workspace, parameterFlags, debugFlags, WorkspaceStart) // It's possible for a workspace build to fail due to the template requiring starting // workspaces with the active version. if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusForbidden { _, _ = fmt.Fprintln(inv.Stdout, "Unable to start the workspace with the template version from the last build. Policy may require you to restart with the current active template version.") - build, err = startWorkspace(inv, client, workspace, parameterFlags, WorkspaceUpdate) + build, err = startWorkspace(inv, client, workspace, parameterFlags, debugFlags, WorkspaceUpdate) if err != nil { return xerrors.Errorf("start workspace with active template version: %w", err) } @@ -73,11 +76,12 @@ func (r *RootCmd) start() *serpent.Command { } cmd.Options = append(cmd.Options, parameterFlags.allOptions()...) + cmd.Options = append(cmd.Options, debugFlags.cliOptions()...) return cmd } -func buildWorkspaceStartRequest(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, action WorkspaceCLIAction) (codersdk.CreateWorkspaceBuildRequest, error) { +func buildWorkspaceStartRequest(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, debugFlags buildDebugFlags, action WorkspaceCLIAction) (codersdk.CreateWorkspaceBuildRequest, error) { version := workspace.LatestBuild.TemplateVersionID if workspace.AutomaticUpdates == codersdk.AutomaticUpdatesAlways || action == WorkspaceUpdate { @@ -124,14 +128,19 @@ func buildWorkspaceStartRequest(inv *serpent.Invocation, client *codersdk.Client return codersdk.CreateWorkspaceBuildRequest{}, err } - return codersdk.CreateWorkspaceBuildRequest{ + wbr := codersdk.CreateWorkspaceBuildRequest{ Transition: codersdk.WorkspaceTransitionStart, RichParameterValues: buildParameters, TemplateVersionID: version, - }, nil + } + if debugFlags.provisioner { + wbr.LogLevel = codersdk.ProvisionerLogLevelDebug + } + + return wbr, nil } -func startWorkspace(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, action WorkspaceCLIAction) (codersdk.WorkspaceBuild, error) { +func startWorkspace(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, debugFlags buildDebugFlags, action WorkspaceCLIAction) (codersdk.WorkspaceBuild, error) { if workspace.DormantAt != nil { _, _ = fmt.Fprintln(inv.Stdout, "Activating dormant workspace...") err := client.UpdateWorkspaceDormancy(inv.Context(), workspace.ID, codersdk.UpdateWorkspaceDormancy{ @@ -141,7 +150,7 @@ func startWorkspace(inv *serpent.Invocation, client *codersdk.Client, workspace return codersdk.WorkspaceBuild{}, xerrors.Errorf("activate workspace: %w", err) } } - req, err := buildWorkspaceStartRequest(inv, client, workspace, parameterFlags, action) + req, err := buildWorkspaceStartRequest(inv, client, workspace, parameterFlags, debugFlags, action) if err != nil { return codersdk.WorkspaceBuild{}, err } diff --git a/cli/stop.go b/cli/stop.go index 890f0275801f1..6397b43781664 100644 --- a/cli/stop.go +++ b/cli/stop.go @@ -10,6 +10,7 @@ import ( ) func (r *RootCmd) stop() *serpent.Command { + var debugFlags buildDebugFlags client := new(codersdk.Client) cmd := &serpent.Command{ Annotations: workspaceCommand, @@ -35,9 +36,13 @@ func (r *RootCmd) stop() *serpent.Command { if err != nil { return err } - build, err := client.CreateWorkspaceBuild(inv.Context(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{ + wbr := codersdk.CreateWorkspaceBuildRequest{ Transition: codersdk.WorkspaceTransitionStop, - }) + } + if debugFlags.provisioner { + wbr.LogLevel = codersdk.ProvisionerLogLevelDebug + } + build, err := client.CreateWorkspaceBuild(inv.Context(), workspace.ID, wbr) if err != nil { return err } @@ -56,5 +61,7 @@ func (r *RootCmd) stop() *serpent.Command { return nil }, } + cmd.Options = append(cmd.Options, debugFlags.cliOptions()...) + return cmd } diff --git a/cli/testdata/coder_delete_--help.golden b/cli/testdata/coder_delete_--help.golden index 3f9800f135840..29fe237b82fe7 100644 --- a/cli/testdata/coder_delete_--help.golden +++ b/cli/testdata/coder_delete_--help.golden @@ -8,6 +8,11 @@ USAGE: Aliases: rm OPTIONS: + --debug-provisioner bool + Sets the provisioner log level to debug. + This will print additional information about the build process. + This is useful for troubleshooting build issues. + --orphan bool Delete a workspace without deleting its resources. This can delete a workspace in a broken state, but may also lead to unaccounted cloud diff --git a/cli/testdata/coder_restart_--help.golden b/cli/testdata/coder_restart_--help.golden index b0b036929cc9a..bc24346eae1c5 100644 --- a/cli/testdata/coder_restart_--help.golden +++ b/cli/testdata/coder_restart_--help.golden @@ -16,6 +16,11 @@ OPTIONS: --build-options bool Prompt for one-time build options defined with ephemeral parameters. + --debug-provisioner bool + Sets the provisioner log level to debug. + This will print additional information about the build process. + This is useful for troubleshooting build issues. + --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". diff --git a/cli/testdata/coder_start_--help.golden b/cli/testdata/coder_start_--help.golden index 4985930b624d2..6e003ff560372 100644 --- a/cli/testdata/coder_start_--help.golden +++ b/cli/testdata/coder_start_--help.golden @@ -16,6 +16,11 @@ OPTIONS: --build-options bool Prompt for one-time build options defined with ephemeral parameters. + --debug-provisioner bool + Sets the provisioner log level to debug. + This will print additional information about the build process. + This is useful for troubleshooting build issues. + --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". diff --git a/cli/testdata/coder_stop_--help.golden b/cli/testdata/coder_stop_--help.golden index 529c38484668e..7d5be290f778d 100644 --- a/cli/testdata/coder_stop_--help.golden +++ b/cli/testdata/coder_stop_--help.golden @@ -6,6 +6,11 @@ USAGE: Stop a workspace OPTIONS: + --debug-provisioner bool + Sets the provisioner log level to debug. + This will print additional information about the build process. + This is useful for troubleshooting build issues. + -y, --yes bool Bypass prompts. diff --git a/cli/testdata/coder_update_--help.golden b/cli/testdata/coder_update_--help.golden index bff90868468ab..f125bbeceada6 100644 --- a/cli/testdata/coder_update_--help.golden +++ b/cli/testdata/coder_update_--help.golden @@ -18,6 +18,11 @@ OPTIONS: --build-options bool Prompt for one-time build options defined with ephemeral parameters. + --debug-provisioner bool + Sets the provisioner log level to debug. + This will print additional information about the build process. + This is useful for troubleshooting build issues. + --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". diff --git a/cli/update.go b/cli/update.go index 1465db716d073..723532a7a4ed3 100644 --- a/cli/update.go +++ b/cli/update.go @@ -10,8 +10,10 @@ import ( ) func (r *RootCmd) update() *serpent.Command { - var parameterFlags workspaceParameterFlags - + var ( + parameterFlags workspaceParameterFlags + debugFlags buildDebugFlags + ) client := new(codersdk.Client) cmd := &serpent.Command{ Annotations: workspaceCommand, @@ -32,7 +34,7 @@ func (r *RootCmd) update() *serpent.Command { return nil } - build, err := startWorkspace(inv, client, workspace, parameterFlags, WorkspaceUpdate) + build, err := startWorkspace(inv, client, workspace, parameterFlags, debugFlags, WorkspaceUpdate) if err != nil { return xerrors.Errorf("start workspace: %w", err) } @@ -54,5 +56,6 @@ func (r *RootCmd) update() *serpent.Command { } cmd.Options = append(cmd.Options, parameterFlags.allOptions()...) + cmd.Options = append(cmd.Options, debugFlags.cliOptions()...) return cmd } diff --git a/docs/reference/cli/delete.md b/docs/reference/cli/delete.md index 7ea5eb0839042..46eaac75e662d 100644 --- a/docs/reference/cli/delete.md +++ b/docs/reference/cli/delete.md @@ -31,3 +31,11 @@ Delete a workspace without deleting its resources. This can delete a workspace i | Type | bool | Bypass prompts. + +### --debug-provisioner + +| | | +| ---- | ----------------- | +| Type | bool | + +Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/docs/reference/cli/restart.md b/docs/reference/cli/restart.md index 215917a8e0d22..f7c9c1e852efc 100644 --- a/docs/reference/cli/restart.md +++ b/docs/reference/cli/restart.md @@ -71,3 +71,11 @@ Rich parameter default values in the format "name=value". | Type | bool | Always prompt all parameters. Does not pull parameter values from existing workspace. + +### --debug-provisioner + +| | | +| ---- | ----------------- | +| Type | bool | + +Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/docs/reference/cli/start.md b/docs/reference/cli/start.md index 0852ec5b57400..4447f856b702c 100644 --- a/docs/reference/cli/start.md +++ b/docs/reference/cli/start.md @@ -71,3 +71,11 @@ Rich parameter default values in the format "name=value". | Type | bool | Always prompt all parameters. Does not pull parameter values from existing workspace. + +### --debug-provisioner + +| | | +| ---- | ----------------- | +| Type | bool | + +Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/docs/reference/cli/stop.md b/docs/reference/cli/stop.md index 65197a2cdbb66..4079e4acfba36 100644 --- a/docs/reference/cli/stop.md +++ b/docs/reference/cli/stop.md @@ -19,3 +19,11 @@ coder stop [flags] | Type | bool | Bypass prompts. + +### --debug-provisioner + +| | | +| ---- | ----------------- | +| Type | bool | + +Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/docs/reference/cli/update.md b/docs/reference/cli/update.md index 562d32f8fd960..2158ded1eed73 100644 --- a/docs/reference/cli/update.md +++ b/docs/reference/cli/update.md @@ -69,3 +69,11 @@ Rich parameter default values in the format "name=value". | Type | bool | Always prompt all parameters. Does not pull parameter values from existing workspace. + +### --debug-provisioner + +| | | +| ---- | ----------------- | +| Type | bool | + +Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/scripts/develop.sh b/scripts/develop.sh index 51f6ded4b96f5..bdaf81c7536e5 100755 --- a/scripts/develop.sh +++ b/scripts/develop.sh @@ -150,7 +150,7 @@ fatal() { trap 'fatal "Script encountered an error"' ERR cdroot - DEBUG_DELVE="${debug}" start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true "$@" + DEBUG_DELVE="${debug}" start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true --enable-terraform-debug-mode "$@" echo '== Waiting for Coder to become ready' # Start the timeout in the background so interrupting this script From 1213553f76ed87ef51f58e5810e08220ae91f23e Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 4 Sep 2024 14:18:35 +0100 Subject: [PATCH 2/2] address PR comments --- cli/delete.go | 8 ++++---- cli/parameter.go | 13 +++++++------ cli/restart.go | 10 +++++----- cli/ssh.go | 4 ++-- cli/start.go | 16 ++++++++-------- cli/stop.go | 6 +++--- cli/testdata/coder_delete_--help.golden | 5 ----- cli/testdata/coder_restart_--help.golden | 5 ----- cli/testdata/coder_start_--help.golden | 5 ----- cli/testdata/coder_stop_--help.golden | 5 ----- cli/testdata/coder_update_--help.golden | 5 ----- cli/update.go | 6 +++--- docs/reference/cli/delete.md | 8 -------- docs/reference/cli/restart.md | 8 -------- docs/reference/cli/start.md | 8 -------- docs/reference/cli/stop.md | 8 -------- docs/reference/cli/update.md | 8 -------- 17 files changed, 32 insertions(+), 96 deletions(-) diff --git a/cli/delete.go b/cli/delete.go index 60cffd82ea937..42abca658623a 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -12,8 +12,8 @@ import ( // nolint func (r *RootCmd) deleteWorkspace() *serpent.Command { var ( - orphan bool - buildDebug buildDebugFlags + orphan bool + prov buildFlags ) client := new(codersdk.Client) cmd := &serpent.Command{ @@ -48,7 +48,7 @@ func (r *RootCmd) deleteWorkspace() *serpent.Command { ProvisionerState: state, Orphan: orphan, } - if buildDebug.provisioner { + if prov.provisionerLogDebug { req.LogLevel = codersdk.ProvisionerLogLevelDebug } build, err := client.CreateWorkspaceBuild(inv.Context(), workspace.ID, req) @@ -78,6 +78,6 @@ func (r *RootCmd) deleteWorkspace() *serpent.Command { }, cliui.SkipPromptOption(), } - cmd.Options = append(cmd.Options, buildDebug.cliOptions()...) + cmd.Options = append(cmd.Options, prov.cliOptions()...) return cmd } diff --git a/cli/parameter.go b/cli/parameter.go index eedffe48d18b9..2c09e9bbefc33 100644 --- a/cli/parameter.go +++ b/cli/parameter.go @@ -128,19 +128,20 @@ func parseParameterMapFile(parameterFile string) (map[string]string, error) { return parameterMap, nil } -// buildDebugFlags contains options relating to troubleshooting build issues. -type buildDebugFlags struct { - provisioner bool +// buildFlags contains options relating to troubleshooting provisioner jobs. +type buildFlags struct { + provisionerLogDebug bool } -func (bdf *buildDebugFlags) cliOptions() []serpent.Option { +func (bf *buildFlags) cliOptions() []serpent.Option { return []serpent.Option{ { - Flag: "debug-provisioner", + Flag: "provisioner-log-debug", Description: `Sets the provisioner log level to debug. This will print additional information about the build process. This is useful for troubleshooting build issues.`, - Value: serpent.BoolOf(&bdf.provisioner), + Value: serpent.BoolOf(&bf.provisionerLogDebug), + Hidden: true, }, } } diff --git a/cli/restart.go b/cli/restart.go index 2ee19cd35e79e..156f506105c5a 100644 --- a/cli/restart.go +++ b/cli/restart.go @@ -16,7 +16,7 @@ import ( func (r *RootCmd) restart() *serpent.Command { var ( parameterFlags workspaceParameterFlags - debugFlags buildDebugFlags + bflags buildFlags ) client := new(codersdk.Client) @@ -38,7 +38,7 @@ func (r *RootCmd) restart() *serpent.Command { return err } - startReq, err := buildWorkspaceStartRequest(inv, client, workspace, parameterFlags, debugFlags, WorkspaceRestart) + startReq, err := buildWorkspaceStartRequest(inv, client, workspace, parameterFlags, bflags, WorkspaceRestart) if err != nil { return err } @@ -54,7 +54,7 @@ func (r *RootCmd) restart() *serpent.Command { wbr := codersdk.CreateWorkspaceBuildRequest{ Transition: codersdk.WorkspaceTransitionStop, } - if debugFlags.provisioner { + if bflags.provisionerLogDebug { wbr.LogLevel = codersdk.ProvisionerLogLevelDebug } build, err := client.CreateWorkspaceBuild(ctx, workspace.ID, wbr) @@ -72,7 +72,7 @@ func (r *RootCmd) restart() *serpent.Command { // workspaces with the active version. if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusForbidden { _, _ = fmt.Fprintln(inv.Stdout, "Unable to restart the workspace with the template version from the last build. Policy may require you to restart with the current active template version.") - build, err = startWorkspace(inv, client, workspace, parameterFlags, debugFlags, WorkspaceUpdate) + build, err = startWorkspace(inv, client, workspace, parameterFlags, bflags, WorkspaceUpdate) if err != nil { return xerrors.Errorf("start workspace with active template version: %w", err) } @@ -94,7 +94,7 @@ func (r *RootCmd) restart() *serpent.Command { } cmd.Options = append(cmd.Options, parameterFlags.allOptions()...) - cmd.Options = append(cmd.Options, debugFlags.cliOptions()...) + cmd.Options = append(cmd.Options, bflags.cliOptions()...) return cmd } diff --git a/cli/ssh.go b/cli/ssh.go index 43da928f64c3f..7d9d2368de2f9 100644 --- a/cli/ssh.go +++ b/cli/ssh.go @@ -649,9 +649,9 @@ func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client * // It's possible for a workspace build to fail due to the template requiring starting // workspaces with the active version. _, _ = fmt.Fprintf(inv.Stderr, "Workspace was stopped, starting workspace to allow connecting to %q...\n", workspace.Name) - _, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, buildDebugFlags{}, WorkspaceStart) + _, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, buildFlags{}, WorkspaceStart) if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusForbidden { - _, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, buildDebugFlags{}, WorkspaceUpdate) + _, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, buildFlags{}, WorkspaceUpdate) if err != nil { return codersdk.Workspace{}, codersdk.WorkspaceAgent{}, xerrors.Errorf("start workspace with active template version: %w", err) } diff --git a/cli/start.go b/cli/start.go index 8836bc43fa08b..da2d394d12846 100644 --- a/cli/start.go +++ b/cli/start.go @@ -15,7 +15,7 @@ import ( func (r *RootCmd) start() *serpent.Command { var ( parameterFlags workspaceParameterFlags - debugFlags buildDebugFlags + bflags buildFlags ) client := new(codersdk.Client) @@ -48,12 +48,12 @@ func (r *RootCmd) start() *serpent.Command { ) build = workspace.LatestBuild default: - build, err = startWorkspace(inv, client, workspace, parameterFlags, debugFlags, WorkspaceStart) + build, err = startWorkspace(inv, client, workspace, parameterFlags, bflags, WorkspaceStart) // It's possible for a workspace build to fail due to the template requiring starting // workspaces with the active version. if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusForbidden { _, _ = fmt.Fprintln(inv.Stdout, "Unable to start the workspace with the template version from the last build. Policy may require you to restart with the current active template version.") - build, err = startWorkspace(inv, client, workspace, parameterFlags, debugFlags, WorkspaceUpdate) + build, err = startWorkspace(inv, client, workspace, parameterFlags, bflags, WorkspaceUpdate) if err != nil { return xerrors.Errorf("start workspace with active template version: %w", err) } @@ -76,12 +76,12 @@ func (r *RootCmd) start() *serpent.Command { } cmd.Options = append(cmd.Options, parameterFlags.allOptions()...) - cmd.Options = append(cmd.Options, debugFlags.cliOptions()...) + cmd.Options = append(cmd.Options, bflags.cliOptions()...) return cmd } -func buildWorkspaceStartRequest(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, debugFlags buildDebugFlags, action WorkspaceCLIAction) (codersdk.CreateWorkspaceBuildRequest, error) { +func buildWorkspaceStartRequest(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, buildFlags buildFlags, action WorkspaceCLIAction) (codersdk.CreateWorkspaceBuildRequest, error) { version := workspace.LatestBuild.TemplateVersionID if workspace.AutomaticUpdates == codersdk.AutomaticUpdatesAlways || action == WorkspaceUpdate { @@ -133,14 +133,14 @@ func buildWorkspaceStartRequest(inv *serpent.Invocation, client *codersdk.Client RichParameterValues: buildParameters, TemplateVersionID: version, } - if debugFlags.provisioner { + if buildFlags.provisionerLogDebug { wbr.LogLevel = codersdk.ProvisionerLogLevelDebug } return wbr, nil } -func startWorkspace(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, debugFlags buildDebugFlags, action WorkspaceCLIAction) (codersdk.WorkspaceBuild, error) { +func startWorkspace(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, buildFlags buildFlags, action WorkspaceCLIAction) (codersdk.WorkspaceBuild, error) { if workspace.DormantAt != nil { _, _ = fmt.Fprintln(inv.Stdout, "Activating dormant workspace...") err := client.UpdateWorkspaceDormancy(inv.Context(), workspace.ID, codersdk.UpdateWorkspaceDormancy{ @@ -150,7 +150,7 @@ func startWorkspace(inv *serpent.Invocation, client *codersdk.Client, workspace return codersdk.WorkspaceBuild{}, xerrors.Errorf("activate workspace: %w", err) } } - req, err := buildWorkspaceStartRequest(inv, client, workspace, parameterFlags, debugFlags, action) + req, err := buildWorkspaceStartRequest(inv, client, workspace, parameterFlags, buildFlags, action) if err != nil { return codersdk.WorkspaceBuild{}, err } diff --git a/cli/stop.go b/cli/stop.go index 6397b43781664..9aec5950c292b 100644 --- a/cli/stop.go +++ b/cli/stop.go @@ -10,7 +10,7 @@ import ( ) func (r *RootCmd) stop() *serpent.Command { - var debugFlags buildDebugFlags + var bflags buildFlags client := new(codersdk.Client) cmd := &serpent.Command{ Annotations: workspaceCommand, @@ -39,7 +39,7 @@ func (r *RootCmd) stop() *serpent.Command { wbr := codersdk.CreateWorkspaceBuildRequest{ Transition: codersdk.WorkspaceTransitionStop, } - if debugFlags.provisioner { + if bflags.provisionerLogDebug { wbr.LogLevel = codersdk.ProvisionerLogLevelDebug } build, err := client.CreateWorkspaceBuild(inv.Context(), workspace.ID, wbr) @@ -61,7 +61,7 @@ func (r *RootCmd) stop() *serpent.Command { return nil }, } - cmd.Options = append(cmd.Options, debugFlags.cliOptions()...) + cmd.Options = append(cmd.Options, bflags.cliOptions()...) return cmd } diff --git a/cli/testdata/coder_delete_--help.golden b/cli/testdata/coder_delete_--help.golden index 29fe237b82fe7..3f9800f135840 100644 --- a/cli/testdata/coder_delete_--help.golden +++ b/cli/testdata/coder_delete_--help.golden @@ -8,11 +8,6 @@ USAGE: Aliases: rm OPTIONS: - --debug-provisioner bool - Sets the provisioner log level to debug. - This will print additional information about the build process. - This is useful for troubleshooting build issues. - --orphan bool Delete a workspace without deleting its resources. This can delete a workspace in a broken state, but may also lead to unaccounted cloud diff --git a/cli/testdata/coder_restart_--help.golden b/cli/testdata/coder_restart_--help.golden index bc24346eae1c5..b0b036929cc9a 100644 --- a/cli/testdata/coder_restart_--help.golden +++ b/cli/testdata/coder_restart_--help.golden @@ -16,11 +16,6 @@ OPTIONS: --build-options bool Prompt for one-time build options defined with ephemeral parameters. - --debug-provisioner bool - Sets the provisioner log level to debug. - This will print additional information about the build process. - This is useful for troubleshooting build issues. - --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". diff --git a/cli/testdata/coder_start_--help.golden b/cli/testdata/coder_start_--help.golden index 6e003ff560372..4985930b624d2 100644 --- a/cli/testdata/coder_start_--help.golden +++ b/cli/testdata/coder_start_--help.golden @@ -16,11 +16,6 @@ OPTIONS: --build-options bool Prompt for one-time build options defined with ephemeral parameters. - --debug-provisioner bool - Sets the provisioner log level to debug. - This will print additional information about the build process. - This is useful for troubleshooting build issues. - --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". diff --git a/cli/testdata/coder_stop_--help.golden b/cli/testdata/coder_stop_--help.golden index 7d5be290f778d..529c38484668e 100644 --- a/cli/testdata/coder_stop_--help.golden +++ b/cli/testdata/coder_stop_--help.golden @@ -6,11 +6,6 @@ USAGE: Stop a workspace OPTIONS: - --debug-provisioner bool - Sets the provisioner log level to debug. - This will print additional information about the build process. - This is useful for troubleshooting build issues. - -y, --yes bool Bypass prompts. diff --git a/cli/testdata/coder_update_--help.golden b/cli/testdata/coder_update_--help.golden index f125bbeceada6..bff90868468ab 100644 --- a/cli/testdata/coder_update_--help.golden +++ b/cli/testdata/coder_update_--help.golden @@ -18,11 +18,6 @@ OPTIONS: --build-options bool Prompt for one-time build options defined with ephemeral parameters. - --debug-provisioner bool - Sets the provisioner log level to debug. - This will print additional information about the build process. - This is useful for troubleshooting build issues. - --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". diff --git a/cli/update.go b/cli/update.go index 723532a7a4ed3..cf4ec5e1b6c39 100644 --- a/cli/update.go +++ b/cli/update.go @@ -12,7 +12,7 @@ import ( func (r *RootCmd) update() *serpent.Command { var ( parameterFlags workspaceParameterFlags - debugFlags buildDebugFlags + bflags buildFlags ) client := new(codersdk.Client) cmd := &serpent.Command{ @@ -34,7 +34,7 @@ func (r *RootCmd) update() *serpent.Command { return nil } - build, err := startWorkspace(inv, client, workspace, parameterFlags, debugFlags, WorkspaceUpdate) + build, err := startWorkspace(inv, client, workspace, parameterFlags, bflags, WorkspaceUpdate) if err != nil { return xerrors.Errorf("start workspace: %w", err) } @@ -56,6 +56,6 @@ func (r *RootCmd) update() *serpent.Command { } cmd.Options = append(cmd.Options, parameterFlags.allOptions()...) - cmd.Options = append(cmd.Options, debugFlags.cliOptions()...) + cmd.Options = append(cmd.Options, bflags.cliOptions()...) return cmd } diff --git a/docs/reference/cli/delete.md b/docs/reference/cli/delete.md index 46eaac75e662d..7ea5eb0839042 100644 --- a/docs/reference/cli/delete.md +++ b/docs/reference/cli/delete.md @@ -31,11 +31,3 @@ Delete a workspace without deleting its resources. This can delete a workspace i | Type | bool | Bypass prompts. - -### --debug-provisioner - -| | | -| ---- | ----------------- | -| Type | bool | - -Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/docs/reference/cli/restart.md b/docs/reference/cli/restart.md index f7c9c1e852efc..215917a8e0d22 100644 --- a/docs/reference/cli/restart.md +++ b/docs/reference/cli/restart.md @@ -71,11 +71,3 @@ Rich parameter default values in the format "name=value". | Type | bool | Always prompt all parameters. Does not pull parameter values from existing workspace. - -### --debug-provisioner - -| | | -| ---- | ----------------- | -| Type | bool | - -Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/docs/reference/cli/start.md b/docs/reference/cli/start.md index 4447f856b702c..0852ec5b57400 100644 --- a/docs/reference/cli/start.md +++ b/docs/reference/cli/start.md @@ -71,11 +71,3 @@ Rich parameter default values in the format "name=value". | Type | bool | Always prompt all parameters. Does not pull parameter values from existing workspace. - -### --debug-provisioner - -| | | -| ---- | ----------------- | -| Type | bool | - -Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/docs/reference/cli/stop.md b/docs/reference/cli/stop.md index 4079e4acfba36..65197a2cdbb66 100644 --- a/docs/reference/cli/stop.md +++ b/docs/reference/cli/stop.md @@ -19,11 +19,3 @@ coder stop [flags] | Type | bool | Bypass prompts. - -### --debug-provisioner - -| | | -| ---- | ----------------- | -| Type | bool | - -Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues. diff --git a/docs/reference/cli/update.md b/docs/reference/cli/update.md index 2158ded1eed73..562d32f8fd960 100644 --- a/docs/reference/cli/update.md +++ b/docs/reference/cli/update.md @@ -69,11 +69,3 @@ Rich parameter default values in the format "name=value". | Type | bool | Always prompt all parameters. Does not pull parameter values from existing workspace. - -### --debug-provisioner - -| | | -| ---- | ----------------- | -| Type | bool | - -Sets the provisioner log level to debug.
This will print additional information about the build process.
This is useful for troubleshooting build issues.