kontena-cli 1.3.0.pre1 → 1.3.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/kontena +2 -1
  4. data/lib/kontena/callback.rb +1 -1
  5. data/lib/kontena/callbacks/auth/01_list_and_select_grid_after_master_auth.rb +1 -2
  6. data/lib/kontena/callbacks/master/01_clear_current_master_after_terminate.rb +2 -3
  7. data/lib/kontena/callbacks/master/deploy/01_show_logo_before_deploy.rb +1 -2
  8. data/lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb +2 -2
  9. data/lib/kontena/callbacks/master/deploy/40_install_ssl_certificate_after_deploy.rb +2 -2
  10. data/lib/kontena/callbacks/master/deploy/50_authenticate_after_deploy.rb +9 -9
  11. data/lib/kontena/callbacks/master/deploy/55_create_initial_grid_after_deploy.rb +2 -2
  12. data/lib/kontena/callbacks/master/deploy/56_set_server_provider_after_deploy.rb +1 -2
  13. data/lib/kontena/callbacks/master/deploy/60_configure_auth_provider_after_deploy.rb +1 -2
  14. data/lib/kontena/callbacks/master/deploy/70_invite_self_after_deploy.rb +2 -3
  15. data/lib/kontena/callbacks/master/deploy/90_proptip_after_deploy.rb +2 -2
  16. data/lib/kontena/cli/apps/common.rb +0 -1
  17. data/lib/kontena/cli/apps/init_command.rb +2 -0
  18. data/lib/kontena/cli/apps/kontena_yml_generator.rb +2 -1
  19. data/lib/kontena/cli/apps/list_command.rb +10 -2
  20. data/lib/kontena/cli/apps/yaml/reader.rb +2 -1
  21. data/lib/kontena/cli/apps/yaml/service_extender.rb +0 -1
  22. data/lib/kontena/cli/cloud/login_command.rb +51 -7
  23. data/lib/kontena/cli/cloud/master/list_command.rb +14 -11
  24. data/lib/kontena/cli/common.rb +36 -83
  25. data/lib/kontena/cli/config.rb +46 -29
  26. data/lib/kontena/cli/containers/list_command.rb +30 -41
  27. data/lib/kontena/cli/etcd/list_command.rb +12 -7
  28. data/lib/kontena/cli/external_registries/list_command.rb +14 -8
  29. data/lib/kontena/cli/grids/list_command.rb +18 -10
  30. data/lib/kontena/cli/grids/trusted_subnets/list_command.rb +7 -5
  31. data/lib/kontena/cli/grids/users/list_command.rb +9 -7
  32. data/lib/kontena/cli/localhost_web_server.rb +3 -3
  33. data/lib/kontena/cli/log_formatters/compact.rb +65 -0
  34. data/lib/kontena/cli/log_formatters/strip_color.rb +13 -0
  35. data/lib/kontena/cli/master/config/import_command.rb +2 -1
  36. data/lib/kontena/cli/master/config/set_command.rb +1 -1
  37. data/lib/kontena/cli/master/list_command.rb +16 -10
  38. data/lib/kontena/cli/master/token/list_command.rb +23 -12
  39. data/lib/kontena/cli/master/user/invite_command.rb +1 -1
  40. data/lib/kontena/cli/master/user/list_command.rb +17 -6
  41. data/lib/kontena/cli/nodes/labels/list_command.rb +3 -0
  42. data/lib/kontena/cli/nodes/list_command.rb +58 -37
  43. data/lib/kontena/cli/nodes/show_command.rb +1 -1
  44. data/lib/kontena/cli/plugins/install_command.rb +2 -2
  45. data/lib/kontena/cli/plugins/list_command.rb +19 -5
  46. data/lib/kontena/cli/plugins/uninstall_command.rb +1 -1
  47. data/lib/kontena/cli/services/containers_command.rb +7 -0
  48. data/lib/kontena/cli/services/envs/list_command.rb +6 -4
  49. data/lib/kontena/cli/services/list_command.rb +47 -36
  50. data/lib/kontena/cli/services/services_helper.rb +9 -16
  51. data/lib/kontena/cli/services/stats_command.rb +2 -1
  52. data/lib/kontena/cli/spinner.rb +3 -5
  53. data/lib/kontena/cli/stacks/common.rb +4 -4
  54. data/lib/kontena/cli/stacks/list_command.rb +42 -33
  55. data/lib/kontena/cli/stacks/registry/search_command.rb +6 -0
  56. data/lib/kontena/cli/stacks/registry/show_command.rb +2 -0
  57. data/lib/kontena/cli/stacks/registry_command.rb +1 -2
  58. data/lib/kontena/cli/stacks/validate_command.rb +1 -0
  59. data/lib/kontena/cli/stacks/yaml/reader.rb +3 -2
  60. data/lib/kontena/cli/stacks/yaml/service_extender.rb +0 -1
  61. data/lib/kontena/cli/stacks/yaml/validations.rb +1 -1
  62. data/lib/kontena/cli/table_generator.rb +125 -0
  63. data/lib/kontena/cli/vault/export_command.rb +7 -4
  64. data/lib/kontena/cli/vault/import_command.rb +3 -0
  65. data/lib/kontena/cli/vault/list_command.rb +23 -10
  66. data/lib/kontena/cli/volumes/create_command.rb +8 -4
  67. data/lib/kontena/cli/volumes/list_command.rb +15 -7
  68. data/lib/kontena/client.rb +44 -33
  69. data/lib/kontena/command.rb +7 -4
  70. data/lib/kontena/debug_instrumentor.rb +10 -9
  71. data/lib/kontena/main_command.rb +1 -3
  72. data/lib/kontena/plugin_manager.rb +15 -7
  73. data/lib/kontena/stacks_cache.rb +7 -7
  74. data/lib/kontena/stacks_client.rb +24 -5
  75. data/lib/kontena/util.rb +43 -15
  76. data/lib/kontena_cli.rb +71 -14
  77. data/spec/kontena/cli/cloud/login_command_spec.rb +42 -0
  78. data/spec/kontena/cli/containers/list_command_spec.rb +1 -2
  79. data/spec/kontena/cli/nodes/list_command_spec.rb +153 -126
  80. data/spec/kontena/cli/registry/create_spec.rb +22 -0
  81. data/spec/kontena/cli/services/stats_command_spec.rb +22 -0
  82. data/spec/kontena/cli/table_generator_spec.rb +118 -0
  83. data/spec/kontena/cli/version_command_spec.rb +2 -2
  84. data/spec/kontena/client_spec.rb +4 -3
  85. data/spec/support/client_helpers.rb +3 -3
  86. data/spec/support/output_helpers.rb +54 -8
  87. metadata +11 -2
@@ -118,6 +118,13 @@ describe Kontena::Cli::Cloud::LoginCommand do
118
118
  expect(subject).to receive(:finish).and_return(true)
119
119
  subject.run([])
120
120
  end
121
+
122
+ it 'should enter the remote login if --remote given' do
123
+ expect(client).not_to receive(:authentication_ok?)
124
+ expect(subject).to receive(:remote_login).and_return(true)
125
+ expect(subject).to receive(:finish).and_return(true)
126
+ subject.run(['--remote'])
127
+ end
121
128
  end
122
129
 
123
130
  context 'when performing web flow' do
@@ -179,6 +186,41 @@ describe Kontena::Cli::Cloud::LoginCommand do
179
186
  end
180
187
  end
181
188
 
189
+ context 'when performing remote login' do
190
+ let(:account) do
191
+ account = Kontena::Cli::Config::Account.new(Kontena::Cli::Config.kontena_account_data)
192
+ account.token = Kontena::Cli::Config::Token.new(access_token: nil, parent_type: :account, parent_name: 'kontena')
193
+ account.client_id = '1234567890'
194
+ account
195
+ end
196
+
197
+ before(:each) do
198
+ expect(subject).to receive(:kontena_account).at_least(:once).and_return(account)
199
+ allow(subject).to receive(:any_key_to_continue).and_return(true)
200
+ end
201
+ it 'creates auth request and exchanges code to access token' do
202
+ expect(client).to receive(:post).with('/auth_requests',
203
+ { client_id: '1234567890' }, {}, { 'Content-Type' => 'application/x-www-form-urlencoded' }
204
+ ).ordered.and_return({
205
+ 'verification_uri' => 'https://cloud.kontena.io/auth_requests/12345',
206
+ 'user_code' => 'tryme',
207
+ 'device_code' => 'devicex'
208
+ })
209
+
210
+ expect(client).to receive(:post).with('/auth_requests/code', {
211
+ client_id: '1234567890',
212
+ device_code: 'devicex'
213
+ }, {}, { 'Content-Type' => 'application/x-www-form-urlencoded'}
214
+ ).ordered.and_return({ 'code' => 'abcd' })
215
+
216
+ expect(client).to receive(:exchange_code).with('abcd').ordered.and_return({
217
+ 'access_token' => 'abcdefg'
218
+ })
219
+ expect(subject).to receive(:finish).and_return(true)
220
+ subject.run(['--remote'])
221
+ end
222
+ end
223
+
182
224
  context 'methods' do
183
225
  let(:account) do
184
226
  account = Kontena::Cli::Config::Account.new(Kontena::Cli::Config.kontena_account_data)
@@ -6,8 +6,7 @@ describe Kontena::Cli::Containers::ListCommand do
6
6
  context "for a single container with logs" do
7
7
 
8
8
  it "fetches containers" do
9
- expect(client).to receive(:get).with('containers/test-grid?').and_return({'containers' => []})
10
-
9
+ expect(client).to receive(:get).with('containers/test-grid').and_return({'containers' => []})
11
10
  subject.run([])
12
11
  end
13
12
  end
@@ -4,63 +4,76 @@ describe Kontena::Cli::Nodes::ListCommand do
4
4
  include ClientHelpers
5
5
  include OutputHelpers
6
6
 
7
+ let(:subject) { described_class.new("kontena") }
8
+
7
9
  before do
8
10
  allow(subject).to receive(:health_icon) {|health| health.inspect }
11
+ allow(subject).to receive(:client).and_return(client)
9
12
  end
10
13
 
11
14
  describe '#show_grid_nodes' do
12
15
  context "For a initial_size=3 grid" do
13
- let :grid do
14
- {
15
- "id" => "test",
16
- "name" => "test",
17
- "initial_size" => 3,
18
- "node_count" => 1,
19
- }
16
+ before do
17
+ allow(client).to receive(:get).with('grids/test-grid').and_return(
18
+ {
19
+ "id" => "test-grid",
20
+ "name" => "test-grid",
21
+ "initial_size" => 3,
22
+ "node_count" => 1,
23
+ }
24
+ )
20
25
  end
21
26
 
22
27
  context "with a single node" do
23
- let :grid_nodes do
24
- { "nodes" => [
28
+
29
+ before do
30
+ allow(client).to receive(:get).with('grids/test-grid/nodes').and_return(
25
31
  {
26
- "connected" => true,
27
- "name" => "node-1",
28
- "node_number" => 1,
29
- "initial_member" => true,
30
- 'agent_version' => '1.1-dev',
31
- },
32
- ] }
32
+ 'nodes' => [
33
+ {
34
+ "connected" => true,
35
+ "name" => "node-1",
36
+ "node_number" => 1,
37
+ "initial_member" => true,
38
+ 'agent_version' => '1.1-dev',
39
+ }
40
+ ]
41
+ }
42
+ )
33
43
  end
34
44
 
35
45
  it "outputs node with error" do
36
- expect{subject.show_grid_nodes(grid, grid_nodes['nodes'])}.to output_table [
46
+ expect{subject.run([])}.to output_table [
37
47
  [':error node-1', '1.1-dev', 'online', '1 / 3', '-'],
38
48
  ]
39
49
  end
40
50
  end
41
51
 
42
52
  context "with a single online node" do
43
- let :grid_nodes do
44
- { "nodes" => [
45
- {
46
- "connected" => true,
47
- "name" => "node-1",
48
- "node_number" => 1,
49
- "initial_member" => true,
50
- 'agent_version' => '1.1-dev',
51
- },
52
- {
53
- "connected" => false,
54
- "name" => "node-2",
55
- "node_number" => 2,
56
- "initial_member" => true,
57
- 'agent_version' => '1.1-dev',
58
- },
59
- ] }
53
+ before do
54
+ allow(client).to receive(:get).with('grids/test-grid/nodes').and_return(
55
+ { "nodes" => [
56
+ {
57
+ "connected" => true,
58
+ "name" => "node-1",
59
+ "node_number" => 1,
60
+ "initial_member" => true,
61
+ 'agent_version' => '1.1-dev',
62
+ },
63
+ {
64
+ "connected" => false,
65
+ "name" => "node-2",
66
+ "node_number" => 2,
67
+ "initial_member" => true,
68
+ 'agent_version' => '1.1-dev',
69
+ },
70
+ ]
71
+ }
72
+ )
60
73
  end
61
74
 
62
75
  it "outputs online node with error" do
63
- expect{subject.show_grid_nodes(grid, grid_nodes['nodes'])}.to output_table [
76
+ expect{subject.run([])}.to output_table [
64
77
  [':error node-1', '1.1-dev', 'online', '1 / 3', '-'],
65
78
  [':offline node-2', '1.1-dev', 'offline', '2 / 3', '-'],
66
79
  ]
@@ -68,27 +81,30 @@ describe Kontena::Cli::Nodes::ListCommand do
68
81
  end
69
82
 
70
83
  context "with two online nodes" do
71
- let :grid_nodes do
72
- { "nodes" => [
73
- {
74
- "connected" => true,
75
- "name" => "node-1",
76
- "node_number" => 1,
77
- "initial_member" => true,
78
- 'agent_version' => '1.1-dev',
79
- },
80
- {
81
- "connected" => true,
82
- "name" => "node-2",
83
- "node_number" => 2,
84
- "initial_member" => true,
85
- 'agent_version' => '1.1-dev',
86
- },
87
- ] }
84
+ before do
85
+ allow(client).to receive(:get).with('grids/test-grid/nodes').and_return(
86
+ { "nodes" => [
87
+ {
88
+ "connected" => true,
89
+ "name" => "node-1",
90
+ "node_number" => 1,
91
+ "initial_member" => true,
92
+ 'agent_version' => '1.1-dev',
93
+ },
94
+ {
95
+ "connected" => true,
96
+ "name" => "node-2",
97
+ "node_number" => 2,
98
+ "initial_member" => true,
99
+ 'agent_version' => '1.1-dev',
100
+ },
101
+ ]
102
+ }
103
+ )
88
104
  end
89
105
 
90
106
  it "outputs both nodes with warning" do
91
- expect{subject.show_grid_nodes(grid, grid_nodes['nodes'])}.to output_table [
107
+ expect{subject.run([])}.to output_table [
92
108
  [':warning node-1', '1.1-dev', 'online', '1 / 3', '-'],
93
109
  [':warning node-2', '1.1-dev', 'online', '2 / 3', '-'],
94
110
  ]
@@ -96,34 +112,37 @@ describe Kontena::Cli::Nodes::ListCommand do
96
112
  end
97
113
 
98
114
  context "with two online nodes and one offline node" do
99
- let :grid_nodes do
100
- { "nodes" => [
101
- {
102
- "connected" => true,
103
- "name" => "node-1",
104
- "node_number" => 1,
105
- "initial_member" => true,
106
- 'agent_version' => '1.1-dev',
107
- },
108
- {
109
- "connected" => true,
110
- "name" => "node-2",
111
- "node_number" => 2,
112
- "initial_member" => true,
113
- 'agent_version' => '1.1-dev',
114
- },
115
- {
116
- "connected" => false,
117
- "name" => "node-3",
118
- "node_number" => 3,
119
- "initial_member" => true,
120
- 'agent_version' => '1.1-dev',
121
- },
122
- ] }
115
+ before do
116
+ allow(client).to receive(:get).with('grids/test-grid/nodes').and_return(
117
+ { "nodes" => [
118
+ {
119
+ "connected" => true,
120
+ "name" => "node-1",
121
+ "node_number" => 1,
122
+ "initial_member" => true,
123
+ 'agent_version' => '1.1-dev',
124
+ },
125
+ {
126
+ "connected" => true,
127
+ "name" => "node-2",
128
+ "node_number" => 2,
129
+ "initial_member" => true,
130
+ 'agent_version' => '1.1-dev',
131
+ },
132
+ {
133
+ "connected" => false,
134
+ "name" => "node-3",
135
+ "node_number" => 3,
136
+ "initial_member" => true,
137
+ 'agent_version' => '1.1-dev',
138
+ },
139
+ ]
140
+ }
141
+ )
123
142
  end
124
143
 
125
144
  it "outputs two nodes with warning and one offline" do
126
- expect{subject.show_grid_nodes(grid, grid_nodes['nodes'])}.to output_table [
145
+ expect{subject.run([])}.to output_table [
127
146
  [':warning node-1', '1.1-dev', 'online', '1 / 3', '-'],
128
147
  [':warning node-2', '1.1-dev', 'online', '2 / 3', '-'],
129
148
  [':offline node-3', '1.1-dev', 'offline', '3 / 3', '-'],
@@ -132,34 +151,38 @@ describe Kontena::Cli::Nodes::ListCommand do
132
151
  end
133
152
 
134
153
  context "with two online initial nodes and one non-initial node" do
135
- let :grid_nodes do
136
- { "nodes" => [
137
- {
138
- "connected" => true,
139
- "name" => "node-1",
140
- "node_number" => 1,
141
- "initial_member" => true,
142
- 'agent_version' => '1.1-dev',
143
- },
154
+ before do
155
+ allow(client).to receive(:get).with('grids/test-grid/nodes').and_return(
144
156
  {
145
- "connected" => true,
146
- "name" => "node-2",
147
- "node_number" => 2,
148
- "initial_member" => true,
149
- 'agent_version' => '1.1-dev',
150
- },
151
- {
152
- "connected" => true,
153
- "name" => "node-4",
154
- "node_number" => 4,
155
- "initial_member" => false,
156
- 'agent_version' => '1.1-dev',
157
- },
158
- ] }
157
+ "nodes" => [
158
+ {
159
+ "connected" => true,
160
+ "name" => "node-1",
161
+ "node_number" => 1,
162
+ "initial_member" => true,
163
+ 'agent_version' => '1.1-dev',
164
+ },
165
+ {
166
+ "connected" => true,
167
+ "name" => "node-2",
168
+ "node_number" => 2,
169
+ "initial_member" => true,
170
+ 'agent_version' => '1.1-dev',
171
+ },
172
+ {
173
+ "connected" => true,
174
+ "name" => "node-4",
175
+ "node_number" => 4,
176
+ "initial_member" => false,
177
+ 'agent_version' => '1.1-dev',
178
+ },
179
+ ]
180
+ }
181
+ )
159
182
  end
160
183
 
161
184
  it "outputs two nodes with warning and one online" do
162
- expect{subject.show_grid_nodes(grid, grid_nodes['nodes'])}.to output_table [
185
+ expect{subject.run([])}.to output_table [
163
186
  [':warning node-1', '1.1-dev', 'online', '1 / 3', '-'],
164
187
  [':warning node-2', '1.1-dev', 'online', '2 / 3', '-'],
165
188
  [':ok node-4', '1.1-dev', 'online', '-', '-'],
@@ -168,34 +191,38 @@ describe Kontena::Cli::Nodes::ListCommand do
168
191
  end
169
192
 
170
193
  context "with three online initial nodes" do
171
- let :grid_nodes do
172
- { "nodes" => [
173
- {
174
- "connected" => true,
175
- "name" => "node-1",
176
- "node_number" => 1,
177
- "initial_member" => true,
178
- 'agent_version' => '1.1-dev',
179
- },
180
- {
181
- "connected" => true,
182
- "name" => "node-2",
183
- "node_number" => 2,
184
- "initial_member" => true,
185
- 'agent_version' => '1.1-dev',
186
- },
194
+ before do
195
+ allow(client).to receive(:get).with('grids/test-grid/nodes').and_return(
187
196
  {
188
- "connected" => true,
189
- "name" => "node-3",
190
- "node_number" => 3,
191
- "initial_member" => true,
192
- 'agent_version' => '1.1-dev',
193
- },
194
- ] }
197
+ "nodes" => [
198
+ {
199
+ "connected" => true,
200
+ "name" => "node-1",
201
+ "node_number" => 1,
202
+ "initial_member" => true,
203
+ 'agent_version' => '1.1-dev',
204
+ },
205
+ {
206
+ "connected" => true,
207
+ "name" => "node-2",
208
+ "node_number" => 2,
209
+ "initial_member" => true,
210
+ 'agent_version' => '1.1-dev',
211
+ },
212
+ {
213
+ "connected" => true,
214
+ "name" => "node-3",
215
+ "node_number" => 3,
216
+ "initial_member" => true,
217
+ 'agent_version' => '1.1-dev',
218
+ },
219
+ ]
220
+ }
221
+ )
195
222
  end
196
223
 
197
224
  it "outputs three nodes with ok" do
198
- expect{subject.show_grid_nodes(grid, grid_nodes['nodes'])}.to output_table [
225
+ expect{subject.run([])}.to output_table [
199
226
  [':ok node-1', '1.1-dev', 'online', '1 / 3', '-'],
200
227
  [':ok node-2', '1.1-dev', 'online', '2 / 3', '-'],
201
228
  [':ok node-3', '1.1-dev', 'online', '3 / 3', '-'],
@@ -0,0 +1,22 @@
1
+ require 'kontena/cli/registry/create_command'
2
+
3
+ describe Kontena::Cli::Registry::CreateCommand do
4
+ include ClientHelpers
5
+ include OutputHelpers
6
+
7
+ context "with an existing legacy registry service" do
8
+ let :service do
9
+ {
10
+ 'name' => 'registry',
11
+ }
12
+ end
13
+
14
+ before do
15
+ allow(client).to receive(:get).with('services/test-grid/registry').and_return(service)
16
+ end
17
+
18
+ it "does not create the registry" do
19
+ expect{subject.run []}.to exit_with_error.and output(/Registry already exists/).to_stderr
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require "kontena/cli/services/stats_command"
2
+
3
+ describe Kontena::Cli::Services::StatsCommand do
4
+ describe "MEM_MAX_LIMITS" do
5
+ let(:subject) { described_class.const_get(:MEM_MAX_LIMITS) }
6
+
7
+ context 'first' do
8
+ it 'is 64 bits' do
9
+ expect(subject.first).to eq 2**64
10
+ expect(subject.first).to eq 1.8446744073709552e+19
11
+ end
12
+ end
13
+
14
+ context 'last' do
15
+ it 'is 9223372036854771712' do
16
+ expect(subject.last).to eq 0x7FFFFFFFFFFFF000
17
+ expect(subject.last).to eq 9.223372036854772e+18
18
+ end
19
+ end
20
+ end
21
+ end
22
+