kontena-cli 1.3.5 → 1.4.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/VERSION +1 -1
  3. data/lib/kontena/cli/etcd/health_command.rb +1 -1
  4. data/lib/kontena/cli/grids/common.rb +51 -0
  5. data/lib/kontena/cli/grids/create_command.rb +13 -9
  6. data/lib/kontena/cli/grids/update_command.rb +11 -44
  7. data/lib/kontena/cli/node_command.rb +3 -0
  8. data/lib/kontena/cli/nodes/create_command.rb +25 -0
  9. data/lib/kontena/cli/nodes/env_command.rb +32 -0
  10. data/lib/kontena/cli/nodes/health_command.rb +2 -2
  11. data/lib/kontena/cli/nodes/labels/add_command.rb +3 -3
  12. data/lib/kontena/cli/nodes/labels/list_command.rb +2 -2
  13. data/lib/kontena/cli/nodes/labels/remove_command.rb +3 -3
  14. data/lib/kontena/cli/nodes/remove_command.rb +9 -7
  15. data/lib/kontena/cli/nodes/reset_token_command.rb +31 -0
  16. data/lib/kontena/cli/nodes/show_command.rb +4 -4
  17. data/lib/kontena/cli/nodes/ssh_command.rb +4 -4
  18. data/lib/kontena/cli/nodes/update_command.rb +13 -8
  19. data/lib/kontena/cli/services/create_command.rb +4 -0
  20. data/lib/kontena/cli/services/services_helper.rb +2 -0
  21. data/lib/kontena/cli/services/update_command.rb +2 -0
  22. data/lib/kontena/cli/stacks/service_generator.rb +2 -0
  23. data/lib/kontena/cli/stacks/show_command.rb +1 -0
  24. data/lib/kontena/cli/stacks/stacks_helper.rb +2 -3
  25. data/lib/kontena/cli/stacks/yaml/validations.rb +3 -1
  26. data/lib/kontena/machine/cloud_config/cloudinit.yml +17 -4
  27. data/omnibus/package-scripts/kontena/postinst +0 -4
  28. data/omnibus/package-scripts/kontena/postrm +1 -1
  29. data/omnibus/package-scripts/kontena/preinst +0 -2
  30. data/spec/fixtures/api/node.json +93 -0
  31. data/spec/kontena/cli/containers/logs_command_spec.rb +0 -4
  32. data/spec/kontena/cli/etcd/health_command_spec.rb +128 -63
  33. data/spec/kontena/cli/nodes/create_command_spec.rb +24 -0
  34. data/spec/kontena/cli/nodes/env_command_spec.rb +49 -0
  35. data/spec/kontena/cli/nodes/health_command_spec.rb +15 -173
  36. data/spec/kontena/cli/nodes/labels/add_command_spec.rb +56 -0
  37. data/spec/kontena/cli/nodes/labels/list_command_spec.rb +43 -0
  38. data/spec/kontena/cli/nodes/labels/remove_command_spec.rb +57 -0
  39. data/spec/kontena/cli/nodes/list_command_spec.rb +0 -2
  40. data/spec/kontena/cli/nodes/remove_command_spec.rb +76 -0
  41. data/spec/kontena/cli/nodes/reset_token_command_spec.rb +38 -0
  42. data/spec/kontena/cli/nodes/show_command_spec.rb +46 -0
  43. data/spec/kontena/cli/nodes/ssh_command_spec.rb +5 -0
  44. data/spec/kontena/cli/nodes/update_command_spec.rb +24 -0
  45. data/spec/kontena/cli/stacks/deploy_command_spec.rb +21 -0
  46. data/spec/kontena/cli/stacks/logs_command_spec.rb +0 -4
  47. data/spec/kontena/cli/table_generator_spec.rb +0 -4
  48. data/spec/spec_helper.rb +5 -0
  49. data/spec/support/output_helpers.rb +3 -14
  50. data/tasks/release.rake +2 -2
  51. metadata +28 -5
@@ -7,8 +7,6 @@ describe Kontena::Cli::Nodes::ListCommand do
7
7
  let(:subject) { described_class.new("kontena") }
8
8
 
9
9
  before do
10
- Kontena.pastel.resolver.color.disable!
11
-
12
10
  allow(subject).to receive(:health_icon) {|health| health.inspect }
13
11
  allow(subject).to receive(:client).and_return(client)
14
12
  end
