kubecontrol 0.2.5 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/{ruby.yml → unit_tests.yml} +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +101 -0
- data/lib/kubecontrol.rb +3 -0
- data/lib/kubecontrol/client.rb +24 -2
- data/lib/kubecontrol/deployment.rb +38 -0
- data/lib/kubecontrol/pod.rb +5 -0
- data/lib/kubecontrol/stateful_set.rb +28 -0
- data/lib/kubecontrol/version.rb +1 -1
- data/spec/kubecontrol/client_spec.rb +186 -12
- data/spec/kubecontrol/deployment_spec.rb +158 -0
- data/spec/kubecontrol/stateful_set_spec.rb +104 -0
- metadata +16 -6
- data/.github/workflows/gempush.yml +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16ffbd150b8509fd48aafeb8caf01321335687af651155c69737e0e931b0fa58
|
4
|
+
data.tar.gz: 2c64c013191b415b3296e43fbd20a95b2ad82c76207d7a5f4ce2878914fa10ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4f4c1831fa2186e2b17c68c6bc2333dab39b0709c7cd887b775d62de93d1471a00cef49afb80937b62a8736b6fe5508db66dc9605a4da85d6538fc4b4b71d2c
|
7
|
+
data.tar.gz: 1ebf4b5a383a8300ba99e72871abe9dd878852610ab09a9e3badaf2c30ef113e54730a313bb2af00dd5f568894ed6bbb2f88f667b3f9627fb42198357c33dc73
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,6 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
##### kubectl Commands
|
23
24
|
```ruby
|
24
25
|
require 'kubecontrol'
|
25
26
|
|
@@ -28,6 +29,15 @@ kubectl_client = Kubecontrol.client.new
|
|
28
29
|
|
29
30
|
#Exec an arbitrary kubectl command
|
30
31
|
std_out, std_err, exit_code = kubectl_client.kubectl_command 'get deployments'
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Pods
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'kubecontrol'
|
38
|
+
|
39
|
+
# create new client
|
40
|
+
kubectl_client = Kubecontrol.client.new
|
31
41
|
|
32
42
|
# all pods for namespace
|
33
43
|
pods = kubectl_client.pods
|
@@ -47,6 +57,94 @@ pod.namespace
|
|
47
57
|
std_out, std_err, exit_code = pod.exec('ls')
|
48
58
|
```
|
49
59
|
|
60
|
+
#### Services
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
require 'kubecontrol'
|
64
|
+
|
65
|
+
# create new client
|
66
|
+
kubectl_client = Kubecontrol.client.new
|
67
|
+
|
68
|
+
# all services for namespace
|
69
|
+
services = kubectl_client.services
|
70
|
+
|
71
|
+
# find service by name regex
|
72
|
+
service = kubectl_client.find_service_by_name /foo-api-.*/
|
73
|
+
|
74
|
+
# access service information
|
75
|
+
service.name
|
76
|
+
service.type
|
77
|
+
service.cluster_ip
|
78
|
+
service.external_ip
|
79
|
+
service.ports
|
80
|
+
service.age
|
81
|
+
service.namespace
|
82
|
+
```
|
83
|
+
|
84
|
+
#### Deployments
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
require 'kubecontrol'
|
88
|
+
|
89
|
+
# create new client
|
90
|
+
kubectl_client = Kubecontrol.client.new
|
91
|
+
|
92
|
+
# all deployments for namespace
|
93
|
+
deployments = kubectl_client.deployments
|
94
|
+
|
95
|
+
# find deployment by name regex
|
96
|
+
deployment = kubectl_client.find_deployment_by_name /foo-api-.*/
|
97
|
+
|
98
|
+
# access deployment information
|
99
|
+
deployment.name
|
100
|
+
deployment.ready
|
101
|
+
deployment.up_to_date
|
102
|
+
deployment.available
|
103
|
+
deployment.age
|
104
|
+
deployment.namespace
|
105
|
+
|
106
|
+
# is deployment ready
|
107
|
+
deployment.ready?
|
108
|
+
deployment.all_ready?
|
109
|
+
|
110
|
+
# is deployment available
|
111
|
+
deployment.available?
|
112
|
+
|
113
|
+
# is deployment up_to_date
|
114
|
+
deployment.up_to_date?
|
115
|
+
|
116
|
+
# scale deployment
|
117
|
+
deployment.scale(5)
|
118
|
+
```
|
119
|
+
|
120
|
+
#### StatefulSets
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
require 'kubecontrol'
|
124
|
+
|
125
|
+
# create new client
|
126
|
+
kubectl_client = Kubecontrol.client.new
|
127
|
+
|
128
|
+
# all stateful_sets for namespace
|
129
|
+
stateful_sets = kubectl_client.stateful_sets
|
130
|
+
|
131
|
+
# find stateful_set by name regex
|
132
|
+
stateful_set = kubectl_client.find_stateful_set_by_name /foo-api-.*/
|
133
|
+
|
134
|
+
# access stateful_set information
|
135
|
+
stateful_set.name
|
136
|
+
stateful_set.ready
|
137
|
+
stateful_set.age
|
138
|
+
stateful_set.namespace
|
139
|
+
|
140
|
+
# is stateful_set ready
|
141
|
+
stateful_set.ready?
|
142
|
+
stateful_set.all_ready?
|
143
|
+
|
144
|
+
# scale stateful_set
|
145
|
+
stateful_set.scale(5)
|
146
|
+
```
|
147
|
+
|
50
148
|
## Development
|
51
149
|
|
52
150
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -56,3 +154,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
56
154
|
## Contributing
|
57
155
|
|
58
156
|
Bug reports and pull requests are welcome on GitHub at https://github.com/madkin10/kubecontrol.
|
157
|
+
|
158
|
+
## Contributors
|
159
|
+
- [Dustin Ashley](https://github.com/DustinAshley)
|
data/lib/kubecontrol.rb
CHANGED
data/lib/kubecontrol/client.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require_relative 'pod'
|
3
|
+
require_relative 'deployment'
|
4
|
+
require_relative 'stateful_set'
|
3
5
|
require_relative 'service'
|
4
6
|
|
5
7
|
module Kubecontrol
|
@@ -16,14 +18,34 @@ module Kubecontrol
|
|
16
18
|
get_resource(Pod, 5)
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
20
|
-
|
21
|
+
def deployments
|
22
|
+
get_resource(Deployment, 5)
|
23
|
+
end
|
24
|
+
|
25
|
+
def stateful_sets
|
26
|
+
get_resource(StatefulSet, 3)
|
21
27
|
end
|
22
28
|
|
23
29
|
def services
|
24
30
|
get_resource(Service, 6)
|
25
31
|
end
|
26
32
|
|
33
|
+
def find_service_by_name(name_regex)
|
34
|
+
services.find { |service| service.name.match?(name_regex) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_pod_by_name(name_regex)
|
38
|
+
pods.find { |pod| pod.name.match?(name_regex) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_deployment_by_name(name_regex)
|
42
|
+
deployments.find { |deployment| deployment.name.match?(name_regex) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_stateful_set_by_name(name_regex)
|
46
|
+
stateful_sets.find { |stateful_set| stateful_set.name.match?(name_regex) }
|
47
|
+
end
|
48
|
+
|
27
49
|
def kubectl_command(command)
|
28
50
|
stdout_data, stderr_data, status = Open3.capture3("kubectl -n #{namespace} #{command}")
|
29
51
|
exit_code = status.exitstatus
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Kubecontrol
|
2
|
+
class Deployment
|
3
|
+
RESOURCE_NAME = 'deployments'.freeze
|
4
|
+
|
5
|
+
attr_reader :name, :ready, :up_to_date, :available, :age, :namespace, :client
|
6
|
+
|
7
|
+
def initialize(name, ready, up_to_date, available, age, namespace, client)
|
8
|
+
@name = name
|
9
|
+
@ready = ready
|
10
|
+
@up_to_date = up_to_date
|
11
|
+
@available = available
|
12
|
+
@age = age
|
13
|
+
@namespace = namespace
|
14
|
+
@client = client
|
15
|
+
end
|
16
|
+
|
17
|
+
def ready?
|
18
|
+
@ready.split('/').first != '0'
|
19
|
+
end
|
20
|
+
|
21
|
+
def all_ready?
|
22
|
+
max_pods = @ready.split('/').last
|
23
|
+
@ready == "#{max_pods}/#{max_pods}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def available?
|
27
|
+
@available.to_i > 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def up_to_date?
|
31
|
+
@up_to_date.to_i > 1
|
32
|
+
end
|
33
|
+
|
34
|
+
def scale(count)
|
35
|
+
@client.kubectl_command("scale deployment #{@name} --replicas=#{count}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/kubecontrol/pod.rb
CHANGED
@@ -23,6 +23,11 @@ module Kubecontrol
|
|
23
23
|
@status == RUNNING
|
24
24
|
end
|
25
25
|
|
26
|
+
def ready?
|
27
|
+
pod_containers = @ready.split('/').last
|
28
|
+
@ready == "#{pod_containers}/#{pod_containers}"
|
29
|
+
end
|
30
|
+
|
26
31
|
def exec(command)
|
27
32
|
@client.kubectl_command("exec -i #{name} -- sh -c \"#{command.gsub('"', '\"')}\"")
|
28
33
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Kubecontrol
|
2
|
+
class StatefulSet
|
3
|
+
RESOURCE_NAME = 'statefulsets'.freeze
|
4
|
+
|
5
|
+
attr_reader :name, :ready, :age, :namespace, :client
|
6
|
+
|
7
|
+
def initialize(name, ready, age, namespace, client)
|
8
|
+
@name = name
|
9
|
+
@ready = ready
|
10
|
+
@age = age
|
11
|
+
@namespace = namespace
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
def ready?
|
16
|
+
@ready.split('/').first != '0'
|
17
|
+
end
|
18
|
+
|
19
|
+
def all_ready?
|
20
|
+
max_pods = @ready.split('/').last
|
21
|
+
@ready == "#{max_pods}/#{max_pods}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def scale(count)
|
25
|
+
@client.kubectl_command("scale statefulset #{@name} --replicas=#{count}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/kubecontrol/version.rb
CHANGED
@@ -2,25 +2,58 @@ require_relative '../spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe Kubecontrol::Client do
|
4
4
|
let(:custom_namespace) { 'custom_namespace' }
|
5
|
-
let(:
|
6
|
-
let(:
|
5
|
+
let(:name) { 'foo_pod' }
|
6
|
+
let(:ready) { '1/1' }
|
7
|
+
let(:age) { '20d' }
|
8
|
+
let(:process_status) do
|
9
|
+
fork { exit }
|
10
|
+
$CHILD_STATUS
|
11
|
+
end
|
12
|
+
|
7
13
|
let(:pod_status) { 'Running' }
|
8
14
|
let(:pod_restarts) { '0' }
|
9
|
-
let(:pod_age) { '20d' }
|
10
|
-
|
11
15
|
let(:get_pods_std_out) do
|
12
16
|
<<~RUBY
|
13
|
-
NAME
|
14
|
-
#{
|
17
|
+
NAME READY STATUS RESTARTS AGE
|
18
|
+
#{name} #{ready} #{pod_status} #{pod_restarts} #{age}
|
15
19
|
RUBY
|
16
20
|
end
|
17
21
|
let(:get_pods_std_err) { '' }
|
18
|
-
let(:process_status) do
|
19
|
-
fork { exit }
|
20
|
-
$CHILD_STATUS
|
21
|
-
end
|
22
22
|
let(:get_pods_response) { [get_pods_std_out, get_pods_std_err, process_status] }
|
23
23
|
|
24
|
+
let(:service_type) { 'ClusterIP' }
|
25
|
+
let(:service_cluster_ip) { '172.20.0.1' }
|
26
|
+
let(:service_external_ip) { '<none>' }
|
27
|
+
let(:service_ports) { '443/TCP' }
|
28
|
+
let(:get_services_std_out) do
|
29
|
+
<<~RUBY
|
30
|
+
NAME TYPE CLUSTER_IP EXTERNAL-IP PORT(S) AGE
|
31
|
+
#{name} #{service_type} #{service_cluster_ip} #{service_external_ip} #{service_ports} #{age}
|
32
|
+
RUBY
|
33
|
+
end
|
34
|
+
let(:get_services_std_err) { '' }
|
35
|
+
let(:get_services_response) { [get_services_std_out, get_services_std_err, process_status] }
|
36
|
+
|
37
|
+
let(:deployments_up_to_date) { '1' }
|
38
|
+
let(:deployments_available) { '1' }
|
39
|
+
let(:get_deployments_std_out) do
|
40
|
+
<<~RUBY
|
41
|
+
NAME READY UP-TO-DATE AVAILABLE AGE
|
42
|
+
#{name} #{ready} #{deployments_up_to_date} #{deployments_available} #{age}
|
43
|
+
RUBY
|
44
|
+
end
|
45
|
+
let(:get_deployments_std_err) { '' }
|
46
|
+
let(:get_deployments_response) { [get_deployments_std_out, get_deployments_std_err, process_status] }
|
47
|
+
|
48
|
+
let(:get_stateful_sets_std_out) do
|
49
|
+
<<~RUBY
|
50
|
+
NAME READY AGE
|
51
|
+
#{name} #{ready} #{age}
|
52
|
+
RUBY
|
53
|
+
end
|
54
|
+
let(:get_stateful_sets_std_err) { '' }
|
55
|
+
let(:get_stateful_sets_response) { [get_stateful_sets_std_out, get_stateful_sets_std_err, process_status] }
|
56
|
+
|
24
57
|
describe '#initialize' do
|
25
58
|
subject { Kubecontrol::Client }
|
26
59
|
|
@@ -78,7 +111,7 @@ RSpec.describe Kubecontrol::Client do
|
|
78
111
|
end
|
79
112
|
|
80
113
|
describe '#find_pod_by_name' do
|
81
|
-
subject { Kubecontrol::Client.new.find_pod_by_name(
|
114
|
+
subject { Kubecontrol::Client.new.find_pod_by_name(name) }
|
82
115
|
|
83
116
|
before do
|
84
117
|
allow(Open3).to receive(:capture3).and_return get_pods_response
|
@@ -87,7 +120,7 @@ RSpec.describe Kubecontrol::Client do
|
|
87
120
|
it { is_expected.to be_an_instance_of Kubecontrol::Pod }
|
88
121
|
|
89
122
|
it 'returns the correct pod' do
|
90
|
-
expect(subject.name).to eq
|
123
|
+
expect(subject.name).to eq name
|
91
124
|
end
|
92
125
|
|
93
126
|
context 'pod does not exist' do
|
@@ -96,4 +129,145 @@ RSpec.describe Kubecontrol::Client do
|
|
96
129
|
it { is_expected.to be_nil }
|
97
130
|
end
|
98
131
|
end
|
132
|
+
|
133
|
+
describe '#services' do
|
134
|
+
subject { Kubecontrol::Client.new.services }
|
135
|
+
|
136
|
+
it 'send a kubectl request to the command line' do
|
137
|
+
expect(Open3).to receive(:capture3).with('kubectl -n default get services').and_return get_services_response
|
138
|
+
subject
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'returns an array of Kubecontrol::Services' do
|
142
|
+
allow(Open3).to receive(:capture3).and_return get_services_response
|
143
|
+
result = subject
|
144
|
+
expect(result).to be_an_instance_of Array
|
145
|
+
expect(result.length).to eq 1
|
146
|
+
expect(result.first).to be_an_instance_of Kubecontrol::Service
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'no services found' do
|
150
|
+
let(:get_services_std_out) { '' }
|
151
|
+
|
152
|
+
before do
|
153
|
+
allow(Open3).to receive(:capture3).and_return get_services_response
|
154
|
+
end
|
155
|
+
|
156
|
+
it { is_expected.to be_empty }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#find_service_by_name' do
|
161
|
+
subject { Kubecontrol::Client.new.find_service_by_name(name) }
|
162
|
+
|
163
|
+
before do
|
164
|
+
allow(Open3).to receive(:capture3).and_return get_services_response
|
165
|
+
end
|
166
|
+
|
167
|
+
it { is_expected.to be_an_instance_of Kubecontrol::Service }
|
168
|
+
|
169
|
+
it 'returns the correct service' do
|
170
|
+
expect(subject.name).to eq name
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'service does not exist' do
|
174
|
+
let(:get_services_std_out) { '' }
|
175
|
+
|
176
|
+
it { is_expected.to be_nil }
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#deployments' do
|
181
|
+
subject { Kubecontrol::Client.new.deployments }
|
182
|
+
|
183
|
+
it 'send a kubectl request to the command line' do
|
184
|
+
expect(Open3).to receive(:capture3).with('kubectl -n default get deployments').and_return get_deployments_response
|
185
|
+
subject
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'returns an array of Kubecontrol::Deployments' do
|
189
|
+
allow(Open3).to receive(:capture3).and_return get_deployments_response
|
190
|
+
result = subject
|
191
|
+
expect(result).to be_an_instance_of Array
|
192
|
+
expect(result.length).to eq 1
|
193
|
+
expect(result.first).to be_an_instance_of Kubecontrol::Deployment
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'no deployments found' do
|
197
|
+
let(:get_deployments_std_out) { '' }
|
198
|
+
|
199
|
+
before do
|
200
|
+
allow(Open3).to receive(:capture3).and_return get_deployments_response
|
201
|
+
end
|
202
|
+
|
203
|
+
it { is_expected.to be_empty }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe '#find_deployment_by_name' do
|
208
|
+
subject { Kubecontrol::Client.new.find_deployment_by_name(name) }
|
209
|
+
|
210
|
+
before do
|
211
|
+
allow(Open3).to receive(:capture3).and_return get_deployments_response
|
212
|
+
end
|
213
|
+
|
214
|
+
it { is_expected.to be_an_instance_of Kubecontrol::Deployment }
|
215
|
+
|
216
|
+
it 'returns the correct deployment' do
|
217
|
+
expect(subject.name).to eq name
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'deployment does not exist' do
|
221
|
+
let(:get_deployments_std_out) { '' }
|
222
|
+
|
223
|
+
it { is_expected.to be_nil }
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe '#stateful_sets' do
|
228
|
+
subject { Kubecontrol::Client.new.stateful_sets }
|
229
|
+
|
230
|
+
it 'send a kubectl request to the command line' do
|
231
|
+
expect(Open3).to receive(:capture3).with('kubectl -n default get statefulsets').and_return get_stateful_sets_response
|
232
|
+
subject
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'returns an array of Kubecontrol::StatefulSet' do
|
236
|
+
allow(Open3).to receive(:capture3).and_return get_stateful_sets_response
|
237
|
+
result = subject
|
238
|
+
expect(result).to be_an_instance_of Array
|
239
|
+
expect(result.length).to eq 1
|
240
|
+
expect(result.first).to be_an_instance_of Kubecontrol::StatefulSet
|
241
|
+
end
|
242
|
+
|
243
|
+
context 'no stateful_sets found' do
|
244
|
+
let(:get_stateful_sets_std_out) { '' }
|
245
|
+
|
246
|
+
before do
|
247
|
+
allow(Open3).to receive(:capture3).and_return get_stateful_sets_response
|
248
|
+
end
|
249
|
+
|
250
|
+
it { is_expected.to be_empty }
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe '#find_stateful_set_by_name' do
|
255
|
+
subject { Kubecontrol::Client.new.find_stateful_set_by_name(name) }
|
256
|
+
|
257
|
+
before do
|
258
|
+
allow(Open3).to receive(:capture3).and_return get_stateful_sets_response
|
259
|
+
end
|
260
|
+
|
261
|
+
it { is_expected.to be_an_instance_of Kubecontrol::StatefulSet }
|
262
|
+
|
263
|
+
it 'returns the correct stateful_sets' do
|
264
|
+
expect(subject.name).to eq name
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'stateful_set does not exist' do
|
268
|
+
let(:get_stateful_sets_std_out) { '' }
|
269
|
+
|
270
|
+
it { is_expected.to be_nil }
|
271
|
+
end
|
272
|
+
end
|
99
273
|
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/kubecontrol/deployment'
|
3
|
+
|
4
|
+
RSpec.describe Kubecontrol::Deployment do
|
5
|
+
let(:deployment_name) { 'foo_deployment' }
|
6
|
+
let(:deployment_age) { '2d' }
|
7
|
+
let(:deployment_ready) { '1/1' }
|
8
|
+
let(:deployment_up_to_date) { '1' }
|
9
|
+
let(:deployment_available) { '1' }
|
10
|
+
let(:namespace) { 'default' }
|
11
|
+
let(:client) { Kubecontrol::Client.new }
|
12
|
+
let(:deployment) { Kubecontrol::Deployment.new(deployment_name, deployment_ready, deployment_up_to_date, deployment_available, deployment_age, namespace, client) }
|
13
|
+
|
14
|
+
describe '#initialize' do
|
15
|
+
subject { deployment }
|
16
|
+
|
17
|
+
it 'sets the deployment name field' do
|
18
|
+
expect(subject.name).to eq deployment_name
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets the deployment age field' do
|
22
|
+
expect(subject.age).to eq deployment_age
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'sets the deployment ready field' do
|
26
|
+
expect(subject.ready).to eq deployment_ready
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets the deployment up to date field' do
|
30
|
+
expect(subject.up_to_date).to eq deployment_up_to_date
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'sets the deployment available field' do
|
34
|
+
expect(subject.available).to eq deployment_available
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'sets the deployment namespace' do
|
38
|
+
expect(subject.namespace).to eq namespace
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sets the client' do
|
42
|
+
expect(subject.client).to eq client
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#ready?' do
|
47
|
+
subject { deployment.ready? }
|
48
|
+
|
49
|
+
context 'all replicas running' do
|
50
|
+
let(:deployment_ready) { '3/3' }
|
51
|
+
|
52
|
+
it { is_expected.to eq true }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'some replicas not running' do
|
56
|
+
let(:deployment_ready) { '2/3' }
|
57
|
+
|
58
|
+
it { is_expected.to eq true }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'no replicas running' do
|
62
|
+
let(:deployment_ready) { '0/3' }
|
63
|
+
|
64
|
+
it { is_expected.to eq false }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#all_ready?' do
|
69
|
+
subject { deployment.all_ready? }
|
70
|
+
|
71
|
+
context 'all replicas running' do
|
72
|
+
let(:deployment_ready) { '3/3' }
|
73
|
+
|
74
|
+
it { is_expected.to eq true }
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'some replicas not running' do
|
78
|
+
let(:deployment_ready) { '2/3' }
|
79
|
+
|
80
|
+
it { is_expected.to eq false }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'no replicas running' do
|
84
|
+
let(:deployment_ready) { '0/3' }
|
85
|
+
|
86
|
+
it { is_expected.to eq false }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#available?' do
|
91
|
+
subject { deployment.available? }
|
92
|
+
|
93
|
+
context 'all replicas available' do
|
94
|
+
let(:deployment_available) { '3' }
|
95
|
+
|
96
|
+
it { is_expected.to eq true }
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'some replicas not available' do
|
100
|
+
let(:deployment_available) { '2' }
|
101
|
+
|
102
|
+
it { is_expected.to eq true }
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'no replicas available' do
|
106
|
+
let(:deployment_available) { '0' }
|
107
|
+
|
108
|
+
it { is_expected.to eq false }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#up_to_date?' do
|
113
|
+
subject { deployment.up_to_date? }
|
114
|
+
|
115
|
+
context 'all replicas up to date' do
|
116
|
+
let(:deployment_up_to_date) { '3' }
|
117
|
+
|
118
|
+
it { is_expected.to eq true }
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'some replicas not up to date' do
|
122
|
+
let(:deployment_up_to_date) { '2' }
|
123
|
+
|
124
|
+
it { is_expected.to eq true }
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'no replicas up to date' do
|
128
|
+
let(:deployment_up_to_date) { '0' }
|
129
|
+
|
130
|
+
it { is_expected.to eq false }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#scale' do
|
135
|
+
let(:scale_count) { '5' }
|
136
|
+
|
137
|
+
let(:kubectl_command) { "scale deployment #{deployment_name} --replicas=#{scale_count}" }
|
138
|
+
let(:std_out) { "deployment.extensions/#{deployment_name} scaled" }
|
139
|
+
let(:std_err) { '' }
|
140
|
+
let(:status_code) { 0 }
|
141
|
+
let(:kubectl_command_response) { [std_out, std_err, status_code] }
|
142
|
+
|
143
|
+
subject { deployment.scale(scale_count) }
|
144
|
+
|
145
|
+
it 'sends the scale command via Kubecontrol::Client#kubectl_command' do
|
146
|
+
expect(deployment.client).to receive(:kubectl_command).with(kubectl_command).and_return kubectl_command_response
|
147
|
+
subject
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'returns an array of std_out, std_err, and status code' do
|
151
|
+
allow(deployment.client).to receive(:kubectl_command).with(kubectl_command).and_return kubectl_command_response
|
152
|
+
std_out_response, std_err_response, status_code_response = subject
|
153
|
+
expect(std_out_response).to eq std_out
|
154
|
+
expect(std_err_response).to eq std_err
|
155
|
+
expect(status_code_response).to eq status_code
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/kubecontrol/stateful_set'
|
3
|
+
|
4
|
+
RSpec.describe Kubecontrol::StatefulSet do
|
5
|
+
let(:stateful_set_name) { 'foo_stateful_set' }
|
6
|
+
let(:stateful_set_age) { '2d' }
|
7
|
+
let(:stateful_set_ready) { '1/1' }
|
8
|
+
let(:namespace) { 'default' }
|
9
|
+
let(:client) { Kubecontrol::Client.new }
|
10
|
+
let(:stateful_set) { Kubecontrol::StatefulSet.new(stateful_set_name, stateful_set_ready, stateful_set_age, namespace, client) }
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
subject { stateful_set }
|
14
|
+
|
15
|
+
it 'sets the stateful_set name field' do
|
16
|
+
expect(subject.name).to eq stateful_set_name
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sets the stateful_set age field' do
|
20
|
+
expect(subject.age).to eq stateful_set_age
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets the stateful_set ready field' do
|
24
|
+
expect(subject.ready).to eq stateful_set_ready
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'sets the stateful_set namespace' do
|
28
|
+
expect(subject.namespace).to eq namespace
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sets the client' do
|
32
|
+
expect(subject.client).to eq client
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#ready?' do
|
37
|
+
subject { stateful_set.ready? }
|
38
|
+
|
39
|
+
context 'all replicas running' do
|
40
|
+
let(:stateful_set_ready) { '3/3' }
|
41
|
+
|
42
|
+
it { is_expected.to eq true }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'some replicas not running' do
|
46
|
+
let(:stateful_set_ready) { '2/3' }
|
47
|
+
|
48
|
+
it { is_expected.to eq true }
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'no replicas running' do
|
52
|
+
let(:stateful_set_ready) { '0/3' }
|
53
|
+
|
54
|
+
it { is_expected.to eq false }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#all_ready?' do
|
59
|
+
subject { stateful_set.all_ready? }
|
60
|
+
|
61
|
+
context 'all replicas running' do
|
62
|
+
let(:stateful_set_ready) { '3/3' }
|
63
|
+
|
64
|
+
it { is_expected.to eq true }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'some replicas not running' do
|
68
|
+
let(:stateful_set_ready) { '2/3' }
|
69
|
+
|
70
|
+
it { is_expected.to eq false }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'no replicas running' do
|
74
|
+
let(:stateful_set_ready) { '0/3' }
|
75
|
+
|
76
|
+
it { is_expected.to eq false }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#scale' do
|
81
|
+
let(:scale_count) { '5' }
|
82
|
+
|
83
|
+
let(:kubectl_command) { "scale statefulset #{stateful_set_name} --replicas=#{scale_count}" }
|
84
|
+
let(:std_out) { "stateful_set.extensions/#{stateful_set_name} scaled" }
|
85
|
+
let(:std_err) { '' }
|
86
|
+
let(:status_code) { 0 }
|
87
|
+
let(:kubectl_command_response) { [std_out, std_err, status_code] }
|
88
|
+
|
89
|
+
subject { stateful_set.scale(scale_count) }
|
90
|
+
|
91
|
+
it 'sends the scale command via Kubecontrol::Client#kubectl_command' do
|
92
|
+
expect(stateful_set.client).to receive(:kubectl_command).with(kubectl_command).and_return kubectl_command_response
|
93
|
+
subject
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns an array of std_out, std_err, and status code' do
|
97
|
+
allow(stateful_set.client).to receive(:kubectl_command).with(kubectl_command).and_return kubectl_command_response
|
98
|
+
std_out_response, std_err_response, status_code_response = subject
|
99
|
+
expect(std_out_response).to eq std_out
|
100
|
+
expect(std_err_response).to eq std_err
|
101
|
+
expect(status_code_response).to eq status_code
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubecontrol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Adkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,8 +75,7 @@ executables:
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
- ".github/workflows/
|
79
|
-
- ".github/workflows/ruby.yml"
|
78
|
+
- ".github/workflows/unit_tests.yml"
|
80
79
|
- ".gitignore"
|
81
80
|
- ".rspec"
|
82
81
|
- CHANGELOG.md
|
@@ -90,12 +89,16 @@ files:
|
|
90
89
|
- kubecontrol.gemspec
|
91
90
|
- lib/kubecontrol.rb
|
92
91
|
- lib/kubecontrol/client.rb
|
92
|
+
- lib/kubecontrol/deployment.rb
|
93
93
|
- lib/kubecontrol/pod.rb
|
94
94
|
- lib/kubecontrol/service.rb
|
95
|
+
- lib/kubecontrol/stateful_set.rb
|
95
96
|
- lib/kubecontrol/version.rb
|
96
97
|
- spec/kubecontrol/client_spec.rb
|
98
|
+
- spec/kubecontrol/deployment_spec.rb
|
97
99
|
- spec/kubecontrol/pod_spec.rb
|
98
100
|
- spec/kubecontrol/service_spec.rb
|
101
|
+
- spec/kubecontrol/stateful_set_spec.rb
|
99
102
|
- spec/kubecontrol_spec.rb
|
100
103
|
- spec/spec_helper.rb
|
101
104
|
homepage: https://github.com/madkin10/kubecontrol
|
@@ -120,8 +123,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
123
|
- !ruby/object:Gem::Version
|
121
124
|
version: '0'
|
122
125
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.1.2
|
124
127
|
signing_key:
|
125
128
|
specification_version: 4
|
126
129
|
summary: Simple ruby wrapper for `kubectl` commands
|
127
|
-
test_files:
|
130
|
+
test_files:
|
131
|
+
- spec/kubecontrol/client_spec.rb
|
132
|
+
- spec/kubecontrol/deployment_spec.rb
|
133
|
+
- spec/kubecontrol/pod_spec.rb
|
134
|
+
- spec/kubecontrol/service_spec.rb
|
135
|
+
- spec/kubecontrol/stateful_set_spec.rb
|
136
|
+
- spec/kubecontrol_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
@@ -1,44 +0,0 @@
|
|
1
|
-
name: Ruby Gem
|
2
|
-
|
3
|
-
on:
|
4
|
-
pull_request:
|
5
|
-
branches:
|
6
|
-
- master
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
|
11
|
-
jobs:
|
12
|
-
build:
|
13
|
-
name: Build + Publish
|
14
|
-
runs-on: ubuntu-latest
|
15
|
-
|
16
|
-
steps:
|
17
|
-
- uses: actions/checkout@master
|
18
|
-
- name: Set up Ruby 2.6
|
19
|
-
uses: actions/setup-ruby@v1
|
20
|
-
with:
|
21
|
-
version: 2.6.x
|
22
|
-
|
23
|
-
- name: Publish to GPR
|
24
|
-
run: |
|
25
|
-
mkdir -p $HOME/.gem
|
26
|
-
touch $HOME/.gem/credentials
|
27
|
-
chmod 0600 $HOME/.gem/credentials
|
28
|
-
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
29
|
-
gem build *.gemspec
|
30
|
-
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
31
|
-
env:
|
32
|
-
GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
|
33
|
-
OWNER: madkin10
|
34
|
-
|
35
|
-
- name: Publish to RubyGems
|
36
|
-
run: |
|
37
|
-
mkdir -p $HOME/.gem
|
38
|
-
touch $HOME/.gem/credentials
|
39
|
-
chmod 0600 $HOME/.gem/credentials
|
40
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
41
|
-
gem build *.gemspec
|
42
|
-
gem push *.gem
|
43
|
-
env:
|
44
|
-
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|