kontena icon indicating copy to clipboard operation
kontena copied to clipboard

CLI: Add --master to commands that accept --grid

Open kke opened this issue 7 years ago • 6 comments

Fixes #2922

Adds --master option to select master by name from config to all commands that accept --grid as an option.

kke avatar Oct 10 '17 09:10 kke

Replaces #1911

SpComb avatar Oct 10 '17 13:10 SpComb

The kontena master list command defines a current_master_name that overlaps the new Kontena::Cli::Common#current_master_name and goes off into an infinite recursion:

 ....
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/common.rb:259:in `current_master'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/master/list_command.rb:11:in `current_master_name'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/common.rb:259:in `current_master'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/master/list_command.rb:11:in `current_master_name'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/common.rb:259:in `current_master'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/master/list_command.rb:11:in `current_master_name'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/common.rb:259:in `current_master'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/master/list_command.rb:11:in `current_master_name'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/common.rb:259:in `current_master'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/master/list_command.rb:11:in `current_master_name'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/master/list_command.rb:16:in `mark_if_current'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:81:in `format_row'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:90:in `block in rows'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:90:in `map'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:90:in `rows'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:67:in `table'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:74:in `render'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:35:in `generate_table'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/table_generator.rb:39:in `print_table'
  /home/kontena/kontena/kontena/cli/lib/kontena/cli/master/list_command.rb:21:in `execute'
  /home/kontena/kontena/kontena/cli/lib/kontena/command.rb:213:in `run'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute'
  /home/kontena/kontena/kontena/cli/lib/kontena/command.rb:213:in `run'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute'
  /home/kontena/kontena/kontena/cli/lib/kontena/command.rb:213:in `run'
  /home/kontena/kontena/kontena/cli/vendor/bundle/ruby/2.3.0/gems/clamp-1.1.2/lib/clamp/command.rb:132:in `run'
  bin/kontena:18:in `<top (required)>'

SpComb avatar Nov 07 '17 10:11 SpComb

The implementation of --platform in the cloud plugin looks much more reasonable: https://github.com/kontena/kontena-plugin-cloud/blob/e68198337c41678f981811b5ea40c622e055c10f/lib/kontena_cli_plugin.rb#L12-L15

option '--platform', 'PLATFORM', 'Specify Kontena Cloud platform to use' do |platform|
            config.current_master = platform
            config.current_grid = platform.split('/')[1]
end

AFAIK that handles all the side-effect-ness of config.current_master= neatly, and also avoids the mess of coupling different mixin modules together via stuff like if self.respond_to?(:current_master_name) && self.current_master_name...

SpComb avatar Nov 07 '17 10:11 SpComb

Looks like our spec_helper swallows SystemExit and makes the specs pass instead of failing

Without the rescue SystemExit it will end running the specs and say "success" Also SystemExit is not an error most of the time.

kke avatar Nov 07 '17 12:11 kke

Looks like our spec_helper swallows SystemExit and makes the specs pass instead of failing

Without the rescue SystemExit it will end running the specs and say "success" Also SystemExit is not an error most of the time.

It seems to cause any spec that hits exit_with_error to bypass any expect(...) checks and unconditionally succeed, unless the specs explicitly expect{...}.to raise_error(SystemExit) :confused:

I tried changing the puts to a fail, which should catch that kind of exit_with_error case.

Dunno how to handle exit(0) - does that happen in the CLI? It seems like that would likely bypass any rspec expect(...) assertions unless the specs themselves trap it.

SpComb avatar Nov 07 '17 12:11 SpComb

This would be nice but the PR has a lot of strange stuff in it. Also it's a bit complex to make it work seamlessly, so this will need some rewriting/factoring.

kke avatar Feb 22 '18 08:02 kke