Skip to content

Commit 90a85ff

Browse files
committed
refactor: Deprecate login_before_ready in favor of startup_script_behavior
Fixes #7758
1 parent e016c30 commit 90a85ff

35 files changed

+1213
-885
lines changed

cli/cliui/agent.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
4848
// We don't take the fast path for opts.NoWait yet because we want to
4949
// show the message.
5050
if agent.Status == codersdk.WorkspaceAgentConnected &&
51-
(agent.LoginBeforeReady || agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady) {
51+
(agent.StartupScriptBehavior == codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking || agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady) {
5252
return nil
5353
}
5454

@@ -96,7 +96,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
9696
// we do this just before starting the spinner to avoid needless
9797
// spinning.
9898
if agent.Status == codersdk.WorkspaceAgentConnected &&
99-
!agent.LoginBeforeReady && opts.NoWait {
99+
agent.StartupScriptBehavior == codersdk.WorkspaceAgentStartupScriptBehaviorBlocking && opts.NoWait {
100100
showMessage()
101101
return nil
102102
}
@@ -140,7 +140,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
140140
// NOTE(mafredri): Once we have access to the workspace agent's
141141
// startup script logs, we can show them here.
142142
// https://github.com/coder/coder/issues/2957
143-
if !agent.LoginBeforeReady && !opts.NoWait {
143+
if agent.StartupScriptBehavior == codersdk.WorkspaceAgentStartupScriptBehaviorBlocking && !opts.NoWait {
144144
switch agent.LifecycleState {
145145
case codersdk.WorkspaceAgentLifecycleReady:
146146
return nil

cli/cliui/agent_test.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func TestAgent(t *testing.T) {
3030
WorkspaceName: "example",
3131
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
3232
agent := codersdk.WorkspaceAgent{
33-
Status: codersdk.WorkspaceAgentDisconnected,
34-
LoginBeforeReady: true,
33+
Status: codersdk.WorkspaceAgentDisconnected,
34+
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking,
3535
}
3636
if disconnected.Load() {
3737
agent.Status = codersdk.WorkspaceAgentConnected
@@ -73,9 +73,9 @@ func TestAgent_TimeoutWithTroubleshootingURL(t *testing.T) {
7373
WorkspaceName: "example",
7474
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
7575
agent := codersdk.WorkspaceAgent{
76-
Status: codersdk.WorkspaceAgentConnecting,
77-
TroubleshootingURL: wantURL,
78-
LoginBeforeReady: true,
76+
Status: codersdk.WorkspaceAgentConnecting,
77+
TroubleshootingURL: wantURL,
78+
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking,
7979
}
8080
switch {
8181
case !connected.Load() && timeout.Load():
@@ -124,10 +124,10 @@ func TestAgent_StartupTimeout(t *testing.T) {
124124
WorkspaceName: "example",
125125
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
126126
agent := codersdk.WorkspaceAgent{
127-
Status: codersdk.WorkspaceAgentConnecting,
128-
LoginBeforeReady: false,
129-
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
130-
TroubleshootingURL: wantURL,
127+
Status: codersdk.WorkspaceAgentConnecting,
128+
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehaviorBlocking,
129+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
130+
TroubleshootingURL: wantURL,
131131
}
132132

133133
if s := status.Load(); s != "" {
@@ -183,10 +183,10 @@ func TestAgent_StartErrorExit(t *testing.T) {
183183
WorkspaceName: "example",
184184
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
185185
agent := codersdk.WorkspaceAgent{
186-
Status: codersdk.WorkspaceAgentConnecting,
187-
LoginBeforeReady: false,
188-
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
189-
TroubleshootingURL: wantURL,
186+
Status: codersdk.WorkspaceAgentConnecting,
187+
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehaviorBlocking,
188+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
189+
TroubleshootingURL: wantURL,
190190
}
191191

192192
if s := status.Load(); s != "" {
@@ -239,10 +239,10 @@ func TestAgent_NoWait(t *testing.T) {
239239
WorkspaceName: "example",
240240
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
241241
agent := codersdk.WorkspaceAgent{
242-
Status: codersdk.WorkspaceAgentConnecting,
243-
LoginBeforeReady: false,
244-
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
245-
TroubleshootingURL: wantURL,
242+
Status: codersdk.WorkspaceAgentConnecting,
243+
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehaviorBlocking,
244+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
245+
TroubleshootingURL: wantURL,
246246
}
247247

248248
if s := status.Load(); s != "" {
@@ -292,7 +292,7 @@ func TestAgent_NoWait(t *testing.T) {
292292
require.NoError(t, <-done, "ready - should exit early")
293293
}
294294

295-
func TestAgent_LoginBeforeReadyEnabled(t *testing.T) {
295+
func TestAgent_StartupScriptBehaviorNonBlocking(t *testing.T) {
296296
t.Parallel()
297297

298298
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
@@ -309,10 +309,10 @@ func TestAgent_LoginBeforeReadyEnabled(t *testing.T) {
309309
WorkspaceName: "example",
310310
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
311311
agent := codersdk.WorkspaceAgent{
312-
Status: codersdk.WorkspaceAgentConnecting,
313-
LoginBeforeReady: true,
314-
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
315-
TroubleshootingURL: wantURL,
312+
Status: codersdk.WorkspaceAgentConnecting,
313+
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking,
314+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
315+
TroubleshootingURL: wantURL,
316316
}
317317

318318
if s := status.Load(); s != "" {

cli/ssh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
350350
{
351351
Flag: "no-wait",
352352
Env: "CODER_SSH_NO_WAIT",
353-
Description: "Specifies whether to wait for a workspace to become ready before logging in (only applicable when the login before ready option has not been enabled). Note that the workspace agent may still be in the process of executing the startup script and the workspace may be in an incomplete state.",
353+
Description: "Specifies whether to wait for a workspace to become ready before logging in (only applicable when the startup script behavior is blocking). Note that the workspace agent may still be in the process of executing the startup script and the workspace may be in an incomplete state.",
354354
Value: clibase.BoolOf(&noWait),
355355
},
356356
{

coderd/apidoc/docs.go

+14-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+11-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbgen/generator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func WorkspaceAgent(t testing.TB, db database.Store, orig database.WorkspaceAgen
141141
ConnectionTimeoutSeconds: takeFirst(orig.ConnectionTimeoutSeconds, 3600),
142142
TroubleshootingURL: takeFirst(orig.TroubleshootingURL, "https://example.com"),
143143
MOTDFile: takeFirst(orig.TroubleshootingURL, ""),
144-
LoginBeforeReady: takeFirst(orig.LoginBeforeReady, false),
144+
StartupScriptBehavior: takeFirst(orig.StartupScriptBehavior, "non-blocking"),
145145
StartupScriptTimeoutSeconds: takeFirst(orig.StartupScriptTimeoutSeconds, 3600),
146146
})
147147
require.NoError(t, err, "insert workspace agent")

coderd/database/dump.sql

+8-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ALTER TABLE workspace_agents ADD COLUMN login_beofre_ready boolean NOT NULL;
2+
3+
UPDATE workspace_agents SET login_before_ready = CASE WHEN startup_script_behavior = 'non-blocking' THEN TRUE ELSE FALSE END;
4+
5+
ALTER TABLE workspace_agents DROP COLUMN startup_script_behavior;
6+
DROP TYPE startup_script_behavior;
7+
8+
COMMENT ON COLUMN workspace_agents.delay_login_until_ready IS 'If true, the agent will delay logins until it is ready (e.g. executing startup script has ended).';
9+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TYPE startup_script_behavior AS ENUM ('blocking', 'non-blocking');
2+
ALTER TABLE workspace_agents ADD COLUMN startup_script_behavior startup_script_behavior NOT NULL;
3+
4+
UPDATE workspace_agents SET startup_script_behavior = (CASE WHEN login_before_ready THEN 'non-blocking' ELSE 'blocking' END)::startup_script_behavior;
5+
6+
ALTER TABLE workspace_agents DROP COLUMN login_before_ready;
7+
8+
COMMENT ON COLUMN workspace_agents.startup_script_behavior IS 'When startup script behavior is non-blocking, the workspace will be ready and accessible upon agent connection, when it is blocking, workspace will wait for the startup script to complete before becoming ready and accessible.'

coderd/database/models.go

+60-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)