@@ -0,0 +1,76 @@
1
+ require 'kontena/cli/nodes/remove_command'
2
+
3
+ describe Kontena::Cli::Nodes::RemoveCommand do
4
+ include ClientHelpers
5
+ include OutputHelpers
6
+
7
+ context 'for an offline node without a node token' do
8
+ let :node do
9
+ {
10
+ "id" => 'test-grid/node-1',
11
+ "name" => 'node-1',
12
+ "has_token" => false,
13
+ "connected" => false,
14
+ }
15
+ end
16
+
17
+ before do
18
+ expect(client).to receive(:get).with('nodes/test-grid/node-1').and_return(node)
19
+ end
20
+
21
+ it 'removes the node' do
22
+ expect(subject).to receive(:confirm_command).with('node-1')
23
+ expect(client).to receive(:delete).with('nodes/test-grid/node-1')
24
+
25
+ subject.run(['node-1'])
26
+ end
27
+
28
+ it 'removes the node with --force' do
29
+ expect(client).to receive(:delete).with('nodes/test-grid/node-1')
30
+
31
+ subject.run(['--force', 'node-1'])
32
+ end
33
+ end
34
+
35
+ context 'for an online node without a node token' do
36
+ let :node do
37
+ {
38
+ "id" => 'test-grid/node-1',
39
+ "name" => 'node-1',
40
+ "has_token" => false,
41
+ "connected" => true,
42
+ }
43
+ end
44
+
45
+ before do
46
+ expect(client).to receive(:get).with('nodes/test-grid/node-1').and_return(node)
47
+ end
48
+
49
+ it 'does not remove the node' do
50
+ expect(client).not_to receive(:delete)
51
+
52
+ expect{subject.run(['node-1'])}.to output(" [error] Node node-1 is still online. You must terminate the node before removing it.\n").to_stderr
53
+ end
54
+ end
55
+
56
+ context 'for an online node with a node token' do
57
+ let :node do
58
+ {
59
+ "id" => 'test-grid/node-1',
60
+ "name" => 'node-1',
61
+ "has_token" => true,
62
+ "connected" => true,
63
+ }
64
+ end
65
+
66
+ before do
67
+ expect(client).to receive(:get).with('nodes/test-grid/node-1').and_return(node)
68
+ end
69
+
70
+ it 'removes the node' do
71
+ expect(client).to receive(:delete).with('nodes/test-grid/node-1')
72
+
73
+ expect{subject.run(['--force', 'node-1'])}.to output(/\[warn\] Node node-1 is still connected using a node token, but will be force-disconnected/).to_stderr
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,38 @@
1
+ require 'kontena/cli/nodes/reset_token_command'
2
+
3
+ describe Kontena::Cli::Nodes::ResetTokenCommand do
4
+ include ClientHelpers
5
+ include OutputHelpers
6
+
7
+ it 'prompts on token update' do
8
+ expect(subject).to receive(:confirm).with("Resetting the node token will disconnect the agent (unless using --no-reset-connection), and require you to reconfigure the kontena-agent using the new `kontena node env` values before it will be able to reconnect. Are you sure?")
9
+
10
+ expect(client).to receive(:put).with('nodes/test-grid/test-node/token', {token: nil, reset_connection: true})
11
+
12
+ subject.run(['test-node'])
13
+ end
14
+
15
+ it 'PUTs token with reset_connection' do
16
+ expect(client).to receive(:put).with('nodes/test-grid/test-node/token', {token: 'asdf', reset_connection: true})
17
+
18
+ subject.run(['--force', '--token=asdf', 'test-node'])
19
+ end
20
+
21
+ it 'PUTs to generate token with reset_connection' do
22
+ expect(client).to receive(:put).with('nodes/test-grid/test-node/token', {token: nil, reset_connection: true})
23
+
24
+ subject.run(['--force', 'test-node'])
25
+ end
26
+
27
+ it 'PUTs to generate token without reset_connection' do
28
+ expect(client).to receive(:put).with('nodes/test-grid/test-node/token', {token: nil, reset_connection: false})
29
+
30
+ subject.run(['--force', '--no-reset-connection', 'test-node'])
31
+ end
32
+
33
+ it 'PUTs to clear token without reset_connection' do
34
+ expect(client).to receive(:put).with('nodes/test-grid/test-node/token', {token: '', reset_connection: false})
35
+
36
+ subject.run(['--force', '--no-reset-connection', '--clear-token', 'test-node'])
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ require 'kontena/cli/nodes/show_command'
2
+
3
+ describe Kontena::Cli::Nodes::ShowCommand do
4
+ include ClientHelpers
5
+ include OutputHelpers
6
+ include FixturesHelpers
7
+
8
+ let(:subject) { described_class.new("kontena") }
9
+
10
+ let(:node) {
11
+ JSON.load(fixture('api/node.json'))
12
+ }
13
+
14
+ before do
15
+ allow(client).to receive(:get).with('nodes/test-grid/core-01').and_return(node)
16
+ end
17
+
18
+ it "outputs the node info" do
19
+ expect{subject.run(['core-01'])}.to output_lines([
20
+ 'development/core-01:',
21
+ ' id: XI4K:NPOL:EQJ4:S4V7:EN3B:DHC5:KZJD:F3U2:PCAN:46EV:IO4A:63S5',
22
+ ' agent version: 1.4.0.dev',
23
+ ' docker version: 1.12.6',
24
+ ' connected: yes',
25
+ ' last connect: 2017-07-04T08:36:02.235Z',
26
+ ' last seen: 2017-07-04T08:36:02.280Z',
27
+ ' public ip: 91.150.10.190',
28
+ ' private ip: 192.168.66.101',
29
+ ' overlay ip: 10.81.0.1',
30
+ ' os: Container Linux by CoreOS 1409.5.0 (Ladybug)',
31
+ ' kernel: 4.11.6-coreos-r1',
32
+ ' drivers:',
33
+ ' storage: overlay',
34
+ ' volume: local',
35
+ ' initial node: yes',
36
+ ' labels:',
37
+ ' - test',
38
+ ' stats:',
39
+ ' cpus: 1',
40
+ ' load: 1.49 0.34 0.11',
41
+ ' memory: 0.39 of 0.97 GB',
42
+ ' filesystem:',
43
+ ' - /var/lib/docker: 2.89 of 15.57 GB',
44
+ ])
45
+ end
46
+ end
@@ -16,6 +16,11 @@ describe Kontena::Cli::Nodes::SshCommand do
16
16
  allow(client).to receive(:get).with('nodes/test-grid/test-node').and_return(node)
17
17
  end
18
18
 
19
+ it "fails if using both --any and a node name as a command" do
20
+ expect(subject).to_not receive(:exec)
21
+ expect{subject.run(['--any', 'ls', '-l'])}.to exit_with_error.and output(/Cannot combine --any with a node name/).to_stderr
22
+ end
23
+
19
24
  it "uses the public IP by default" do
20
25
  expect(subject).to receive(:exec).with('ssh', 'core@192.0.2.10')
21
26
  subject.run ['test-node']
@@ -0,0 +1,24 @@
1
+ require 'kontena/cli/nodes/update_command'
2
+
3
+ describe Kontena::Cli::Nodes::UpdateCommand do
4
+ include ClientHelpers
5
+ include OutputHelpers
6
+
7
+ it 'PUTs with empty parameters by default' do
8
+ expect(client).to receive(:put).with('nodes/test-grid/test-node', {})
9
+
10
+ subject.run(['test-node'])
11
+ end
12
+
13
+ it 'PUTs with labels' do
14
+ expect(client).to receive(:put).with('nodes/test-grid/test-node', {labels: ['test1=yes', 'test2=no']})
15
+
16
+ subject.run(['-l', 'test1=yes', '--label=test2=no', 'test-node'])
17
+ end
18
+
19
+ it 'PUTs with empty labels' do
20
+ expect(client).to receive(:put).with('nodes/test-grid/test-node', {labels: []})
21
+
22
+ subject.run(['--clear-labels', 'test-node'])
23
+ end
24
+ end
@@ -24,4 +24,25 @@ describe Kontena::Cli::Stacks::DeployCommand do
24
24
  subject.run(['test-stack'])
25
25
  end
26
26
  end
27
+
28
+ it 'exits with error if the stack deploy fails to start' do
29
+ expect(client).to receive(:post).with('stacks/test-grid/test-stack/deploy', {}).once.and_return({
30
+ 'id' => '59524bd753caed000801b6a3',
31
+ 'stack_id' => 'test-grid/test-stack',
32
+ 'created_at' => '2017-06-27T12:13:11.181Z',
33
+ 'state' => 'created',
34
+ 'service_deploys' => [],
35
+ })
36
+
37
+ expect(client).to receive(:get).with('stacks/test-grid/test-stack/deploys/59524bd753caed000801b6a3').once.and_return({
38
+ 'id' => '59524bd753caed000801b6a3',
39
+ 'stack_id' => 'test-grid/test-stack',
40
+ 'created_at' => '2017-06-27T12:13:11.181Z',
41
+ 'state' => 'error',
42
+ 'service_deploys' => [],
43
+ })
44
+ expect(subject).to receive(:sleep).once
45
+
46
+ expect{subject.run(['test-stack'])}.to exit_with_error.and output(/deploy failed/).to_stderr
47
+ end
27
48
  end
