Skip to content
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

feat: Add workspace agent for SSH #318

Merged
merged 19 commits into from
Feb 19, 2022
Merged

feat: Add workspace agent for SSH #318

merged 19 commits into from
Feb 19, 2022

Conversation

kylecarbs
Copy link
Member

This adds the initial agent that supports TTY
and execution over SSH. It functions across MacOS,
Windows, and Linux.

This does not handle the coderd interaction yet,
but does setup a simple path forward.

@codecov
Copy link

codecov bot commented Feb 18, 2022

Codecov Report

Merging #318 (516b605) into main (65de96c) will increase coverage by 0.16%.
The diff coverage is 63.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #318      +/-   ##
==========================================
+ Coverage   67.53%   67.70%   +0.16%     
==========================================
  Files         140      142       +2     
  Lines        7443     7700     +257     
  Branches       77       77              
==========================================
+ Hits         5027     5213     +186     
- Misses       1905     1960      +55     
- Partials      511      527      +16     
Flag Coverage Δ
unittest-go-macos-latest 66.49% <65.06%> (+0.47%) ⬆️
unittest-go-ubuntu-latest 67.57% <64.77%> (+0.14%) ⬆️
unittest-go-windows-2022 65.95% <64.12%> (+0.16%) ⬆️
unittest-js 63.61% <ø> (ø)
Impacted Files Coverage Δ
pty/pty_other.go 35.89% <0.00%> (ø)
pty/start_windows.go 51.30% <20.00%> (-0.95%) ⬇️
agent/usershell/usershell_other.go 60.00% <60.00%> (ø)
agent/agent.go 66.08% <66.08%> (ø)
pty/ptytest/ptytest.go 90.74% <66.66%> (+0.94%) ⬆️
pty/start_other.go 72.00% <66.66%> (+1.16%) ⬆️
pty/pty_windows.go 60.31% <80.00%> (+1.30%) ⬆️
coderd/coderdtest/coderdtest.go 100.00% <100.00%> (ø)
pty/start.go 100.00% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65de96c...516b605. Read the comment docs.

@@ -0,0 +1,293 @@
package agent
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this agent be run as a standalone executable, or part of coderd? If it is the former - maybe it would make sense to be agentd?

Copy link
Member Author

Choose a reason for hiding this comment

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

Part of the coder CLI! I was debating the name and structure internally. The purpose is the listening agent inside of a workspace for enabling access. It'll be added as coder agent start, or something of the like.

I initially had this in cli/agent, but felt that unnecessarily nested core business logic. Beyond that, it's likely this package will be used for tests that aren't relevant to the CLI at all. eg. agenttest.New will likely exist.

I'd appreciate your thoughts here. It's more of an agent than a daemon, because it doesn't require system-level privileges, and is active rather than passive.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for all the helpful details @kylecarbs !

It'll be added as coder agent start, or something of the like.

That sounds good!

I initially had this in cli/agent, but felt that unnecessarily nested core business logic.

Agreed, it seems like our convention here is to have packages at the top-level - don't see a compelling reason to switch that.

It's more of an agent than a daemon, because it doesn't require system-level privileges, and is active rather than passive.

Makes sense to me 👍

agent/agent.go Outdated
return nil, err
}
sshConn, channels, requests, err := gossh.NewClientConn(netConn, "localhost:22", &gossh.ClientConfig{
User: "kyle",
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this user be configurable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, yes haha!

@kylecarbs kylecarbs force-pushed the workspaceagent branch 2 times, most recently from 7ec58fb to 2c477aa Compare February 18, 2022 03:57
Copy link
Contributor

@bryphe-coder bryphe-coder left a comment

Choose a reason for hiding this comment

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

Just some questions inline - but overall looks great. Exciting to have the agent piece come together. Hopefully that means we can ssh into workspaces soon 😄

agent/agent.go Outdated Show resolved Hide resolved
agent/agent.go Outdated Show resolved Hide resolved
agent/agent_test.go Outdated Show resolved Hide resolved
agent/agent_test.go Show resolved Hide resolved
agent/usershell/usershell_other.go Show resolved Hide resolved
templates/null/main.tf Show resolved Hide resolved
This adds the initial agent that supports TTY
and execution over SSH. It functions across MacOS,
Windows, and Linux.

This does not handle the coderd interaction yet,
but does setup a simple path forward.
return nil, nil, xerrors.Errorf("find process %d: %w", processInfo.ProcessId, err)
}
go func() {
_, _ = process.Wait()
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth adding logging here too with the exit code of the process.

I saw this failure in a recent run:

    ptytest.go:82: 
        	Error Trace:	ptytest.go:82
        	            				start_windows_test.go:24
        	Error:      	Received unexpected error:
        	            	read |0: file already closed
        	Test:       	TestStart/Echo

https://github.com/coder/coder/runs/5242887100?check_suite_focus=true#step:7:239

And I suspect this part of the change might be related. Having the logging could help give details here. It could be a race in that the process might exit and the pty is closed before being fully read by the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, will add!

Copy link
Member Author

Choose a reason for hiding this comment

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

CI caught a real issue here! Fixed in 42656a4

@kylecarbs kylecarbs force-pushed the workspaceagent branch 2 times, most recently from 11e5274 to 0c755fb Compare February 18, 2022 05:33
@kylecarbs kylecarbs merged commit 91bf863 into main Feb 19, 2022
@kylecarbs kylecarbs deleted the workspaceagent branch February 19, 2022 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants