-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Add WebSocket connection support and implement /attach
and /exec
#360
Conversation
d87b214
to
52541f8
Compare
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.
quick initial comments.
I have to admit that I've not really looked at the websocket stuff at all within kubernetes, nor have I dealt much with them otherwise, so you'll have to bear with me a bit unless there are others to help review; feel free to ping others from the original issue* to try and get help. I will ping this PR in the discord (linked in the readme). But integration wise, holy crap, you've done an excellent job of making it fit the patterns of kube, you've juggled a lot of the really hard bits in the config around TLS, and even have a reasonable setup for the features as well (which always become hairy). Everything is in the place I would expect, and is very readable 👍. I at least think you are going in the right direction. The only thing I would request is that we try to make the tungstenite (and anything it pulls in) part of a "websocket" or "attach" feature (or something else that describes it better). The additional subresources this supports, while useful to some, is probably not going to be as popular for the people - whose dependency trees are inflated - without a use for them. (There is also the more philosophical point that this moves kube even further away from not owning the underlying clients; it's already hard to juggle clients, and now we have another type of clients. I was always hoping we'd be able to make it generic long run ala #100 , but I don't really know how to best proceed in that area. If you don't either, don't worry, just noting down some thoughts.) |
f685b04
to
480af85
Compare
9d524b7
to
0e09127
Compare
39f8728
to
557c125
Compare
See [wsstream/conn.go] and [remotecommand/httpstream.go]. v4 sends JSON Status to the error channel (3). [wsstream/conn.go]: https://github.com/kubernetes/kubernetes/blob/0a839c6c3b9489716e216b4fc9dd2f9c17948c16/staging/src/k8s.io/apiserver/pkg/util/wsstream/conn.go#L34-L48 [remotecommand/httpstream.go]: https://github.com/kubernetes/kubernetes/blob/cea1d4e20b4a7886d8ff65f34c6d4f95efcb4742/pkg/kubelet/cri/streaming/remotecommand/httpstream.go#L202-L204
f67066a
to
65b4376
Compare
65b4376
to
5dfff99
Compare
/attach
and /exec
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.
There are few more chores left to do, but I think it's now ready for reviews.
544b554
to
3b08028
Compare
Found the compile issue: examples or kube need to at least rev tokio to 0.22.4 for tokio::io::duplex. The 0.22.0 version does not have it (and that's what i got with a blank build). |
This is looking really good now. Have had a chance to fiddle around with examples and check that things work as expected. There is one thing I feel is a little awkward re: stream conversions, but that might not be anything at fault herein. I pushed an example to |
- Rename `start` to `start_message_loop` to avoid confusion - Filter to reduce the possible cases within loop - Clarify error cases
@clux Maybe it's because of |
3b08028
to
d12e6eb
Compare
https://docs.rs/tokio-util/0.6.0/tokio_util/compat/index.html might be relevant here |
f429593
to
ffa0c57
Compare
Wow, yeah, it works! If users put some ansi unescaping on top of that they'd have something damn close to One small spot, while playing around: there is some truncation somewhere. If you send a very large At any rate, error handling is looking great, as does the rest of the code. I don't have anything else that I can really nitpick at anymore. So whenever you are satisfied, lemme know and we'll merge it :-). Thank you so much for all the hard work over the holiday, this is really a huge contribution. Have invited you to the collaborators so you can push branches + merge on here in the future. |
It might have something to do with the internal buffer size. The default is 1024 bytes.
Thanks :) This is ready to be merged 👍 I'll do some clean up after #363 and look into the truncation. |
🎉🎉🎉 Will put it in the next minor, probably try to do it today so we can release it (unless reqwest gets a tokio one version today). |
Thanks for this PR @kazk, this came at a perfect time for me personally. I believe this is going to be super useful for me in the next 2 weeks. Really appreciate the work. |
Released in |
Attempt to support WebSocket connection.
@clux
I'd like to know if this is on the right track before spending more time on it.
I think it works, but haven't tried.(outputting to stdout works, seepod_attach
example)This is based on #229 (comment)
I had to change
Config
a bit so that it's less coupled withreqwest
to createAsyncTlsConnector
for WebSocket connection when creating aClient
.native-tls
rustls
(accept_invalid_certs
not supported at the moment, needrustls
0.17.0+ and that requires updatingtokio
first)ws
featureattach
/exec
methods.AttachedProcess
struct. Need review/feedback./attach
(seepod_attach
example)/exec
(seepod_exec
example)ws
specific code into a separate module. This should make it much easier to maintain.stdin
,stdout
,stderr
must be setstderr
andtty
cannot be both set because multiplexing is not supported.stderr
will be ignored.MakeWill do when there's a need.WebSocketConfig
configurable.api/streaming
toapi/remote_command
AttachParams
stdin
,stdout
,stderr
allows access to writer/streams fromAttachedProcess
AttachedProcess
stdin()
,stdout()
,stderr()
works