Skip to content

feat(cli/configssh): add support for wait yes/no/auto #7893

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 8, 2023

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Jun 7, 2023

This PR adds support for wait/no-wait and also for flag option serialization into the config file, like ssh options provided via -o.

Refs #7768
Depends on #7894

mafredri added a commit that referenced this pull request Jun 7, 2023
@mafredri mafredri force-pushed the mafredri/feat-cli-configssh-add-wait-no-wait branch from 6494ad9 to a47b44c Compare June 7, 2023 12:49
@mafredri mafredri force-pushed the mafredri/feat-cli-configssh-add-wait-no-wait branch from a47b44c to f4ec444 Compare June 7, 2023 12:53
mafredri added a commit that referenced this pull request Jun 7, 2023
@mafredri mafredri changed the title feat(cli): Add wait and no-wait support to config-ssh feat(cli): add wait and no-wait support to config-ssh Jun 7, 2023
mafredri added a commit that referenced this pull request Jun 7, 2023
mafredri added a commit that referenced this pull request Jun 7, 2023
@mafredri mafredri marked this pull request as ready for review June 7, 2023 14:35
@mafredri mafredri requested a review from Emyrk June 7, 2023 14:35
cli/configssh.go Outdated
Comment on lines 544 to 553
Flag: "wait",
Env: "CODER_CONFIGSSH_WAIT", // Not to be mixed with CODER_SSH_WAIT.
Description: "Set the option to wait for the the startup script to finish executing. This is the default if the template has configured the agent startup script behavior as blocking. Can not be used together with --no-wait.",
Value: clibase.BoolOf(&sshConfigOpts.wait),
},
{
Flag: "no-wait",
Env: "CODER_CONFIGSSH_NO_WAIT", // Not to be mixed with CODER_SSH_NO_WAIT.
Description: "Set the option to 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. Can not be used together with --wait.",
Value: clibase.BoolOf(&sshConfigOpts.noWait),
Copy link
Member

Choose a reason for hiding this comment

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

Should we deprecate one of these options?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a valid thing to point out, however, both are needed because depending on the agent configuration, you may want to use the opposite of what is configured.

If we only used --wait and --wait=false, for instance, we would still need to detect the presence of this flag. I.e. we can't simply check the boolean, we have to check if the flag/env was provided so that we know whether or not to override the template. We also can't say on the CLI what the default value for this flag is because it's workspace dependent.

I'm not sure clibase easily provides this info and I also think it's bad UX to require =false (or true). 🤔

For most clarity, this should perhaps be --startup-script-behavior=auto|blocking|non-blocking, but again, not very UX friendly.

Copy link
Member

Choose a reason for hiding this comment

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

Just throwing ideas about, but how about --wait=(always|never|auto) (default=auto)? That equates to the same as --startup-script-behaviour and is arguably easier to manage than --wait vs --no-wait, at the cost of a little more typing.

Copy link
Member Author

@mafredri mafredri Jun 7, 2023

Choose a reason for hiding this comment

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

It's a great suggestion. What do you think @bpmct?

I would amend this to be --wait=yes|no|auto, this way it's less typing, and could even support shorthand in the future like -w y.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried implementing it here: 5e8c487 (#7894), I like it.

Copy link
Member

Choose a reason for hiding this comment

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

I like this too.

@mafredri mafredri changed the title feat(cli): add wait and no-wait support to config-ssh feat(cli/config-ssh): add wait yes/no/auto and and deprecate no-wait Jun 7, 2023
@mafredri mafredri changed the title feat(cli/config-ssh): add wait yes/no/auto and and deprecate no-wait feat(cli/config-ssh): add support for wait yes/no/auto Jun 7, 2023
@mafredri mafredri changed the title feat(cli/config-ssh): add support for wait yes/no/auto feat(cli/configssh): add support for wait yes/no/auto Jun 7, 2023
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

LGTM.

Would be nice if auto was an actual enum type, but I get it.
One day Golang will figure out proper enums...

Comment on lines -48 to +50
sshOptions []string
waitEnum string
userHostPrefix string
sshOptions []string
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines +221 to +223
if sshConfigOpts.waitEnum != "auto" && skipProxyCommand {
return xerrors.Errorf("cannot specify both --skip-proxy-command and --wait")
}
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, but for anyone reading this code for the first time, maybe include a comment on this that says something like:

// The waitEnum is a flag applied to the ProxyCommand. If the user specifies skipProxyCommand
// then the waitEnum flag is not used.

Just took me a second to remember what SkipProxyCommand did.

@@ -505,9 +527,16 @@ func (r *RootCmd) configSSH() *clibase.Cmd {
},
{
Flag: "ssh-host-prefix",
Env: "",
Env: "CODER_CONFIGSSH_SSH_HOST_PREFIX",
Copy link
Member

Choose a reason for hiding this comment

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

👍

@mafredri mafredri enabled auto-merge (squash) June 8, 2023 13:56
@mafredri mafredri merged commit a1c3295 into main Jun 8, 2023
@mafredri mafredri deleted the mafredri/feat-cli-configssh-add-wait-no-wait branch June 8, 2023 14:06
@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants