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

Commita8f2a8a

Browse files
authored
fix(cli): skip dry-run for workspace start/restart commands (#20754)
## ProblemThe `prepWorkspaceBuild()` function in `cli/create.go` wasunconditionally executing dry-runs for **all** workspace actions. Thiscaused unnecessary delays and "Planning workspace..." messages during`coder start` and `coder restart` commands when they should only happenduring `coder create` and `coder update`.## Root CauseThe `prepWorkspaceBuild()` function is shared code called by:- **create command** - passes `WorkspaceCreate` action ✅ dry-run ISdesired- **update command** - passes `WorkspaceUpdate` action ✅ dry-run ISdesired- **start command** - passes `WorkspaceStart` action (or`WorkspaceUpdate` as fallback) ❌ dry-run NOT desired for`WorkspaceStart`- **restart command** - passes `WorkspaceRestart` action ❌ dry-run NOTdesired- **scaletest commands** - pass `WorkspaceCreate` action ✅ dry-run ISdesired## SolutionWrapped the dry-run section (lines 580-627) in a conditional that onlyexecutes when `args.Action == WorkspaceCreate || args.Action ==WorkspaceUpdate`.This skips dry-run for `WorkspaceStart` and `WorkspaceRestart` actionswhile preserving it for creation and explicit updates.## Changes- Added conditional check around the entire dry-run logic block- Added clarifying comment explaining the intent- Changed from unconditional execution to: `if args.Action ==WorkspaceCreate || args.Action == WorkspaceUpdate { ... }`## Impact| Command | Action Type | Dry-run Before | Dry-run After | Status ||---------|-------------|----------------|---------------|--------|| `coder create` | `WorkspaceCreate` | ✅ Yes | ✅ Yes | Unchanged || `coder update` | `WorkspaceUpdate` | ✅ Yes | ✅ Yes | Unchanged || `coder start` (normal) | `WorkspaceStart` | ❌ Yes (bug) | ✅ No |**Fixed** || `coder start` (template changed) | `WorkspaceUpdate` | ✅ Yes | ✅ Yes |Unchanged (correct behavior) || `coder restart` | `WorkspaceRestart` | ❌ Yes (bug) | ✅ No | **Fixed**|| scaletest | `WorkspaceCreate` | ✅ Yes | ✅ Yes | Unchanged |## Testing✅ **Code compiles successfully**```bashgo build -o /dev/null ./cli/...```✅ **All relevant tests pass locally**```bashcd cli && go test -run "TestCreate|TestStart|TestRestart|TestUpdate" -vPASSok github.com/coder/coder/v2/cli 3.337s```✅ **All CI checks pass**- test-go-pg (ubuntu, macos, windows) ✅- test-go-pg-17 ✅- test-go-race-pg ✅- test-e2e ✅- All other checks ✅## Behavior Changes**Before:**- Users running `coder start` would see "Planning workspace..." and waitfor unnecessary dry-run completion- Users running `coder restart` would experience unnecessary dry-runoverhead**After:**- `coder start` (simple start) skips dry-run entirely (faster, moreintuitive)- `coder start` (with template update) still shows dry-run (correct -user needs to see what's changing)- `coder restart` skips dry-run entirely (faster, more intuitive)- `coder create` maintains existing dry-run behavior (shows "Planningworkspace..." and resource preview)- `coder update` maintains existing dry-run behavior (shows "Planningworkspace..." and resource preview)## VerificationManual testing should verify:1. `coder create` still shows "Planning workspace..." ✅2. `coder update` still shows "Planning workspace..." ✅3. `coder start` (simple start) does NOT show "Planning workspace..." ✅4. `coder restart` does NOT show "Planning workspace..." ✅
1 parent04727c0 commita8f2a8a

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

‎cli/create.go‎

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -577,53 +577,57 @@ func prepWorkspaceBuild(inv *serpent.Invocation, client *codersdk.Client, args p
577577
returnnil,xerrors.Errorf("template version git auth: %w",err)
578578
}
579579

580-
// Run a dry-run with the given parameters to check correctness
581-
dryRun,err:=client.CreateTemplateVersionDryRun(inv.Context(),templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
582-
WorkspaceName:args.NewWorkspaceName,
583-
RichParameterValues:buildParameters,
584-
})
585-
iferr!=nil {
586-
returnnil,xerrors.Errorf("begin workspace dry-run: %w",err)
587-
}
580+
// Only perform dry-run for workspace creation and updates
581+
// Skip for start and restart to avoid unnecessary delays
582+
ifargs.Action==WorkspaceCreate||args.Action==WorkspaceUpdate {
583+
// Run a dry-run with the given parameters to check correctness
584+
dryRun,err:=client.CreateTemplateVersionDryRun(inv.Context(),templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
585+
WorkspaceName:args.NewWorkspaceName,
586+
RichParameterValues:buildParameters,
587+
})
588+
iferr!=nil {
589+
returnnil,xerrors.Errorf("begin workspace dry-run: %w",err)
590+
}
588591

