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

Rewrite CLI container exec websocket client #2599

Merged
merged 27 commits into from Jul 27, 2017
Merged

Conversation

SpComb
Copy link
Contributor

@SpComb SpComb commented Jul 20, 2017

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 improved kontena-websocket-client, and rewrite the Kontena::Cli::Helpers::ExecHelper, Kontena::Cli::Containers::ExecComamnd, Kontena::Cli::Services::ExecCommand.

@SpComb SpComb changed the title [WiP] Rewrite CLI websocket exec to use kontena-websocket-client [WiP] Rewrite CLI websocket container exec helpers Jul 20, 2017
@@ -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"
Copy link
Contributor Author

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...

Copy link
Contributor

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?

Copy link
Contributor Author

@SpComb SpComb Jul 24, 2017

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like a plan.

Copy link
Contributor Author

@SpComb SpComb Jul 25, 2017

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|
Copy link
Contributor Author

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)>'

@SpComb SpComb changed the title [WiP] Rewrite CLI websocket container exec helpers Rewrite CLI websocket container exec helpers Jul 21, 2017
@SpComb SpComb requested a review from jakolehm July 21, 2017 13:45
cli/Gemfile Outdated
@@ -1,7 +1,10 @@
source 'https://rubygems.org'

gem 'kontena-websocket-client', git: 'https://github.com/kontena/kontena-websocket-client.git'
Copy link
Contributor

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"
Copy link
Contributor

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?

@SpComb
Copy link
Contributor Author

SpComb commented Jul 24, 2017

Needs something to deal with oauth2 token refresh... running kontena container exec after the token expires fails with HTTP 403, because it doesn't do any normal API requests that would refresh the token:

 [error] Error during WebSocket handshake: Unexpected response code: 403


# 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
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is ok.

Copy link
Contributor Author

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.

@SpComb SpComb requested a review from jakolehm July 24, 2017 08:34
@@ -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"
Copy link
Contributor

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'
Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

This is ok.

@SpComb
Copy link
Contributor Author

SpComb commented Jul 26, 2017

Added e2e specs for the error exit statuses.

@SpComb SpComb requested a review from jakolehm July 26, 2017 12:39
@SpComb SpComb changed the title Rewrite CLI websocket container exec helpers Rewrite CLI container exec websocket client Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants