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
@@ -0,0 +1,24 @@
1
+ require 'kontena/cli/nodes/create_command'
2
+
3
+ describe Kontena::Cli::Nodes::CreateCommand do
4
+ include ClientHelpers
5
+ include OutputHelpers
6
+
7
+ it 'POSTs the node' do
8
+ expect(client).to receive(:post).with('grids/test-grid/nodes', {name: 'node-4', labels: []})
9
+
10
+ subject.run(['node-4'])
11
+ end
12
+
13
+ it 'POSTs the node with labels' do
14
+ expect(client).to receive(:post).with('grids/test-grid/nodes', {name: 'node-4', labels: ['test=4']})
15
+
16
+ subject.run(['-l', 'test=4', 'node-4'])
17
+ end
18
+
19
+ it 'POSTs with given token' do
20
+ expect(client).to receive(:post).with('grids/test-grid/nodes', {name: 'node-4', labels: [], token: 'asdf'})
21
+
22
+ subject.run(['--token=asdf', 'node-4'])
23
+ end
24
+ end
@@ -0,0 +1,49 @@
1
+ require 'kontena/cli/nodes/env_command'
2
+
3
+ describe Kontena::Cli::Nodes::EnvCommand do
4
+ include ClientHelpers
5
+ include OutputHelpers
6
+
7
+ context 'for a node created with a token' do
8
+ let :node_token do
9
+ {
10
+ "id" => 'test-grid/node-4',
11
+ "token" => 'TPnBKanfXJpi47CCvuv+Gq319AXvXBi0LL/8grXrhPr9MyqcXHsWbUy0Q3stmPGHhjaqubi5ZCwa7LbnSvZ/Iw=='
12
+ }
13
+ end
14
+
15
+ before do
16
+ expect(client).to receive(:get).with('nodes/test-grid/node-4/token').and_return(node_token)
17
+ end
18
+
19
+ it 'shows the node env' do
20
+ expect{subject.run(['node-4'])}.to output_lines [
21
+ 'KONTENA_URI=ws://someurl.example.com/',
22
+ 'KONTENA_NODE_TOKEN=TPnBKanfXJpi47CCvuv+Gq319AXvXBi0LL/8grXrhPr9MyqcXHsWbUy0Q3stmPGHhjaqubi5ZCwa7LbnSvZ/Iw==',
23
+ ]
24
+ end
25
+
26
+ it 'shows the --token' do
27
+ expect{subject.run(['--token', 'node-4'])}.to output_lines [
28
+ 'TPnBKanfXJpi47CCvuv+Gq319AXvXBi0LL/8grXrhPr9MyqcXHsWbUy0Q3stmPGHhjaqubi5ZCwa7LbnSvZ/Iw==',
29
+ ]
30
+ end
31
+ end
32
+
33
+ context 'for a node without any token' do
34
+ let :node_token do
35
+ {
36
+ "id" => nil,
37
+ "token" => nil,
38
+ }
39
+ end
40
+
41
+ before do
42
+ expect(client).to receive(:get).with('nodes/test-grid/node-1/token').and_return(node_token)
43
+ end
44
+
45
+ it 'uses the grid token' do
46
+ expect{subject.run(['node-1'])}.to exit_with_error.and output(" [error] Node node-1 was not created with a node token. Use `kontena grid env` instead\n").to_stderr
47
+ end
48
+ end
49
+ end
@@ -8,199 +8,41 @@ describe Kontena::Cli::Nodes::HealthCommand do
8
8
  allow(subject).to receive(:health_icon) {|health| health.inspect }
9
9
  end
10
10
 
11
+ before do
12
+ allow(client).to receive(:get).with('nodes/test-grid/node').and_return(node)
13
+ end
14
+
11
15
  context "for an online node" do
12
16
  let :node do
13
17
  {
14
- "connected" => true,
15
- "name" => "node-4",
18
+ "name" => "node",
16
19
  "node_number" => 4,
17
20
  "initial_member" => false,
21
+ "connected" => true,
18
22
  }
19
23
  end
20
24
 
21
- let :grid_health do
22
- :ok
23
- end
24
-
25
- describe '#node_health' do
26
- it "returns ok" do
27
- expect(subject.node_health(node, grid_health)).to eq(:ok)
28
- end
29
- end
30
-
31
- describe '#show_node_health' do
32
- it "returns true" do
33
- expect{subject.show_node_health(node)}.to return_and_output true,
34
- ":ok Node is online"
35
- end
25
+ it "outputs ok" do
26
+ expect{subject.run(['node'])}.to output_lines [
27
+ ":ok Node is online",
28
+ ]
36
29
  end
37
30
  end
38
31
 
39
32
  context "for an offline node" do
40
33
  let :node do
41
34
  {
42
- "connected" => false,
43
- "name" => "node-4",
35
+ "name" => "node",
44
36
  "node_number" => 4,
45
37
  "initial_member" => false,
46
- }
47
- end
48
-
49
- let :grid_health do
50
- :ok
51
- end
52
-
53
- describe '#node_health' do
54
- it "returns offline" do
55
- expect(subject.node_health(node, grid_health)).to eq(:offline)
56
- end
57
- end
58
-
59
- describe '#show_node_health' do
60
- it "returns false" do
61
- expect{subject.show_node_health(node)}.to return_and_output false,
62
- ":offline Node is offline"
63
- end
64
- end
65
- end
66
-
67
- context "for an online initial node in an ok grid" do
68
- let :node do
69
- {
70
- "connected" => true,
71
- "name" => "node-1",
72
- "node_number" => 1,
73
- "initial_member" => true,
74
- }
75
- end
76
-
77
- let :grid_health do
78
- :ok
79
- end
80
-
81
- describe '#node_health' do
82
- it "returns ok" do
83
- expect(subject.node_health(node, grid_health)).to eq(:ok)
84
- end
85
- end
86
-
87
- describe '#show_node_health' do
88
- it "returns true" do
89
- expect{subject.show_node_health(node)}.to return_and_output true,
90
- ":ok Node is online"
91
- end
92
- end
93
- end
94
-
95
- context "for an online initial node in a warning grid" do
96
- let :node do
97
- {
98
- "connected" => true,
99
- "name" => "node-1",
100
- "node_number" => 1,
101
- "initial_member" => true,
102
- }
103
- end
104
-
105
- let :grid_health do
106
- :warning
107
- end
108
-
109
- describe '#node_health' do
110
- it "returns ok" do
111
- expect(subject.node_health(node, grid_health)).to eq(:warning)
112
- end
113
- end
114
-
115
- describe '#show_node_health' do
116
- it "returns true" do
117
- expect{subject.show_node_health(node)}.to return_and_output true,
118
- ":ok Node is online"
119
- end
120
- end
121
- end
122
-
123
- context "for an online initial node in an error grid" do
124
- let :node do
125
- {
126
- "connected" => true,
127
- "name" => "node-1",
128
- "node_number" => 1,
129
- "initial_member" => true,
130
- }
131
- end
132
-
133
- let :grid_health do
134
- :error
135
- end
136
-
137
- describe '#node_health' do
138
- it "returns ok" do
139
- expect(subject.node_health(node, grid_health)).to eq(:error)
140
- end
141
- end
142
-
143
- describe '#show_node_health' do
144
- it "returns true" do
145
- expect{subject.show_node_health(node)}.to return_and_output true,
146
- ":ok Node is online"
147
- end
148
- end
149
- end
150
-
151
- context "for an offline initial node in a warning grid" do
152
- let :node do
153
- {
154
38
  "connected" => false,
155
- "name" => "node-1",
156
- "node_number" => 1,
157
- "initial_member" => true,
158
39
  }
159
40
  end
160
41
 
161
- let :grid_health do
162
- :warning
163
- end
164
-
165
- describe '#node_health' do
166
- it "returns offline" do
167
- expect(subject.node_health(node, grid_health)).to eq(:offline)
168
- end
169
- end
170
-
171
- describe '#show_node_health' do
172
- it "returns false" do
173
- expect{subject.show_node_health(node)}.to return_and_output false,
174
- ":offline Node is offline"
175
- end
176
- end
177
- end
178
-
179
- context "for an offline initial node in a error grid" do
180
- let :node do
181
- {
182
- "connected" => false,
183
- "name" => "node-1",
184
- "node_number" => 1,
185
- "initial_member" => true,
186
- }
187
- end
188
-
189
- let :grid_health do
190
- :error
191
- end
192
-
193
- describe '#node_health' do
194
- it "returns offline" do
195
- expect(subject.node_health(node, grid_health)).to eq(:offline)
196
- end
197
- end
198
-
199
- describe '#show_node_health' do
200
- it "returns false" do
201
- expect{subject.show_node_health(node)}.to return_and_output false,
202
- ":offline Node is offline"
203
- end
42
+ it "fails as error" do
43
+ expect{subject.run(['node'])}.to exit_with_error.and output_lines [
44
+ ":offline Node is offline",
45
+ ]
204
46
  end
205
47
  end
206
48
  end
