Skip to content

Commit 981cac5

Browse files
authored
chore: Invert delay_login_until_ready, now login_before_ready (#5893)
1 parent 8a5760a commit 981cac5

35 files changed

+392
-337
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/me
494494
cd site
495495
yarn run format:write:only ../docs/admin/prometheus.md
496496

497-
docs/cli/coder.md: scripts/clidocgen/main.go $(shell find ./cli/ -type f)
497+
docs/cli/coder.md: scripts/clidocgen/main.go $(GO_SRC_FILES) docs/manifest.json
498498
BASE_PATH="." go run scripts/clidocgen/main.go
499499
cd site
500-
yarn run format:write:only ../docs/cli/**.md
500+
yarn run format:write:only ../docs/cli/*.md ../docs/manifest.json
501501

502502
docs/admin/audit-logs.md: scripts/auditdocgen/main.go enterprise/audit/table.go
503503
go run scripts/auditdocgen/main.go

cli/cliui/agent.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
4545
// We don't take the fast path for opts.NoWait yet because we want to
4646
// show the message.
4747
if agent.Status == codersdk.WorkspaceAgentConnected &&
48-
(!agent.DelayLoginUntilReady || agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady) {
48+
(agent.LoginBeforeReady || agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady) {
4949
return nil
5050
}
5151

@@ -93,7 +93,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
9393
// we do this just before starting the spinner to avoid needless
9494
// spinning.
9595
if agent.Status == codersdk.WorkspaceAgentConnected &&
96-
agent.DelayLoginUntilReady && opts.NoWait {
96+
!agent.LoginBeforeReady && opts.NoWait {
9797
showMessage()
9898
return nil
9999
}
@@ -137,7 +137,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
137137
// NOTE(mafredri): Once we have access to the workspace agent's
138138
// startup script logs, we can show them here.
139139
// https://github.com/coder/coder/issues/2957
140-
if agent.DelayLoginUntilReady && !opts.NoWait {
140+
if !agent.LoginBeforeReady && !opts.NoWait {
141141
switch agent.LifecycleState {
142142
case codersdk.WorkspaceAgentLifecycleReady:
143143
return nil
@@ -176,7 +176,7 @@ func waitingMessage(agent codersdk.WorkspaceAgent, opts AgentOptions) (m *messag
176176
Prompt: "Don't panic, your workspace is booting up!",
177177
}
178178
defer func() {
179-
if opts.NoWait {
179+
if agent.Status == codersdk.WorkspaceAgentConnected && opts.NoWait {
180180
m.Spin = ""
181181
}
182182
if m.Spin != "" {

cli/cliui/agent_test.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -30,7 +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,
33+
Status: codersdk.WorkspaceAgentDisconnected,
34+
LoginBeforeReady: true,
3435
}
3536
if disconnected.Load() {
3637
agent.Status = codersdk.WorkspaceAgentConnected
@@ -73,6 +74,7 @@ func TestAgent_TimeoutWithTroubleshootingURL(t *testing.T) {
7374
agent := codersdk.WorkspaceAgent{
7475
Status: codersdk.WorkspaceAgentConnecting,
7576
TroubleshootingURL: wantURL,
77+
LoginBeforeReady: true,
7678
}
7779
switch {
7880
case !connected.Load() && timeout.Load():
@@ -119,10 +121,10 @@ func TestAgent_StartupTimeout(t *testing.T) {
119121
WorkspaceName: "example",
120122
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
121123
agent := codersdk.WorkspaceAgent{
122-
Status: codersdk.WorkspaceAgentConnecting,
123-
DelayLoginUntilReady: true,
124-
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
125-
TroubleshootingURL: wantURL,
124+
Status: codersdk.WorkspaceAgentConnecting,
125+
LoginBeforeReady: false,
126+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
127+
TroubleshootingURL: wantURL,
126128
}
127129

128130
if s := status.Load(); s != "" {
@@ -177,10 +179,10 @@ func TestAgent_StartErrorExit(t *testing.T) {
177179
WorkspaceName: "example",
178180
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
179181
agent := codersdk.WorkspaceAgent{
180-
Status: codersdk.WorkspaceAgentConnecting,
181-
DelayLoginUntilReady: true,
182-
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
183-
TroubleshootingURL: wantURL,
182+
Status: codersdk.WorkspaceAgentConnecting,
183+
LoginBeforeReady: false,
184+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
185+
TroubleshootingURL: wantURL,
184186
}
185187

186188
if s := status.Load(); s != "" {
@@ -232,10 +234,10 @@ func TestAgent_NoWait(t *testing.T) {
232234
WorkspaceName: "example",
233235
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
234236
agent := codersdk.WorkspaceAgent{
235-
Status: codersdk.WorkspaceAgentConnecting,
236-
DelayLoginUntilReady: true,
237-
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
238-
TroubleshootingURL: wantURL,
237+
Status: codersdk.WorkspaceAgentConnecting,
238+
LoginBeforeReady: false,
239+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
240+
TroubleshootingURL: wantURL,
239241
}
240242

241243
if s := status.Load(); s != "" {
@@ -284,7 +286,7 @@ func TestAgent_NoWait(t *testing.T) {
284286
require.NoError(t, <-done, "ready - should exit early")
285287
}
286288

287-
func TestAgent_DelayLoginUntilReadyDisabled(t *testing.T) {
289+
func TestAgent_LoginBeforeReadyEnabled(t *testing.T) {
288290
t.Parallel()
289291

290292
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
@@ -301,10 +303,10 @@ func TestAgent_DelayLoginUntilReadyDisabled(t *testing.T) {
301303
WorkspaceName: "example",
302304
Fetch: func(_ context.Context) (codersdk.WorkspaceAgent, error) {
303305
agent := codersdk.WorkspaceAgent{
304-
Status: codersdk.WorkspaceAgentConnecting,
305-
DelayLoginUntilReady: false,
306-
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
307-
TroubleshootingURL: wantURL,
306+
Status: codersdk.WorkspaceAgentConnecting,
307+
LoginBeforeReady: true,
308+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
309+
TroubleshootingURL: wantURL,
308310
}
309311

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

cli/cliui/resources_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestWorkspaceResources(t *testing.T) {
2626
Agents: []codersdk.WorkspaceAgent{{
2727
Name: "dev",
2828
Status: codersdk.WorkspaceAgentConnected,
29+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
2930
Architecture: "amd64",
3031
OperatingSystem: "linux",
3132
}},
@@ -60,6 +61,7 @@ func TestWorkspaceResources(t *testing.T) {
6061
Agents: []codersdk.WorkspaceAgent{{
6162
CreatedAt: database.Now().Add(-10 * time.Second),
6263
Status: codersdk.WorkspaceAgentConnecting,
64+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
6365
Name: "dev",
6466
OperatingSystem: "linux",
6567
Architecture: "amd64",
@@ -70,12 +72,14 @@ func TestWorkspaceResources(t *testing.T) {
7072
Name: "dev",
7173
Agents: []codersdk.WorkspaceAgent{{
7274
Status: codersdk.WorkspaceAgentConnected,
75+
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
7376
Name: "go",
7477
Architecture: "amd64",
7578
OperatingSystem: "linux",
7679
}, {
7780
DisconnectedAt: &disconnected,
7881
Status: codersdk.WorkspaceAgentDisconnected,
82+
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
7983
Name: "postgres",
8084
Architecture: "amd64",
8185
OperatingSystem: "linux",

cli/ssh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func ssh() *cobra.Command {
250250
cliflag.BoolVarP(cmd.Flags(), &forwardGPG, "forward-gpg", "G", "CODER_SSH_FORWARD_GPG", false, "Specifies whether to forward the GPG agent. Unsupported on Windows workspaces, but supports all clients. Requires gnupg (gpg, gpgconf) on both the client and workspace. The GPG agent must already be running locally and will not be started for you. If a GPG agent is already running in the workspace, it will be attempted to be killed.")
251251
cliflag.StringVarP(cmd.Flags(), &identityAgent, "identity-agent", "", "CODER_SSH_IDENTITY_AGENT", "", "Specifies which identity agent to use (overrides $SSH_AUTH_SOCK), forward agent must also be enabled")
252252
cliflag.DurationVarP(cmd.Flags(), &wsPollInterval, "workspace-poll-interval", "", "CODER_WORKSPACE_POLL_INTERVAL", workspacePollInterval, "Specifies how often to poll for workspace automated shutdown.")
253-
cliflag.BoolVarP(cmd.Flags(), &noWait, "no-wait", "", "CODER_SSH_NO_WAIT", false, "Specifies whether to wait for a workspace to become ready before logging in (only applicable when the delay login until ready option is 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.")
253+
cliflag.BoolVarP(cmd.Flags(), &noWait, "no-wait", "", "CODER_SSH_NO_WAIT", false, "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.")
254254
return cmd
255255
}
256256

cli/testdata/coder_ssh_--help.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Flags:
2222
Consumes $CODER_SSH_IDENTITY_AGENT
2323
--no-wait Specifies whether to wait for a workspace to become
2424
ready before logging in (only applicable when the
25-
delay login until ready option is enabled). Note
26-
that the workspace agent may still be in the
25+
login before ready option has not been enabled).
26+
Note that the workspace agent may still be in the
2727
process of executing the startup script and the
2828
workspace may be in an incomplete state.
2929
Consumes $CODER_SSH_NO_WAIT

cmd/cliui/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ func main() {
163163
Use: "agent",
164164
RunE: func(cmd *cobra.Command, args []string) error {
165165
agent := codersdk.WorkspaceAgent{
166-
Status: codersdk.WorkspaceAgentDisconnected,
166+
Status: codersdk.WorkspaceAgentDisconnected,
167+
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
167168
}
168169
go func() {
169170
time.Sleep(3 * time.Second)
@@ -203,6 +204,7 @@ func main() {
203204
Agents: []codersdk.WorkspaceAgent{{
204205
CreatedAt: database.Now().Add(-10 * time.Second),
205206
Status: codersdk.WorkspaceAgentConnecting,
207+
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
206208
Name: "dev",
207209
OperatingSystem: "linux",
208210
Architecture: "amd64",
@@ -213,12 +215,14 @@ func main() {
213215
Name: "dev",
214216
Agents: []codersdk.WorkspaceAgent{{
215217
Status: codersdk.WorkspaceAgentConnected,
218+
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
216219
Name: "go",
217220
Architecture: "amd64",
218221
OperatingSystem: "linux",
219222
}, {
220223
DisconnectedAt: &disconnected,
221224
Status: codersdk.WorkspaceAgentDisconnected,
225+
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
222226
Name: "postgres",
223227
Architecture: "amd64",
224228
OperatingSystem: "linux",

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/database/dump.sql

+2-2
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,8 @@
1+
BEGIN;
2+
ALTER TABLE workspace_agents RENAME COLUMN login_before_ready TO delay_login_until_ready;
3+
ALTER TABLE workspace_agents ALTER COLUMN delay_login_until_ready SET DEFAULT false;
4+
5+
UPDATE workspace_agents SET delay_login_until_ready = NOT delay_login_until_ready;
6+
7+
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).';
8+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
BEGIN;
2+
ALTER TABLE workspace_agents RENAME COLUMN delay_login_until_ready TO login_before_ready;
3+
ALTER TABLE workspace_agents ALTER COLUMN login_before_ready SET DEFAULT true;
4+
5+
UPDATE workspace_agents SET login_before_ready = NOT login_before_ready;
6+
7+
COMMENT ON COLUMN workspace_agents.login_before_ready IS 'If true, the agent will not prevent login before it is ready (e.g. startup script is still executing).';
8+
COMMIT;

coderd/database/models.go

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

0 commit comments

Comments
 (0)