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
Rewrite CLI container exec websocket client #2599
Conversation
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec| | |||
spec.add_runtime_dependency "semantic", "~> 1.5" | |||
spec.add_runtime_dependency "liquid", "~> 4.0.0" | |||
spec.add_runtime_dependency "tty-table", "~> 0.8.0" | |||
spec.add_runtime_dependency "websocket-driver-kontena", "0.6.5" | |||
spec.add_runtime_dependency "kontena-websocket-client", "~> 0.1.0" |
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.
Needs some trickery to avoid the websocket-extensions
dependency...
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.
How can we do that trickery?
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.
s/websocket-extensions/native websocket_mask extension/
The websocket-driver-ruby
already handles the require 'websocket_mask'
as an optional dependency with a fallback to a pure-ruby implementation... the kontena-websocket-client
should probably depend on the pure-ruby websocket-driver-kontena
, and then the agent could also depend on some optional gem that provides the optional websocket_mask
extension for better performance.
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.
Sounds like a plan.
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.
it 'connects and sends messages from stdin' do | ||
stdin_eol = false | ||
|
||
expect(subject).to receive(:read_stdin).with(tty: true) do |&block| |
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.
1) Kontena::Cli::Helpers::ExecHelper#websocket_exec with interactive tty connects and sends messages from stdin
Failure/Error:
expect(subject).to receive(:read_stdin).with(tty: true) do |&block|
block.call 'f'
block.call 'oo'
block.call "\n"
sleep 1
end
(#<#<Class:0x00000002c4e058>:0x00000002c4df68>).read_stdin({:tty=>true})
expected: 1 time with arguments: ({:tty=>true})
received: 0 times
# ./spec/kontena/cli/helpers/exec_helper_spec.rb:192:in `block (4 levels) in <top (required)>'
# ./spec/spec_helper.rb:50:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:48:in `catch'
# ./spec/spec_helper.rb:48:in `block (2 levels) in <top (required)>'
…sl_subject_cn for Kontena::Client
cli/Gemfile
Outdated
@@ -1,7 +1,10 @@ | |||
source 'https://rubygems.org' | |||
|
|||
gem 'kontena-websocket-client', git: 'https://github.com/kontena/kontena-websocket-client.git' |
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.
We need to get rid of this git reference.
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec| | |||
spec.add_runtime_dependency "semantic", "~> 1.5" | |||
spec.add_runtime_dependency "liquid", "~> 4.0.0" | |||
spec.add_runtime_dependency "tty-table", "~> 0.8.0" | |||
spec.add_runtime_dependency "websocket-driver-kontena", "0.6.5" | |||
spec.add_runtime_dependency "kontena-websocket-client", "~> 0.1.0" |
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.
How can we do that trickery?
Needs something to deal with oauth2 token refresh... running
|
|
||
# we do not expect CloseError, because the server will send an 'exit' message first, | ||
# and we return before seeing the close frame | ||
# TODO: handle HTTP 404 errors |
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.
The old code had some special handling of HTTP 404 responses, which this is missing. ATM something like a kontena container exec core-01/weavex
looks like this:
[error] Error during WebSocket handshake: Unexpected response code: 404
Compared to other commands:
[error] 404 : Not found (/v1/services/development/null/test)
Probably acceptable... otherwise the kontena-websocket-client
would need to trap the ProtocolError
raised by the websocket-driver
and reraise it as some kind of HTTPError
with a @status_code
.
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.
This is ok.
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.
Updated the e2e spec to match.
ba54e20
to
2ed0cc3
Compare
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec| | |||
spec.add_runtime_dependency "semantic", "~> 1.5" | |||
spec.add_runtime_dependency "liquid", "~> 4.0.0" | |||
spec.add_runtime_dependency "tty-table", "~> 0.8.0" | |||
spec.add_runtime_dependency "websocket-driver-kontena", "0.6.5" | |||
spec.add_runtime_dependency "kontena-websocket-client", "~> 0.1.0" |
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.
Sounds like a plan.
@@ -1,87 +1,190 @@ | |||
require_relative '../../websocket/client' | |||
require 'io/console' |
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.
why did we move this outside? (this was inside a method for lazy loading)
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.
The entire exec_helper.rb
is only loaded if you run an exec command:
lib/kontena/cli/containers/exec_command.rb:require_relative '../helpers/exec_helper'
lib/kontena/cli/services/exec_command.rb:require_relative '../helpers/exec_helper'
Or was there some even more specific purpose in only loading it when using --interactive
?
|
||
# we do not expect CloseError, because the server will send an 'exit' message first, | ||
# and we return before seeing the close frame | ||
# TODO: handle HTTP 404 errors |
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.
This is ok.
Added e2e specs for the error exit statuses. |
Fixes #2500 CLI SSL certificate verification
Mitigates #2605 to exit with an 5s websocket open timeout error instead of hanging indefinitely
See #2560 for the agent websocket client
Replaces the CLI
Kontena::Websocket::Client
with the improvedkontena-websocket-client
, and rewrite theKontena::Cli::Helpers::ExecHelper
,Kontena::Cli::Containers::ExecComamnd
,Kontena::Cli::Services::ExecCommand
.