Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Generalize console control #623

Merged
merged 1 commit into from
Nov 27, 2019

Conversation

MikaelSmith
Copy link
Contributor

@MikaelSmith MikaelSmith commented Nov 26, 2019

Sometimes a plugin needs control of the console for a prompt it doesn't make directly. Get control before calling all primitives that take a context (as a proxy for potential network activity or execs).

This isn't entirely safe. If it's backgrounded and prompts for input it may not exit cleanly. Using plugin.Prompt guards against this issue.

Fixes #297.

Signed-off-by: Michael Smith [email protected]

@MikaelSmith MikaelSmith requested a review from a team November 26, 2019 19:45
@ghost ghost requested review from ekinanp and removed request for a team November 26, 2019 19:46
@ekinanp
Copy link
Contributor

ekinanp commented Nov 26, 2019

So this handles the case when the plugin's API prompts for something, right? Then having control of the console prior to a method invocation would make sense.

@MikaelSmith
Copy link
Contributor Author

Yes.

@MikaelSmith
Copy link
Contributor Author

Ok, I think this works better now.

@MikaelSmith MikaelSmith force-pushed the fix-kubectl-exec branch 2 times, most recently from be84dba to 7568973 Compare November 26, 2019 21:55
Copy link
Contributor

@ekinanp ekinanp left a comment

Choose a reason for hiding this comment

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

Most comments are about moving err := stuff to a separate line. I think only one asks a legitimate question. Otherwise, this LGTM.

signal.Notify(sigCh, syscall.SIGINT)
cancelCtx, cancel := context.WithCancel(ctx)
go func() {
<-sigCh
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't block forever, will it? Guessing the Reset below prevents that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, it might. I can probably do something about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be addressed now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just close sigCh in a defer? You'll still need to call the cancel func either way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, didn't think of it.

Sometimes a plugin needs control of the console for a prompt it doesn't
make directly. Get control before calling all primitives that take a
context (as a proxy for potential network activity or execs).

This isn't entirely safe. If it's backgrounded and prompts for input it
may not exit cleanly. Using `plugin.Prompt` guards against this issue.

Fixes puppetlabs-toy-chest#297.

Signed-off-by: Michael Smith <[email protected]>
@ekinanp ekinanp merged commit 0464d04 into puppetlabs-toy-chest:master Nov 27, 2019
@MikaelSmith MikaelSmith deleted the fix-kubectl-exec branch November 27, 2019 19:39
MikaelSmith added a commit to MikaelSmith/wash that referenced this pull request Dec 2, 2019
When `wash` is run, it starts a shell as a child process where all the
action happens. It then stays running as a daemon to handle
Wash-specific requests through FUSE and the socket API. However if it
needs to prompt for input, it has trouble because it's TTY is not the
same as the one handling input (the child shell).

We previously addressed that by temporarily transferring control of
input to the Wash daemon, but that had some problems
- it only worked when a plugin requested input using Wash's helper
- if the process that triggered the plugin activity tried to do
something with stdin - like MacVim appears to on startup - it would fail

Reparent the Wash daemon to have a new session under the new shell so
they share the same TTY. Prompts for input now work wherever they're
triggered from. MacVim still behaves a little strangely if you get a
prompt when opening it, but I'm not sure what to do about it.

Fixes puppetlabs-toy-chest#623.

Signed-off-by: Michael Smith <[email protected]>
MikaelSmith added a commit to MikaelSmith/wash that referenced this pull request Dec 2, 2019
When `wash` is run, it starts a shell as a child process where all the
action happens. It then stays running as a daemon to handle
Wash-specific requests through FUSE and the socket API. However if it
needs to prompt for input, it has trouble because it's TTY is not the
same as the one handling input (the child shell).

We previously addressed that by temporarily transferring control of
input to the Wash daemon, but that had some problems
- it only worked when a plugin requested input using Wash's helper
- if the process that triggered the plugin activity tried to do
something with stdin - like MacVim appears to on startup - it would fail

Reparent the Wash daemon to have a new session under the new shell so
they share the same TTY. Prompts for input now work wherever they're
triggered from. MacVim still behaves a little strangely if you get a
prompt when opening it, but I'm not sure what to do about it.

Fixes puppetlabs-toy-chest#623.

Signed-off-by: Michael Smith <[email protected]>
MikaelSmith added a commit to MikaelSmith/wash that referenced this pull request Dec 3, 2019
When `wash` is run, it starts a shell as a child process where all the
action happens. It then stays running as a daemon to handle
Wash-specific requests through FUSE and the socket API. However if it
needs to prompt for input, it has trouble because it's TTY is not the
same as the one handling input (the child shell).

We previously addressed that by temporarily transferring control of
input to the Wash daemon, but that had some problems
- it only worked when a plugin requested input using Wash's helper
- if the process that triggered the plugin activity tried to do
something with stdin - like MacVim appears to on startup - it would fail

Reparent the Wash daemon to have a new session under the new shell so
they share the same TTY. Prompts for input now work wherever they're
triggered from. MacVim still behaves a little strangely if you get a
prompt when opening it, but I'm not sure what to do about it.

Fixes puppetlabs-toy-chest#623.

Signed-off-by: Michael Smith <[email protected]>
MikaelSmith added a commit to MikaelSmith/wash that referenced this pull request Dec 3, 2019
When `wash` is run, it starts a shell as a child process where all the
action happens. It then stays running as a daemon to handle
Wash-specific requests through FUSE and the socket API. However if it
needs to prompt for input, it has trouble because it's TTY is not the
same as the one handling input (the child shell).

We previously addressed that by temporarily transferring control of
input to the Wash daemon, but that had some problems
- it only worked when a plugin requested input using Wash's helper
- if the process that triggered the plugin activity tried to do
something with stdin - like MacVim appears to on startup - it would fail

Reparent the Wash daemon to have a new session under the new shell so
they share the same TTY. Prompts for input now work wherever they're
triggered from. MacVim still behaves a little strangely if you get a
prompt when opening it, but I'm not sure what to do about it.

Fixes puppetlabs-toy-chest#623.

Signed-off-by: Michael Smith <[email protected]>
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.

Kubernetes config with 'exec' resource where exec requires MFA hangs
2 participants