@@ -15,10 +15,6 @@ describe Kontena::Cli::Stacks::LogsCommand do
15
15
  ]
16
16
  end
17
17
 
18
- before(:each) do
19
- Kontena.pastel.resolver.color.disable!
20
- end
21
-
22
18
  it "shows stack logs" do
23
19
  expect(client).to receive(:get).with('stacks/test-grid/test-stack/container_logs', {
24
20
  limit: 100,
@@ -5,10 +5,6 @@ require 'kontena/cli/common'
5
5
  describe Kontena::Cli::TableGenerator do
6
6
  let(:data) { [{'a' => 'a1', 'b' => 'b1', 'c' => 'c1'}, {'a' => 'a2', 'b' => 'b2', 'c' => 'c2'}] }
7
7
 
8
- before do
9
- Kontena.pastel.resolver.color.disable!
10
- end
11
-
12
8
  context Kontena::Cli::TableGenerator::Helper do
13
9
  let(:klass) { Class.new(Kontena::Command) }
14
10
 
data/spec/spec_helper.rb CHANGED
@@ -33,6 +33,11 @@ RSpec.configure do |config|
33
33
  Kontena::Cli::Config.reset_instance
34
34
  end
35
35
 
36
+ # disable pastel colors for all specs, regardless of order
37
+ config.before(:all) do
38
+ Kontena.pastel.resolver.color.disable!
39
+ end
40
+
36
41
  config.after(:each) do
37
42
  RSpec::Mocks.space.proxy_for(File).reset
38
43
  RSpec::Mocks.space.proxy_for(Kontena::Cli::Config).reset
@@ -90,21 +90,10 @@ module OutputHelpers
90
90
  supports_block_expectations
91
91
 
92
92
  match do |block|
93
- stdout = lines.flatten.join("\n") + "\n"
94
-
95
- begin
96
- expect{@return = block.call}.to output(stdout).to_stdout
97
- rescue Exception => error
98
- @error = error
93
+ @expected = lines.flatten
94
+ @actual = CaptureStdoutLines.capture(block)
99
95
 
100
- return false
101
- else
102
- return true
103
- end
104
- end
105
-
106
- failure_message do |block|
107
- return @error
96
+ values_match?(@actual, @expected)
108
97
  end
109
98
  end
110
99
 
data/tasks/release.rake CHANGED
@@ -2,9 +2,9 @@ namespace :release do
2
2
  VERSION = Gem::Version.new(File.read('VERSION').strip)
3
3
  DOCKER_NAME = 'kontena/cli'
4
4
  if VERSION.prerelease?
5
- DOCKER_VERSIONS = []
5
+ DOCKER_VERSIONS = ['edge']
6
6
  else
7
- DOCKER_VERSIONS = [VERSION.to_s.match(/(\d+\.\d+)/)[1]]
7
+ DOCKER_VERSIONS = ['latest', VERSION.to_s.match(/(\d+\.\d+)/)[1]]
8
8
  end
9
9
 
10
10
  desc 'Build all'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.4.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -381,6 +381,8 @@ files:
381
381
  - lib/kontena/cli/master/users_command.rb
382
382
  - lib/kontena/cli/master_command.rb
383
383
  - lib/kontena/cli/node_command.rb
384
+ - lib/kontena/cli/nodes/create_command.rb
385
+ - lib/kontena/cli/nodes/env_command.rb
384
386
  - lib/kontena/cli/nodes/health_command.rb
385
387
  - lib/kontena/cli/nodes/label_command.rb
386
388
  - lib/kontena/cli/nodes/labels/add_command.rb
@@ -388,6 +390,7 @@ files:
388
390
  - lib/kontena/cli/nodes/labels/remove_command.rb
389
391
  - lib/kontena/cli/nodes/list_command.rb
390
392
  - lib/kontena/cli/nodes/remove_command.rb
393
+ - lib/kontena/cli/nodes/reset_token_command.rb
391
394
  - lib/kontena/cli/nodes/show_command.rb
392
395
  - lib/kontena/cli/nodes/ssh_command.rb
393
396
  - lib/kontena/cli/nodes/update_command.rb
@@ -536,6 +539,7 @@ files:
536
539
  - omnibus/resources/kontena/pkg/license.html.erb
537
540
  - omnibus/resources/kontena/pkg/welcome.html.erb
538
541
  - omnibus/wrappers/sh/kontena
542
+ - spec/fixtures/api/node.json
539
543
  - spec/fixtures/app.json
540
544
  - spec/fixtures/docker-compose-invalid.yml
541
545
  - spec/fixtures/docker-compose.yml
@@ -609,9 +613,18 @@ files:
609
613
  - spec/kontena/cli/master/user/remove_command_spec.rb
610
614
  - spec/kontena/cli/master/user/role/add_command_spec.rb
611
615
  - spec/kontena/cli/master/user/role/remove_command_spec.rb
616
+ - spec/kontena/cli/nodes/create_command_spec.rb
617
+ - spec/kontena/cli/nodes/env_command_spec.rb
612
618
  - spec/kontena/cli/nodes/health_command_spec.rb
619
+ - spec/kontena/cli/nodes/labels/add_command_spec.rb
620
+ - spec/kontena/cli/nodes/labels/list_command_spec.rb
621
+ - spec/kontena/cli/nodes/labels/remove_command_spec.rb
613
622
  - spec/kontena/cli/nodes/list_command_spec.rb
623
+ - spec/kontena/cli/nodes/remove_command_spec.rb
624
+ - spec/kontena/cli/nodes/reset_token_command_spec.rb
625
+ - spec/kontena/cli/nodes/show_command_spec.rb
614
626
  - spec/kontena/cli/nodes/ssh_command_spec.rb
627
+ - spec/kontena/cli/nodes/update_command_spec.rb
615
628
  - spec/kontena/cli/plugins/install_command_spec.rb
616
629
  - spec/kontena/cli/registry/create_spec.rb
617
630
  - spec/kontena/cli/services/containers_command_spec.rb
@@ -682,16 +695,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
682
695
  version: 2.1.0
683
696
  required_rubygems_version: !ruby/object:Gem::Requirement
684
697
  requirements:
685
- - - ">="
698
+ - - ">"
686
699
  - !ruby/object:Gem::Version
687
- version: '0'
700
+ version: 1.3.1
688
701
  requirements: []
689
702
  rubyforge_project:
690
- rubygems_version: 2.7.1
703
+ rubygems_version: 2.6.8
691
704
  signing_key:
692
705
  specification_version: 4
693
706
  summary: Kontena command line tool
694
707
  test_files:
708
+ - spec/fixtures/api/node.json
695
709
  - spec/fixtures/app.json
696
710
  - spec/fixtures/docker-compose-invalid.yml
697
711
  - spec/fixtures/docker-compose.yml
@@ -765,9 +779,18 @@ test_files:
765
779
  - spec/kontena/cli/master/user/remove_command_spec.rb
766
780
  - spec/kontena/cli/master/user/role/add_command_spec.rb
767
781
  - spec/kontena/cli/master/user/role/remove_command_spec.rb
782
+ - spec/kontena/cli/nodes/create_command_spec.rb
783
+ - spec/kontena/cli/nodes/env_command_spec.rb
768
784
  - spec/kontena/cli/nodes/health_command_spec.rb
785
+ - spec/kontena/cli/nodes/labels/add_command_spec.rb
786
+ - spec/kontena/cli/nodes/labels/list_command_spec.rb
787
+ - spec/kontena/cli/nodes/labels/remove_command_spec.rb
769
788
  - spec/kontena/cli/nodes/list_command_spec.rb
789
+ - spec/kontena/cli/nodes/remove_command_spec.rb
790
+ - spec/kontena/cli/nodes/reset_token_command_spec.rb
791
+ - spec/kontena/cli/nodes/show_command_spec.rb
770
792
  - spec/kontena/cli/nodes/ssh_command_spec.rb
793
+ - spec/kontena/cli/nodes/update_command_spec.rb
771
794
  - spec/kontena/cli/plugins/install_command_spec.rb
772
795
  - spec/kontena/cli/registry/create_spec.rb
773
796
  - spec/kontena/cli/services/containers_command_spec.rb