@@ -0,0 +1,56 @@
1
+ require 'kontena/cli/nodes/label_command'
2
+ require 'kontena/cli/nodes/labels/add_command'
3
+
4
+ describe Kontena::Cli::Nodes::Labels::AddCommand do
5
+ include ClientHelpers
6
+ include OutputHelpers
7
+
8
+ before do
9
+ allow(client).to receive(:get).with('nodes/test-grid/node').and_return(node)
10
+ end
11
+
12
+ context "for a node without any labels" do
13
+ let :node do
14
+ {
15
+ "id" => 'test-grid/node',
16
+ "name" => "node",
17
+ "labels" => [],
18
+ }
19
+ end
20
+
21
+ it "adds the labels" do
22
+ expect(client).to receive(:put).with('nodes/test-grid/node', {
23
+ labels: ['test=yes'],
24
+ })
25
+ subject.run(['node', 'test=yes'])
26
+ end
27
+ end
28
+
29
+ context "for a node with labels" do
30
+ let :node do
31
+ {
32
+ "id" => 'test-grid/node',
33
+ "name" => "node",
34
+ "labels" => [
35
+ 'test=yes',
36
+ ],
37
+ }
38
+ end
39
+
40
+ it "adds new labels" do
41
+ expect(client).to receive(:put).with('nodes/test-grid/node', {
42
+ labels: ['test=yes', 'test=no'],
43
+ })
44
+
45
+ subject.run(['node', 'test=no'])
46
+ end
47
+
48
+ it "deduplicates labels" do
49
+ expect(client).to receive(:put).with('nodes/test-grid/node', {
50
+ labels: ['test=yes'],
51
+ })
52
+
53
+ subject.run(['node', 'test=yes'])
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,43 @@
1
+ require 'kontena/cli/nodes/label_command'
2
+ require 'kontena/cli/nodes/labels/list_command'
3
+
4
+ describe Kontena::Cli::Nodes::Labels::ListCommand do
5
+ include ClientHelpers
6
+ include OutputHelpers
7
+
8
+ before do
9
+ allow(client).to receive(:get).with('nodes/test-grid/node').and_return(node)
10
+ end
11
+
12
+ context "for a node without any labels" do
13
+ let :node do
14
+ {
15
+ "id" => 'test-grid/node',
16
+ "name" => "node",
17
+ "labels" => [],
18
+ }
19
+ end
20
+
21
+ it "outputs nothing" do
22
+ expect{subject.run(['node'])}.to output_lines [ ]
23
+ end
24
+ end
25
+
26
+ context "for a node with labels" do
27
+ let :node do
28
+ {
29
+ "id" => 'test-grid/node',
30
+ "name" => "node",
31
+ "labels" => [
32
+ 'test=yes',
33
+ ],
34
+ }
35
+ end
36
+
37
+ it "outputs nothing" do
38
+ expect{subject.run(['node'])}.to output_lines [
39
+ 'test=yes',
40
+ ]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,57 @@
1
+ require 'kontena/cli/nodes/label_command'
2
+ require 'kontena/cli/nodes/labels/remove_command'
3
+
4
+ describe Kontena::Cli::Nodes::Labels::RemoveCommand do
5
+ include ClientHelpers
6
+ include OutputHelpers
7
+
8
+ before do
9
+ allow(client).to receive(:get).with('nodes/test-grid/node').and_return(node)
10
+ end
11
+
12
+ context "for a node without any labels" do
13
+ let :node do
14
+ {
15
+ "id" => 'test-grid/node',
16
+ "name" => "node",
17
+ "labels" => [],
18
+ }
19
+ end
20
+
21
+ it "doesn't remove anything" do
22
+ expect(client).to receive(:put).with('nodes/test-grid/node', {
23
+ labels: [],
24
+ })
25
+ subject.run(['node', 'test=yes'])
26
+ end
27
+ end
28
+
29
+ context "for a node with labels" do
30
+ let :node do
31
+ {
32
+ "id" => 'test-grid/node',
33
+ "name" => "node",
34
+ "labels" => [
35
+ 'test=yes',
36
+ 'test=no',
37
+ ],
38
+ }
39
+ end
40
+
41
+ it "removes labels" do
42
+ expect(client).to receive(:put).with('nodes/test-grid/node', {
43
+ labels: ['test=no'],
44
+ })
45
+
46
+ subject.run(['node', 'test=yes'])
47
+ end
48
+
49
+ it "removes all labels" do
50
+ expect(client).to receive(:put).with('nodes/test-grid/node', {
51
+ labels: [],
52
+ })
53
+
54
+ subject.run(['node', 'test=yes', 'test=no'])
55
+ end
56
+ end
57
+ end