-
Notifications
You must be signed in to change notification settings - Fork 889
feat(cli/ssh): implement wait options and deprecate no-wait #7894
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,13 +42,15 @@ var ( | |
autostopNotifyCountdown = []time.Duration{30 * time.Minute} | ||
) | ||
|
||
//nolint:gocyclo | ||
func (r *RootCmd) ssh() *clibase.Cmd { | ||
var ( | ||
stdio bool | ||
forwardAgent bool | ||
forwardGPG bool | ||
identityAgent string | ||
wsPollInterval time.Duration | ||
waitEnum string | ||
noWait bool | ||
logDir string | ||
logToFile bool | ||
|
@@ -105,6 +107,30 @@ func (r *RootCmd) ssh() *clibase.Cmd { | |
return err | ||
} | ||
|
||
// Select the startup script behavior based on template configuration or flags. | ||
var wait bool | ||
switch waitEnum { | ||
case "yes": | ||
wait = true | ||
case "no": | ||
wait = false | ||
case "auto": | ||
switch workspaceAgent.StartupScriptBehavior { | ||
case codersdk.WorkspaceAgentStartupScriptBehaviorBlocking: | ||
wait = true | ||
case codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking: | ||
wait = false | ||
default: | ||
return xerrors.Errorf("unknown startup script behavior %q", workspaceAgent.StartupScriptBehavior) | ||
} | ||
default: | ||
return xerrors.Errorf("unknown wait value %q", waitEnum) | ||
} | ||
// The `--no-wait` flag is deprecated, but for now, check it. | ||
if noWait { | ||
wait = false | ||
} | ||
|
||
templateVersion, err := client.TemplateVersion(ctx, workspace.LatestBuild.TemplateVersionID) | ||
if err != nil { | ||
return err | ||
|
@@ -134,7 +160,7 @@ func (r *RootCmd) ssh() *clibase.Cmd { | |
Fetch: func(ctx context.Context) (codersdk.WorkspaceAgent, error) { | ||
return client.WorkspaceAgent(ctx, workspaceAgent.ID) | ||
}, | ||
NoWait: noWait, | ||
Wait: wait, | ||
}) | ||
if err != nil { | ||
if xerrors.Is(err, context.Canceled) { | ||
|
@@ -313,6 +339,13 @@ func (r *RootCmd) ssh() *clibase.Cmd { | |
return nil | ||
}, | ||
} | ||
waitOption := clibase.Option{ | ||
Flag: "wait", | ||
Env: "CODER_SSH_WAIT", | ||
Description: "Specifies whether or not to wait for the startup script to finish executing. Auto means that the agent startup script behavior configured in the workspace template is used.", | ||
Default: "auto", | ||
Value: clibase.EnumOf(&waitEnum, "yes", "no", "auto"), | ||
} | ||
cmd.Options = clibase.OptionSet{ | ||
{ | ||
Flag: "stdio", | ||
|
@@ -347,11 +380,13 @@ func (r *RootCmd) ssh() *clibase.Cmd { | |
Default: "1m", | ||
Value: clibase.DurationOf(&wsPollInterval), | ||
}, | ||
waitOption, | ||
{ | ||
Flag: "no-wait", | ||
Env: "CODER_SSH_NO_WAIT", | ||
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.", | ||
Description: "Enter workspace immediately after the agent has connected. This is the default if the template has configured the agent startup script behavior as non-blocking.", | ||
Value: clibase.BoolOf(&noWait), | ||
UseInstead: []clibase.Option{waitOption}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took me a hot second to see this as I was looking for |
||
}, | ||
{ | ||
Flag: "log-dir", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review: Before change from
NoWait -> Wait
, these were bugs, added the explicit false here to signal intent.