From d55a2e5717cdeb06da3eef3d5e7172b2bfa82690 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 9 Jun 2023 12:37:17 +0000 Subject: [PATCH] fix(codersdk): Handle API older than client for startup script behavior --- coderd/workspaceagents.go | 2 +- codersdk/workspaceagents.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/coderd/workspaceagents.go b/coderd/workspaceagents.go index cc05ecc73d3ef..b881e337906ba 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -1126,7 +1126,7 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin ConnectionTimeoutSeconds: dbAgent.ConnectionTimeoutSeconds, TroubleshootingURL: troubleshootingURL, LifecycleState: codersdk.WorkspaceAgentLifecycle(dbAgent.LifecycleState), - LoginBeforeReady: dbAgent.StartupScriptBehavior == database.StartupScriptBehaviorNonBlocking, + LoginBeforeReady: dbAgent.StartupScriptBehavior != database.StartupScriptBehaviorBlocking, StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehavior(dbAgent.StartupScriptBehavior), StartupScriptTimeoutSeconds: dbAgent.StartupScriptTimeoutSeconds, ShutdownScript: dbAgent.ShutdownScript.String, diff --git a/codersdk/workspaceagents.go b/codersdk/workspaceagents.go index dcede6a069f4f..b99185bd7cc8d 100644 --- a/codersdk/workspaceagents.go +++ b/codersdk/workspaceagents.go @@ -375,7 +375,18 @@ func (c *Client) WorkspaceAgent(ctx context.Context, id uuid.UUID) (WorkspaceAge return WorkspaceAgent{}, ReadBodyAsError(res) } var workspaceAgent WorkspaceAgent - return workspaceAgent, json.NewDecoder(res.Body).Decode(&workspaceAgent) + err = json.NewDecoder(res.Body).Decode(&workspaceAgent) + if err != nil { + return WorkspaceAgent{}, err + } + // Backwards compatibility for cases where the API is older then the client. + if workspaceAgent.StartupScriptBehavior == "" { + workspaceAgent.StartupScriptBehavior = WorkspaceAgentStartupScriptBehaviorNonBlocking + if !workspaceAgent.LoginBeforeReady { + workspaceAgent.StartupScriptBehavior = WorkspaceAgentStartupScriptBehaviorBlocking + } + } + return workspaceAgent, nil } type IssueReconnectingPTYSignedTokenRequest struct {