Skip to content

refactor: deprecate login_before_ready in favor of startup_script_behavior #7837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR fixes
  • Loading branch information
mafredri committed Jun 5, 2023
commit 011f82bbfc90495af908ecf2d192823cab899353
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BEGIN;

ALTER TABLE workspace_agents ADD COLUMN login_before_ready boolean NOT NULL DEFAULT TRUE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do we need begin & commit around this block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose yes, fixed. I'm sometimes on the fence since we're not consistent about always using them. We should probably always enforce it, can't think of a reason not to.


UPDATE workspace_agents SET login_before_ready = CASE WHEN startup_script_behavior = 'non-blocking' THEN TRUE ELSE FALSE END;
Expand All @@ -6,3 +8,5 @@ ALTER TABLE workspace_agents DROP COLUMN startup_script_behavior;
DROP TYPE startup_script_behavior;

COMMENT ON COLUMN workspace_agents.login_before_ready IS 'If true, the agent will delay logins until it is ready (e.g. executing startup script has ended).';

COMMIT;
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BEGIN;

CREATE TYPE startup_script_behavior AS ENUM ('blocking', 'non-blocking');
ALTER TABLE workspace_agents ADD COLUMN startup_script_behavior startup_script_behavior NOT NULL DEFAULT 'non-blocking';

Expand All @@ -6,3 +8,5 @@ UPDATE workspace_agents SET startup_script_behavior = (CASE WHEN login_before_re
ALTER TABLE workspace_agents DROP COLUMN login_before_ready;

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.'

COMMIT;
2 changes: 1 addition & 1 deletion coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
}
}

// Set the default in case it was not provided.
// Set the default in case it was not provided (e.g. echo provider).
if prAgent.GetStartupScriptBehavior() == "" {
prAgent.StartupScriptBehavior = string(codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking)
}
Expand Down
1 change: 1 addition & 0 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +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,
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehavior(dbAgent.StartupScriptBehavior),
StartupScriptTimeoutSeconds: dbAgent.StartupScriptTimeoutSeconds,
ShutdownScript: dbAgent.ShutdownScript.String,
Expand Down
10 changes: 6 additions & 4 deletions codersdk/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ type WorkspaceAgent struct {
Version string `json:"version"`
Apps []WorkspaceApp `json:"apps"`
// DERPLatency is mapped by region name (e.g. "New York City", "Seattle").
DERPLatency map[string]DERPRegion `json:"latency,omitempty"`
ConnectionTimeoutSeconds int32 `json:"connection_timeout_seconds"`
TroubleshootingURL string `json:"troubleshooting_url"`
StartupScriptBehavior WorkspaceAgentStartupScriptBehavior `json:"startup_script_behavior"`
DERPLatency map[string]DERPRegion `json:"latency,omitempty"`
ConnectionTimeoutSeconds int32 `json:"connection_timeout_seconds"`
TroubleshootingURL string `json:"troubleshooting_url"`
// Deprecated: Use StartupScriptBehavior instead.
LoginBeforeReady bool `json:"login_before_ready"`
StartupScriptBehavior WorkspaceAgentStartupScriptBehavior `json:"startup_script_behavior"`
// StartupScriptTimeoutSeconds is the number of seconds to wait for the startup script to complete. If the script does not complete within this time, the agent lifecycle will be marked as start_timeout.
StartupScriptTimeoutSeconds int32 `json:"startup_script_timeout_seconds"`
ShutdownScript string `json:"shutdown_script,omitempty"`
Expand Down
Loading