kubecontrol 0.3.5 → 0.4.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/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +26 -0
- data/lib/kubecontrol.rb +1 -4
- data/lib/kubecontrol/client.rb +23 -8
- data/lib/kubecontrol/resources.rb +5 -0
- data/lib/kubecontrol/resources/deployment.rb +40 -0
- data/lib/kubecontrol/resources/pod.rb +37 -0
- data/lib/kubecontrol/resources/secret.rb +18 -0
- data/lib/kubecontrol/resources/service.rb +20 -0
- data/lib/kubecontrol/resources/stateful_set.rb +30 -0
- data/lib/kubecontrol/version.rb +1 -1
- data/spec/kubecontrol/client_spec.rb +150 -8
- data/spec/kubecontrol/{deployment_spec.rb → resources/deployment_spec.rb} +4 -4
- data/spec/kubecontrol/{pod_spec.rb → resources/pod_spec.rb} +7 -7
- data/spec/kubecontrol/resources/secret_spec.rb +40 -0
- data/spec/kubecontrol/{service_spec.rb → resources/service_spec.rb} +4 -4
- data/spec/kubecontrol/{stateful_set_spec.rb → resources/stateful_set_spec.rb} +4 -4
- metadata +18 -14
- data/lib/kubecontrol/deployment.rb +0 -38
- data/lib/kubecontrol/pod.rb +0 -35
- data/lib/kubecontrol/service.rb +0 -18
- data/lib/kubecontrol/stateful_set.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 947d4bdb94d24c41570d476fe6a57692b26a4c04b44af915dc334c15842f586c
|
4
|
+
data.tar.gz: abd66e519fd96e3f871e6c57c0593f3fd9894d0762df6f295f4c0d399d354eda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c678d96f09936c328f11859639d577d7faeba1903d1267ab226f9c2bc4ccce3af168d54ea4dd5b313ee0237987c6e6ac17efbe6249954f181951ce3fff8288d
|
7
|
+
data.tar.gz: e050203e479656d5d9346611e7f7861c2de85c0102b2c620a769df5e31671febe5a261713b245b4e225a0fb608018ff4438bc6b44bb1ce83e686c0d416cfc9b2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# v0.4.5 / 02-24-2020
|
2
|
+
- [ENHANCEMENT] Kubecontrol::Resources - Move all existing resources(Pod, Deployment, Service, Secret, Stateful Set) into a 'Resources' namespace.
|
3
|
+
- [FEATURE] Kubecontrol::Secret
|
4
|
+
- [FEATURE] Kubecontrol::Client#apply
|
5
|
+
|
1
6
|
# v0.3.5 / 02-21-2020
|
2
7
|
- [FEATURE] Kubecontrol::Deployment
|
3
8
|
- [FEATURE] Kubecontrol::StatefulSet
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -27,6 +27,10 @@ require 'kubecontrol'
|
|
27
27
|
# create new client
|
28
28
|
kubectl_client = Kubecontrol.client.new
|
29
29
|
|
30
|
+
#Exec an kubectl apply command
|
31
|
+
std_out, std_err, exit_code = kubectl_client.apply(file_path: 'path/to/deployment.yaml')
|
32
|
+
std_out, std_err, exit_code = kubectl_client.apply(kustomization_dir: 'path/to/kustomization_dir')
|
33
|
+
|
30
34
|
#Exec an arbitrary kubectl command
|
31
35
|
std_out, std_err, exit_code = kubectl_client.kubectl_command 'get deployments'
|
32
36
|
```
|
@@ -145,6 +149,28 @@ stateful_set.all_ready?
|
|
145
149
|
stateful_set.scale(5)
|
146
150
|
```
|
147
151
|
|
152
|
+
#### Secrets
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
require 'kubecontrol'
|
156
|
+
|
157
|
+
# create new client
|
158
|
+
kubectl_client = Kubecontrol.client.new
|
159
|
+
|
160
|
+
# all secrets for namespace
|
161
|
+
secrets = kubectl_client.secrets
|
162
|
+
|
163
|
+
# find secret by name regex
|
164
|
+
secret = kubectl_client.find_secret_by_name /foo-api-.*/
|
165
|
+
|
166
|
+
# access secret information
|
167
|
+
secret.name
|
168
|
+
secret.type
|
169
|
+
secret.data
|
170
|
+
secret.age
|
171
|
+
secret.namespace
|
172
|
+
```
|
173
|
+
|
148
174
|
## Development
|
149
175
|
|
150
176
|
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.
|
data/lib/kubecontrol.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'kubecontrol/version'
|
2
2
|
require 'kubecontrol/client'
|
3
|
-
require 'kubecontrol/
|
4
|
-
require 'kubecontrol/service'
|
5
|
-
require 'kubecontrol/stateful_set'
|
6
|
-
require 'kubecontrol/deployment'
|
3
|
+
require 'kubecontrol/resources'
|
7
4
|
|
8
5
|
module Kubecontrol
|
9
6
|
class Error < StandardError; end
|
data/lib/kubecontrol/client.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
require 'open3'
|
2
|
-
require_relative '
|
3
|
-
require_relative 'deployment'
|
4
|
-
require_relative 'stateful_set'
|
5
|
-
require_relative 'service'
|
2
|
+
require_relative 'resources'
|
6
3
|
|
7
4
|
module Kubecontrol
|
8
5
|
class Client
|
@@ -14,20 +11,38 @@ module Kubecontrol
|
|
14
11
|
@namespace = namespace
|
15
12
|
end
|
16
13
|
|
14
|
+
def apply(file_path: nil, kustomization_dir: nil)
|
15
|
+
raise ArgumentError.new('Must pass a file_path or kustomization_dir keyword argument') if (file_path.nil? && kustomization_dir.nil?) || (file_path && kustomization_dir)
|
16
|
+
|
17
|
+
if file_path
|
18
|
+
kubectl_command("apply -f #{file_path}")
|
19
|
+
else
|
20
|
+
kubectl_command("apply -k #{kustomization_dir}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
17
24
|
def pods
|
18
|
-
get_resource(Pod, 5)
|
25
|
+
get_resource(Resources::Pod, 5)
|
19
26
|
end
|
20
27
|
|
21
28
|
def deployments
|
22
|
-
get_resource(Deployment, 5)
|
29
|
+
get_resource(Resources::Deployment, 5)
|
23
30
|
end
|
24
31
|
|
25
32
|
def stateful_sets
|
26
|
-
get_resource(StatefulSet, 3)
|
33
|
+
get_resource(Resources::StatefulSet, 3)
|
27
34
|
end
|
28
35
|
|
29
36
|
def services
|
30
|
-
get_resource(Service, 6)
|
37
|
+
get_resource(Resources::Service, 6)
|
38
|
+
end
|
39
|
+
|
40
|
+
def secrets
|
41
|
+
get_resource(Resources::Secret, 4)
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_secret_by_name(name_regex)
|
45
|
+
secrets.find { |secret| secret.name.match?(name_regex) }
|
31
46
|
end
|
32
47
|
|
33
48
|
def find_service_by_name(name_regex)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Kubecontrol
|
2
|
+
module Resources
|
3
|
+
class Deployment
|
4
|
+
RESOURCE_NAME = 'deployments'.freeze
|
5
|
+
|
6
|
+
attr_reader :name, :ready, :up_to_date, :available, :age, :namespace, :client
|
7
|
+
|
8
|
+
def initialize(name, ready, up_to_date, available, age, namespace, client)
|
9
|
+
@name = name
|
10
|
+
@ready = ready
|
11
|
+
@up_to_date = up_to_date
|
12
|
+
@available = available
|
13
|
+
@age = age
|
14
|
+
@namespace = namespace
|
15
|
+
@client = client
|
16
|
+
end
|
17
|
+
|
18
|
+
def ready?
|
19
|
+
@ready.split('/').first != '0'
|
20
|
+
end
|
21
|
+
|
22
|
+
def all_ready?
|
23
|
+
max_pods = @ready.split('/').last
|
24
|
+
@ready == "#{max_pods}/#{max_pods}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def available?
|
28
|
+
@available.to_i > 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def up_to_date?
|
32
|
+
@up_to_date.to_i > 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def scale(count)
|
36
|
+
@client.kubectl_command("scale deployment #{@name} --replicas=#{count}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Kubecontrol
|
2
|
+
module Resources
|
3
|
+
class Pod
|
4
|
+
RESOURCE_NAME = 'pods'.freeze
|
5
|
+
RUNNING = 'Running'.freeze
|
6
|
+
|
7
|
+
attr_reader :name, :ready, :status, :restarts, :age, :namespace, :client
|
8
|
+
|
9
|
+
def initialize(name, ready, status, restarts, age, namespace, client)
|
10
|
+
@name = name
|
11
|
+
@ready = ready
|
12
|
+
@status = status
|
13
|
+
@restarts = restarts
|
14
|
+
@age = age
|
15
|
+
@namespace = namespace
|
16
|
+
@client = client
|
17
|
+
end
|
18
|
+
|
19
|
+
def stopped?
|
20
|
+
@status != RUNNING
|
21
|
+
end
|
22
|
+
|
23
|
+
def running?
|
24
|
+
@status == RUNNING
|
25
|
+
end
|
26
|
+
|
27
|
+
def ready?
|
28
|
+
pod_containers = @ready.split('/').last
|
29
|
+
@ready == "#{pod_containers}/#{pod_containers}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def exec(command)
|
33
|
+
@client.kubectl_command("exec -i #{name} -- sh -c \"#{command.gsub('"', '\"')}\"")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kubecontrol
|
2
|
+
module Resources
|
3
|
+
class Secret
|
4
|
+
RESOURCE_NAME = 'secrets'.freeze
|
5
|
+
|
6
|
+
attr_reader :name, :type, :data, :age, :namespace, :client
|
7
|
+
|
8
|
+
def initialize(name, type, data, age, namespace, client)
|
9
|
+
@name = name
|
10
|
+
@type = type
|
11
|
+
@data = data
|
12
|
+
@age = age
|
13
|
+
@namespace = namespace
|
14
|
+
@client = client
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Kubecontrol
|
2
|
+
module Resources
|
3
|
+
class Service
|
4
|
+
RESOURCE_NAME = 'services'.freeze
|
5
|
+
|
6
|
+
attr_reader :name, :age, :type, :cluster_ip, :external_ip, :ports, :namespace, :client
|
7
|
+
|
8
|
+
def initialize(name, type, cluster_ip, external_ip, ports, age, namespace, client)
|
9
|
+
@name = name
|
10
|
+
@age = age
|
11
|
+
@type = type
|
12
|
+
@cluster_ip = cluster_ip
|
13
|
+
@external_ip = external_ip
|
14
|
+
@ports = ports
|
15
|
+
@namespace = namespace
|
16
|
+
@client = client
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Kubecontrol
|
2
|
+
module Resources
|
3
|
+
class StatefulSet
|
4
|
+
RESOURCE_NAME = 'statefulsets'.freeze
|
5
|
+
|
6
|
+
attr_reader :name, :ready, :age, :namespace, :client
|
7
|
+
|
8
|
+
def initialize(name, ready, age, namespace, client)
|
9
|
+
@name = name
|
10
|
+
@ready = ready
|
11
|
+
@age = age
|
12
|
+
@namespace = namespace
|
13
|
+
@client = client
|
14
|
+
end
|
15
|
+
|
16
|
+
def ready?
|
17
|
+
@ready.split('/').first != '0'
|
18
|
+
end
|
19
|
+
|
20
|
+
def all_ready?
|
21
|
+
max_pods = @ready.split('/').last
|
22
|
+
@ready == "#{max_pods}/#{max_pods}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def scale(count)
|
26
|
+
@client.kubectl_command("scale statefulset #{@name} --replicas=#{count}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/kubecontrol/version.rb
CHANGED
@@ -54,6 +54,17 @@ RSpec.describe Kubecontrol::Client do
|
|
54
54
|
let(:get_stateful_sets_std_err) { '' }
|
55
55
|
let(:get_stateful_sets_response) { [get_stateful_sets_std_out, get_stateful_sets_std_err, process_status] }
|
56
56
|
|
57
|
+
let(:secret_type) { 'Opaque' }
|
58
|
+
let(:secret_data) { '5' }
|
59
|
+
let(:get_secrets_std_out) do
|
60
|
+
<<~RUBY
|
61
|
+
NAME TYPE DATA AGE
|
62
|
+
#{name} #{secret_type} #{secret_data} #{age}
|
63
|
+
RUBY
|
64
|
+
end
|
65
|
+
let(:get_secrets_std_err) { '' }
|
66
|
+
let(:get_secrets_response) { [get_secrets_std_out, get_secrets_std_err, process_status] }
|
67
|
+
|
57
68
|
describe '#initialize' do
|
58
69
|
subject { Kubecontrol::Client }
|
59
70
|
|
@@ -83,6 +94,90 @@ RSpec.describe Kubecontrol::Client do
|
|
83
94
|
end
|
84
95
|
end
|
85
96
|
|
97
|
+
describe '#kubectl_command' do
|
98
|
+
let(:command) { 'get pods' }
|
99
|
+
|
100
|
+
subject { Kubecontrol::Client.new.kubectl_command(command) }
|
101
|
+
|
102
|
+
before do
|
103
|
+
allow(Open3).to receive(:capture3).and_return get_pods_response
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'sends a kubectl request to the command line' do
|
107
|
+
expect(Open3).to receive(:capture3).with("kubectl -n default #{command}").and_return get_pods_response
|
108
|
+
subject
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns an array of std_out, std_err, and status code' do
|
112
|
+
std_out_response, std_err_response, status_code_response = subject
|
113
|
+
expect(std_out_response).to eq get_pods_std_out
|
114
|
+
expect(std_err_response).to eq get_pods_std_err
|
115
|
+
expect(status_code_response).to eq process_status
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#apply' do
|
120
|
+
let(:std_out) { 'deployment.extensions/deployment configured' }
|
121
|
+
let(:std_err) { '' }
|
122
|
+
let(:apply_response) { ['deployment.extensions/deployment configured', '', process_status] }
|
123
|
+
|
124
|
+
before do
|
125
|
+
allow(Open3).to receive(:capture3).and_return apply_response
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'missing file path or kustomization dir keyword arguments' do
|
129
|
+
subject { Kubecontrol::Client.new.apply }
|
130
|
+
|
131
|
+
it 'raises an ArgumentError' do
|
132
|
+
expect{subject}.to raise_error(ArgumentError)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'with both file path and kustomization dir keyword arguments' do
|
137
|
+
subject { Kubecontrol::Client.new.apply(file_path: 'foo', kustomization_dir: 'bar') }
|
138
|
+
|
139
|
+
it 'raises an ArgumentError' do
|
140
|
+
expect{subject}.to raise_error(ArgumentError)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'with a file path' do
|
145
|
+
let(:file_path) { 'foo/bar/deployment.yaml' }
|
146
|
+
|
147
|
+
subject { Kubecontrol::Client.new.apply(file_path: file_path) }
|
148
|
+
|
149
|
+
it 'send a kubectl request to the command line' do
|
150
|
+
expect(Open3).to receive(:capture3).with("kubectl -n default apply -f #{file_path}").and_return apply_response
|
151
|
+
subject
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'returns an array of std_out, std_err, and status code' do
|
155
|
+
std_out_response, std_err_response, status_code_response = subject
|
156
|
+
expect(std_out_response).to eq std_out
|
157
|
+
expect(std_err_response).to eq std_err
|
158
|
+
expect(status_code_response).to eq process_status
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'with a kustomization directory' do
|
163
|
+
let(:kustomization_dir) { 'foo/bar/kustomization' }
|
164
|
+
|
165
|
+
subject { Kubecontrol::Client.new.apply(kustomization_dir: kustomization_dir) }
|
166
|
+
|
167
|
+
it 'send a kubectl request to the command line' do
|
168
|
+
expect(Open3).to receive(:capture3).with("kubectl -n default apply -k #{kustomization_dir}").and_return apply_response
|
169
|
+
subject
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'returns an array of std_out, std_err, and status code' do
|
173
|
+
std_out_response, std_err_response, status_code_response = subject
|
174
|
+
expect(std_out_response).to eq std_out
|
175
|
+
expect(std_err_response).to eq std_err
|
176
|
+
expect(status_code_response).to eq process_status
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
86
181
|
describe '#pods' do
|
87
182
|
subject { Kubecontrol::Client.new.pods }
|
88
183
|
|
@@ -96,7 +191,7 @@ RSpec.describe Kubecontrol::Client do
|
|
96
191
|
result = subject
|
97
192
|
expect(result).to be_an_instance_of Array
|
98
193
|
expect(result.length).to eq 1
|
99
|
-
expect(result.first).to be_an_instance_of Kubecontrol::Pod
|
194
|
+
expect(result.first).to be_an_instance_of Kubecontrol::Resources::Pod
|
100
195
|
end
|
101
196
|
|
102
197
|
context 'no pods found' do
|
@@ -117,7 +212,7 @@ RSpec.describe Kubecontrol::Client do
|
|
117
212
|
allow(Open3).to receive(:capture3).and_return get_pods_response
|
118
213
|
end
|
119
214
|
|
120
|
-
it { is_expected.to be_an_instance_of Kubecontrol::Pod }
|
215
|
+
it { is_expected.to be_an_instance_of Kubecontrol::Resources::Pod }
|
121
216
|
|
122
217
|
it 'returns the correct pod' do
|
123
218
|
expect(subject.name).to eq name
|
@@ -143,7 +238,7 @@ RSpec.describe Kubecontrol::Client do
|
|
143
238
|
result = subject
|
144
239
|
expect(result).to be_an_instance_of Array
|
145
240
|
expect(result.length).to eq 1
|
146
|
-
expect(result.first).to be_an_instance_of Kubecontrol::Service
|
241
|
+
expect(result.first).to be_an_instance_of Kubecontrol::Resources::Service
|
147
242
|
end
|
148
243
|
|
149
244
|
context 'no services found' do
|
@@ -164,7 +259,7 @@ RSpec.describe Kubecontrol::Client do
|
|
164
259
|
allow(Open3).to receive(:capture3).and_return get_services_response
|
165
260
|
end
|
166
261
|
|
167
|
-
it { is_expected.to be_an_instance_of Kubecontrol::Service }
|
262
|
+
it { is_expected.to be_an_instance_of Kubecontrol::Resources::Service }
|
168
263
|
|
169
264
|
it 'returns the correct service' do
|
170
265
|
expect(subject.name).to eq name
|
@@ -190,7 +285,7 @@ RSpec.describe Kubecontrol::Client do
|
|
190
285
|
result = subject
|
191
286
|
expect(result).to be_an_instance_of Array
|
192
287
|
expect(result.length).to eq 1
|
193
|
-
expect(result.first).to be_an_instance_of Kubecontrol::Deployment
|
288
|
+
expect(result.first).to be_an_instance_of Kubecontrol::Resources::Deployment
|
194
289
|
end
|
195
290
|
|
196
291
|
context 'no deployments found' do
|
@@ -211,7 +306,7 @@ RSpec.describe Kubecontrol::Client do
|
|
211
306
|
allow(Open3).to receive(:capture3).and_return get_deployments_response
|
212
307
|
end
|
213
308
|
|
214
|
-
it { is_expected.to be_an_instance_of Kubecontrol::Deployment }
|
309
|
+
it { is_expected.to be_an_instance_of Kubecontrol::Resources::Deployment }
|
215
310
|
|
216
311
|
it 'returns the correct deployment' do
|
217
312
|
expect(subject.name).to eq name
|
@@ -237,7 +332,7 @@ RSpec.describe Kubecontrol::Client do
|
|
237
332
|
result = subject
|
238
333
|
expect(result).to be_an_instance_of Array
|
239
334
|
expect(result.length).to eq 1
|
240
|
-
expect(result.first).to be_an_instance_of Kubecontrol::StatefulSet
|
335
|
+
expect(result.first).to be_an_instance_of Kubecontrol::Resources::StatefulSet
|
241
336
|
end
|
242
337
|
|
243
338
|
context 'no stateful_sets found' do
|
@@ -258,7 +353,7 @@ RSpec.describe Kubecontrol::Client do
|
|
258
353
|
allow(Open3).to receive(:capture3).and_return get_stateful_sets_response
|
259
354
|
end
|
260
355
|
|
261
|
-
it { is_expected.to be_an_instance_of Kubecontrol::StatefulSet }
|
356
|
+
it { is_expected.to be_an_instance_of Kubecontrol::Resources::StatefulSet }
|
262
357
|
|
263
358
|
it 'returns the correct stateful_sets' do
|
264
359
|
expect(subject.name).to eq name
|
@@ -270,4 +365,51 @@ RSpec.describe Kubecontrol::Client do
|
|
270
365
|
it { is_expected.to be_nil }
|
271
366
|
end
|
272
367
|
end
|
368
|
+
|
369
|
+
describe '#secrets' do
|
370
|
+
subject { Kubecontrol::Client.new.secrets }
|
371
|
+
|
372
|
+
it 'send a kubectl request to the command line' do
|
373
|
+
expect(Open3).to receive(:capture3).with('kubectl -n default get secrets').and_return get_secrets_response
|
374
|
+
subject
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'returns an array of Kubecontrol::Secret' do
|
378
|
+
allow(Open3).to receive(:capture3).and_return get_secrets_response
|
379
|
+
result = subject
|
380
|
+
expect(result).to be_an_instance_of Array
|
381
|
+
expect(result.length).to eq 1
|
382
|
+
expect(result.first).to be_an_instance_of Kubecontrol::Resources::Secret
|
383
|
+
end
|
384
|
+
|
385
|
+
context 'no secrets found' do
|
386
|
+
let(:get_secrets_std_out) { '' }
|
387
|
+
|
388
|
+
before do
|
389
|
+
allow(Open3).to receive(:capture3).and_return get_secrets_response
|
390
|
+
end
|
391
|
+
|
392
|
+
it { is_expected.to be_empty }
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
describe '#find_secret_by_name' do
|
397
|
+
subject { Kubecontrol::Client.new.find_secret_by_name(name) }
|
398
|
+
|
399
|
+
before do
|
400
|
+
allow(Open3).to receive(:capture3).and_return get_secrets_response
|
401
|
+
end
|
402
|
+
|
403
|
+
it { is_expected.to be_an_instance_of Kubecontrol::Resources::Secret }
|
404
|
+
|
405
|
+
it 'returns the correct secrets' do
|
406
|
+
expect(subject.name).to eq name
|
407
|
+
end
|
408
|
+
|
409
|
+
context 'secret does not exist' do
|
410
|
+
let(:get_secrets_std_out) { '' }
|
411
|
+
|
412
|
+
it { is_expected.to be_nil }
|
413
|
+
end
|
414
|
+
end
|
273
415
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/kubecontrol/resources/deployment'
|
3
3
|
|
4
|
-
RSpec.describe Kubecontrol::Deployment do
|
4
|
+
RSpec.describe Kubecontrol::Resources::Deployment do
|
5
5
|
let(:deployment_name) { 'foo_deployment' }
|
6
6
|
let(:deployment_age) { '2d' }
|
7
7
|
let(:deployment_ready) { '1/1' }
|
@@ -9,7 +9,7 @@ RSpec.describe Kubecontrol::Deployment do
|
|
9
9
|
let(:deployment_available) { '1' }
|
10
10
|
let(:namespace) { 'default' }
|
11
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) }
|
12
|
+
let(:deployment) { Kubecontrol::Resources::Deployment.new(deployment_name, deployment_ready, deployment_up_to_date, deployment_available, deployment_age, namespace, client) }
|
13
13
|
|
14
14
|
describe '#initialize' do
|
15
15
|
subject { deployment }
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/kubecontrol/resources/pod'
|
3
3
|
|
4
|
-
RSpec.describe Kubecontrol::Pod do
|
4
|
+
RSpec.describe Kubecontrol::Resources::Pod do
|
5
5
|
let(:pod_name) { 'foo_pod' }
|
6
6
|
let(:pod_ready) { '1/1' }
|
7
7
|
let(:pod_status) { 'Running' }
|
@@ -11,7 +11,7 @@ RSpec.describe Kubecontrol::Pod do
|
|
11
11
|
let(:client) { Kubecontrol::Client.new }
|
12
12
|
|
13
13
|
describe '#initialize' do
|
14
|
-
subject { Kubecontrol::Pod.new(pod_name, pod_ready, pod_status, pod_restarts, pod_age, namespace, client) }
|
14
|
+
subject { Kubecontrol::Resources::Pod.new(pod_name, pod_ready, pod_status, pod_restarts, pod_age, namespace, client) }
|
15
15
|
|
16
16
|
it 'sets the pod name field' do
|
17
17
|
expect(subject.name).to eq pod_name
|
@@ -43,7 +43,7 @@ RSpec.describe Kubecontrol::Pod do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe '#running?' do
|
46
|
-
subject { Kubecontrol::Pod.new(pod_name, pod_ready, pod_status, pod_restarts, pod_age, namespace, client).running? }
|
46
|
+
subject { Kubecontrol::Resources::Pod.new(pod_name, pod_ready, pod_status, pod_restarts, pod_age, namespace, client).running? }
|
47
47
|
|
48
48
|
context 'is running' do
|
49
49
|
it { is_expected.to eq true }
|
@@ -57,7 +57,7 @@ RSpec.describe Kubecontrol::Pod do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#stopped?' do
|
60
|
-
subject { Kubecontrol::Pod.new(pod_name, pod_ready, pod_status, pod_restarts, pod_age, namespace, client).stopped? }
|
60
|
+
subject { Kubecontrol::Resources::Pod.new(pod_name, pod_ready, pod_status, pod_restarts, pod_age, namespace, client).stopped? }
|
61
61
|
|
62
62
|
context 'is running' do
|
63
63
|
it { is_expected.to eq false }
|
@@ -77,7 +77,7 @@ RSpec.describe Kubecontrol::Pod do
|
|
77
77
|
let(:std_err) { '' }
|
78
78
|
let(:status_code) { 0 }
|
79
79
|
let(:kubectl_command_response) { [std_out, std_err, status_code] }
|
80
|
-
let(:pod) { Kubecontrol::Pod.new(pod_name, pod_ready, pod_status, pod_restarts, pod_age, namespace, client) }
|
80
|
+
let(:pod) { Kubecontrol::Resources::Pod.new(pod_name, pod_ready, pod_status, pod_restarts, pod_age, namespace, client) }
|
81
81
|
|
82
82
|
subject { pod.exec(command) }
|
83
83
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/kubecontrol/resources/secret'
|
3
|
+
|
4
|
+
RSpec.describe Kubecontrol::Resources::Secret do
|
5
|
+
let(:secret_name) { 'foo_secret' }
|
6
|
+
let(:secret_type) { 'Opaque' }
|
7
|
+
let(:secret_data) { '5' }
|
8
|
+
let(:secret_age) { '2d' }
|
9
|
+
let(:namespace) { 'default' }
|
10
|
+
let(:client) { Kubecontrol::Client.new }
|
11
|
+
let(:secret) { Kubecontrol::Resources::Secret.new(secret_name, secret_type, secret_data, secret_age, namespace, client) }
|
12
|
+
|
13
|
+
describe '#initialize' do
|
14
|
+
subject { secret }
|
15
|
+
|
16
|
+
it 'sets the secret name field' do
|
17
|
+
expect(subject.name).to eq secret_name
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets the secret type field' do
|
21
|
+
expect(subject.type).to eq secret_type
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets the secret data field' do
|
25
|
+
expect(subject.data).to eq secret_data
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets the secret age field' do
|
29
|
+
expect(subject.age).to eq secret_age
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'sets the secret namespace' do
|
33
|
+
expect(subject.namespace).to eq namespace
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'sets the client' do
|
37
|
+
expect(subject.client).to eq client
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/kubecontrol/resources/service'
|
3
3
|
|
4
|
-
RSpec.describe Kubecontrol::Service do
|
4
|
+
RSpec.describe Kubecontrol::Resources::Service do
|
5
5
|
let(:service_name) { 'foo_service' }
|
6
6
|
let(:service_age) { '2d' }
|
7
7
|
let(:service_type) { 'ClusterIP' }
|
@@ -12,7 +12,7 @@ RSpec.describe Kubecontrol::Service do
|
|
12
12
|
let(:client) { Kubecontrol::Client.new }
|
13
13
|
|
14
14
|
describe '#initialize' do
|
15
|
-
subject { Kubecontrol::Service.new(service_name, service_type, service_cluster_ip, service_external_ip, service_ports, service_age, namespace, client) }
|
15
|
+
subject { Kubecontrol::Resources::Service.new(service_name, service_type, service_cluster_ip, service_external_ip, service_ports, service_age, namespace, client) }
|
16
16
|
|
17
17
|
it 'sets the service name field' do
|
18
18
|
expect(subject.name).to eq service_name
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/kubecontrol/resources/stateful_set'
|
3
3
|
|
4
|
-
RSpec.describe Kubecontrol::StatefulSet do
|
4
|
+
RSpec.describe Kubecontrol::Resources::StatefulSet do
|
5
5
|
let(:stateful_set_name) { 'foo_stateful_set' }
|
6
6
|
let(:stateful_set_age) { '2d' }
|
7
7
|
let(:stateful_set_ready) { '1/1' }
|
8
8
|
let(:namespace) { 'default' }
|
9
9
|
let(:client) { Kubecontrol::Client.new }
|
10
|
-
let(:stateful_set) { Kubecontrol::StatefulSet.new(stateful_set_name, stateful_set_ready, stateful_set_age, namespace, client) }
|
10
|
+
let(:stateful_set) { Kubecontrol::Resources::StatefulSet.new(stateful_set_name, stateful_set_ready, stateful_set_age, namespace, client) }
|
11
11
|
|
12
12
|
describe '#initialize' do
|
13
13
|
subject { stateful_set }
|
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.4.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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,16 +89,19 @@ files:
|
|
89
89
|
- kubecontrol.gemspec
|
90
90
|
- lib/kubecontrol.rb
|
91
91
|
- lib/kubecontrol/client.rb
|
92
|
-
- lib/kubecontrol/
|
93
|
-
- lib/kubecontrol/
|
94
|
-
- lib/kubecontrol/
|
95
|
-
- lib/kubecontrol/
|
92
|
+
- lib/kubecontrol/resources.rb
|
93
|
+
- lib/kubecontrol/resources/deployment.rb
|
94
|
+
- lib/kubecontrol/resources/pod.rb
|
95
|
+
- lib/kubecontrol/resources/secret.rb
|
96
|
+
- lib/kubecontrol/resources/service.rb
|
97
|
+
- lib/kubecontrol/resources/stateful_set.rb
|
96
98
|
- lib/kubecontrol/version.rb
|
97
99
|
- spec/kubecontrol/client_spec.rb
|
98
|
-
- spec/kubecontrol/deployment_spec.rb
|
99
|
-
- spec/kubecontrol/pod_spec.rb
|
100
|
-
- spec/kubecontrol/
|
101
|
-
- spec/kubecontrol/
|
100
|
+
- spec/kubecontrol/resources/deployment_spec.rb
|
101
|
+
- spec/kubecontrol/resources/pod_spec.rb
|
102
|
+
- spec/kubecontrol/resources/secret_spec.rb
|
103
|
+
- spec/kubecontrol/resources/service_spec.rb
|
104
|
+
- spec/kubecontrol/resources/stateful_set_spec.rb
|
102
105
|
- spec/kubecontrol_spec.rb
|
103
106
|
- spec/spec_helper.rb
|
104
107
|
homepage: https://github.com/madkin10/kubecontrol
|
@@ -129,9 +132,10 @@ specification_version: 4
|
|
129
132
|
summary: Simple ruby wrapper for `kubectl` commands
|
130
133
|
test_files:
|
131
134
|
- spec/kubecontrol/client_spec.rb
|
132
|
-
- spec/kubecontrol/deployment_spec.rb
|
133
|
-
- spec/kubecontrol/pod_spec.rb
|
134
|
-
- spec/kubecontrol/
|
135
|
-
- spec/kubecontrol/
|
135
|
+
- spec/kubecontrol/resources/deployment_spec.rb
|
136
|
+
- spec/kubecontrol/resources/pod_spec.rb
|
137
|
+
- spec/kubecontrol/resources/secret_spec.rb
|
138
|
+
- spec/kubecontrol/resources/service_spec.rb
|
139
|
+
- spec/kubecontrol/resources/stateful_set_spec.rb
|
136
140
|
- spec/kubecontrol_spec.rb
|
137
141
|
- spec/spec_helper.rb
|
@@ -1,38 +0,0 @@
|
|
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
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Kubecontrol
|
2
|
-
class Pod
|
3
|
-
RESOURCE_NAME = 'pods'.freeze
|
4
|
-
RUNNING = 'Running'.freeze
|
5
|
-
|
6
|
-
attr_reader :name, :ready, :status, :restarts, :age, :namespace, :client
|
7
|
-
|
8
|
-
def initialize(name, ready, status, restarts, age, namespace, client)
|
9
|
-
@name = name
|
10
|
-
@ready = ready
|
11
|
-
@status = status
|
12
|
-
@restarts = restarts
|
13
|
-
@age = age
|
14
|
-
@namespace = namespace
|
15
|
-
@client = client
|
16
|
-
end
|
17
|
-
|
18
|
-
def stopped?
|
19
|
-
@status != RUNNING
|
20
|
-
end
|
21
|
-
|
22
|
-
def running?
|
23
|
-
@status == RUNNING
|
24
|
-
end
|
25
|
-
|
26
|
-
def ready?
|
27
|
-
pod_containers = @ready.split('/').last
|
28
|
-
@ready == "#{pod_containers}/#{pod_containers}"
|
29
|
-
end
|
30
|
-
|
31
|
-
def exec(command)
|
32
|
-
@client.kubectl_command("exec -i #{name} -- sh -c \"#{command.gsub('"', '\"')}\"")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/kubecontrol/service.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Kubecontrol
|
2
|
-
class Service
|
3
|
-
RESOURCE_NAME = 'services'.freeze
|
4
|
-
|
5
|
-
attr_reader :name, :age, :type, :cluster_ip, :external_ip, :ports, :namespace, :client
|
6
|
-
|
7
|
-
def initialize(name, type, cluster_ip, external_ip, ports, age, namespace, client)
|
8
|
-
@name = name
|
9
|
-
@age = age
|
10
|
-
@type = type
|
11
|
-
@cluster_ip = cluster_ip
|
12
|
-
@external_ip = external_ip
|
13
|
-
@ports = ports
|
14
|
-
@namespace = namespace
|
15
|
-
@client = client
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,28 +0,0 @@
|
|
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
|