589-
matchedProvisioners,err:=client.TemplateVersionDryRunMatchedProvisioners(inv.Context(),templateVersion.ID,dryRun.ID)
590-
iferr!=nil {
591-
returnnil,xerrors.Errorf("get matched provisioners: %w",err)
592-
}
593-
cliutil.WarnMatchedProvisioners(inv.Stdout,&matchedProvisioners,dryRun)
594-
_,_=fmt.Fprintln(inv.Stdout,"Planning workspace...")
595-
err=cliui.ProvisionerJob(inv.Context(),inv.Stdout, cliui.ProvisionerJobOptions{
596-
Fetch:func() (codersdk.ProvisionerJob,error) {
597-
returnclient.TemplateVersionDryRun(inv.Context(),templateVersion.ID,dryRun.ID)
598-
},
599-
Cancel:func()error {
600-
returnclient.CancelTemplateVersionDryRun(inv.Context(),templateVersion.ID,dryRun.ID)
601-
},
602-
Logs:func() (<-chan codersdk.ProvisionerJobLog, io.Closer,error) {
603-
returnclient.TemplateVersionDryRunLogsAfter(inv.Context(),templateVersion.ID,dryRun.ID,0)
604-
},
605-
// Don't show log output for the dry-run unless there's an error.
606-
Silent:true,
607-
})
608-
iferr!=nil {
609-
// TODO (Dean): reprompt for parameter values if we deem it to
610-
// be a validation error
611-
returnnil,xerrors.Errorf("dry-run workspace: %w",err)
612-
}
592+
matchedProvisioners,err:=client.TemplateVersionDryRunMatchedProvisioners(inv.Context(),templateVersion.ID,dryRun.ID)
593+
iferr!=nil {
594+
returnnil,xerrors.Errorf("get matched provisioners: %w",err)
595+
}
596+
cliutil.WarnMatchedProvisioners(inv.Stdout,&matchedProvisioners,dryRun)
597+
_,_=fmt.Fprintln(inv.Stdout,"Planning workspace...")
598+
err=cliui.ProvisionerJob(inv.Context(),inv.Stdout, cliui.ProvisionerJobOptions{
599+
Fetch:func() (codersdk.ProvisionerJob,error) {
600+
returnclient.TemplateVersionDryRun(inv.Context(),templateVersion.ID,dryRun.ID)
601+
},
602+
Cancel:func()error {
603+
returnclient.CancelTemplateVersionDryRun(inv.Context(),templateVersion.ID,dryRun.ID)
604+
},
605+
Logs:func() (<-chan codersdk.ProvisionerJobLog, io.Closer,error) {
606+
returnclient.TemplateVersionDryRunLogsAfter(inv.Context(),templateVersion.ID,dryRun.ID,0)
607+
},
608+
// Don't show log output for the dry-run unless there's an error.
609+
Silent:true,
610+
})
611+
iferr!=nil {
612+
// TODO (Dean): reprompt for parameter values if we deem it to
613+
// be a validation error
614+
returnnil,xerrors.Errorf("dry-run workspace: %w",err)
615+
}
613616

614-
resources,err:=client.TemplateVersionDryRunResources(inv.Context(),templateVersion.ID,dryRun.ID)
615-
iferr!=nil {
616-
returnnil,xerrors.Errorf("get workspace dry-run resources: %w",err)
617-
}
617+
resources,err:=client.TemplateVersionDryRunResources(inv.Context(),templateVersion.ID,dryRun.ID)
618+
iferr!=nil {
619+
returnnil,xerrors.Errorf("get workspace dry-run resources: %w",err)
620+
}
618621

619-
err=cliui.WorkspaceResources(inv.Stdout,resources, cliui.WorkspaceResourcesOptions{
620-
WorkspaceName:args.NewWorkspaceName,
621-
// Since agents haven't connected yet, hiding this makes more sense.
622-
HideAgentState:true,
623-
Title:"Workspace Preview",
624-
})
625-
iferr!=nil {
626-
returnnil,xerrors.Errorf("get resources: %w",err)
622+
err=cliui.WorkspaceResources(inv.Stdout,resources, cliui.WorkspaceResourcesOptions{
623+
WorkspaceName:args.NewWorkspaceName,
624+
// Since agents haven't connected yet, hiding this makes more sense.
625+
HideAgentState:true,
626+
Title:"Workspace Preview",
627+
})
628+
iferr!=nil {
629+
returnnil,xerrors.Errorf("get resources: %w",err)
630+
}
627631
}
628632

629633
returnbuildParameters,nil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp