mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: change coder start to be a no-op if workspace is started
Fixes #11380
This commit is contained in:
+26
-11
@@ -30,18 +30,33 @@ func (r *RootCmd) start() *clibase.Cmd {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
build, err := startWorkspace(inv, client, workspace, parameterFlags, 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, "Failed to restart with the template version from your last build. Policy may require you to restart with the current active template version.")
|
||||
build, err = startWorkspace(inv, client, workspace, parameterFlags, WorkspaceUpdate)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("start workspace with active template version: %w", err)
|
||||
var build codersdk.WorkspaceBuild
|
||||
switch workspace.LatestBuild.Status {
|
||||
case codersdk.WorkspaceStatusRunning:
|
||||
_, _ = fmt.Fprintf(
|
||||
inv.Stdout, "\nThe %s workspace is already running!\n",
|
||||
cliui.Keyword(workspace.Name),
|
||||
)
|
||||
return nil
|
||||
case codersdk.WorkspaceStatusStarting:
|
||||
_, _ = fmt.Fprintf(
|
||||
inv.Stdout, "\nThe %s workspace is already starting.\n",
|
||||
cliui.Keyword(workspace.Name),
|
||||
)
|
||||
build = workspace.LatestBuild
|
||||
default:
|
||||
build, err = startWorkspace(inv, client, workspace, parameterFlags, 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, "Failed to restart with the template version from your last build. Policy may require you to restart with the current active template version.")
|
||||
build, err = startWorkspace(inv, client, workspace, parameterFlags, WorkspaceUpdate)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("start workspace with active template version: %w", err)
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, build.ID)
|
||||
|
||||
Reference in New Issue
Block a user