kerbi 0.0.1 → 0.0.2
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/lib/cli/base_handler.rb +180 -0
- data/lib/cli/base_serializer.rb +120 -0
- data/lib/cli/config_handler.rb +51 -0
- data/lib/cli/entry_serializers.rb +99 -0
- data/lib/cli/project_handler.rb +2 -2
- data/lib/cli/root_handler.rb +32 -13
- data/lib/cli/state_handler.rb +95 -0
- data/lib/cli/values_handler.rb +4 -3
- data/lib/config/cli_schema.rb +299 -27
- data/lib/config/config_file.rb +60 -0
- data/lib/config/globals.rb +4 -0
- data/lib/config/run_opts.rb +150 -0
- data/lib/config/state_consts.rb +10 -0
- data/lib/kerbi.rb +31 -9
- data/lib/main/errors.rb +109 -0
- data/lib/main/mixer.rb +12 -8
- data/lib/mixins/cli_state_helpers.rb +136 -0
- data/lib/mixins/cm_backend_testing.rb +95 -0
- data/lib/mixins/entry_tag_logic.rb +183 -0
- data/lib/state/base_backend.rb +59 -0
- data/lib/state/config_map_backend.rb +119 -0
- data/lib/state/entry.rb +173 -0
- data/lib/state/entry_set.rb +137 -0
- data/lib/state/metadata.yaml.erb +11 -0
- data/lib/state/mixers.rb +23 -0
- data/lib/state/resources.yaml.erb +17 -0
- data/lib/utils/cli.rb +77 -10
- data/lib/utils/helm.rb +10 -12
- data/lib/utils/k8s_auth.rb +87 -0
- data/lib/utils/misc.rb +36 -1
- data/lib/utils/mixing.rb +1 -1
- data/lib/utils/values.rb +13 -22
- data/spec/cli/config_handler_spec.rb +38 -0
- data/spec/cli/root_handler_spec.rb +99 -0
- data/spec/cli/state_handler_spec.rb +139 -0
- data/spec/cli/values_handler_spec.rb +17 -0
- data/spec/expectations/common/bad-tag.txt +1 -0
- data/spec/expectations/config/bad-set.txt +1 -0
- data/spec/expectations/config/set.txt +1 -0
- data/spec/expectations/config/show-default.yaml +6 -0
- data/spec/expectations/root/template-inlines.yaml +31 -0
- data/spec/expectations/root/template-production.yaml +31 -0
- data/spec/expectations/root/template-read-inlines.yaml +31 -0
- data/spec/expectations/root/template-read.yaml +31 -0
- data/spec/expectations/root/template-write.yaml +31 -0
- data/spec/expectations/root/template.yaml +31 -0
- data/spec/expectations/root/values.json +28 -0
- data/spec/expectations/state/delete.txt +1 -0
- data/spec/expectations/state/demote.txt +1 -0
- data/spec/expectations/state/init-already-existed.txt +2 -0
- data/spec/expectations/state/init-both-created.txt +2 -0
- data/spec/expectations/state/list.json +51 -0
- data/spec/expectations/state/list.txt +6 -0
- data/spec/expectations/state/list.yaml +35 -0
- data/spec/expectations/state/promote.txt +1 -0
- data/spec/expectations/state/prune-candidates.txt +1 -0
- data/spec/expectations/state/retag.txt +1 -0
- data/spec/expectations/state/set.txt +1 -0
- data/spec/expectations/state/show.json +13 -0
- data/spec/expectations/state/show.txt +13 -0
- data/spec/expectations/state/show.yaml +8 -0
- data/spec/expectations/state/status-all-working.txt +4 -0
- data/spec/expectations/state/status-not-provisioned.txt +4 -0
- data/spec/expectations/values/order-of-precedence.yaml +4 -0
- data/spec/main/configmap_backend_spec.rb +109 -0
- data/spec/main/state_entry_set_spec.rb +112 -0
- data/spec/main/state_entry_spec.rb +109 -0
- data/spec/spec_helper.rb +87 -1
- data/spec/utils/helm_spec.rb +1 -21
- data/spec/utils/k8s_auth_spec.rb +32 -0
- data/spec/utils/misc_utils_spec.rb +9 -0
- data/spec/utils/values_utils_spec.rb +12 -19
- metadata +114 -13
- data/lib/cli/base.rb +0 -83
- data/lib/config/cli_opts.rb +0 -50
- data/lib/config/manager.rb +0 -36
- data/lib/main/state_manager.rb +0 -47
- data/lib/utils/kubectl.rb +0 -58
- data/spec/main/examples_spec.rb +0 -12
- data/spec/main/state_manager_spec.rb +0 -84
- data/spec/utils/state_utils.rb +0 -15
data/spec/utils/helm_spec.rb
CHANGED
@@ -10,14 +10,6 @@ RSpec.describe Kerbi::Utils::Helm do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
let :config do
|
14
|
-
Kerbi::Config::Manager
|
15
|
-
end
|
16
|
-
|
17
|
-
before(:each) do
|
18
|
-
# config.helm_exec = 'helm'
|
19
|
-
end
|
20
|
-
|
21
13
|
describe '.template' do
|
22
14
|
let(:repo_org) { "jetstack" }
|
23
15
|
let(:repo_url) { "https://charts.jetstack.io" }
|
@@ -43,11 +35,6 @@ RSpec.describe Kerbi::Utils::Helm do
|
|
43
35
|
expect(res_dicts.count).to be_within(40).of(40)
|
44
36
|
end
|
45
37
|
end
|
46
|
-
|
47
|
-
it 'cleans up' do
|
48
|
-
subject.template('kerbi', chart)
|
49
|
-
expect(File.exists?(config.tmp_helm_values_path)).to be_falsey
|
50
|
-
end
|
51
38
|
end
|
52
39
|
|
53
40
|
describe '.encode_inline_assigns' do
|
@@ -99,16 +86,9 @@ RSpec.describe Kerbi::Utils::Helm do
|
|
99
86
|
describe '#can_exec?' do
|
100
87
|
context 'exec working' do
|
101
88
|
it 'returns true' do
|
102
|
-
config.helm_exec = 'helm'
|
89
|
+
# config.helm_exec = 'helm'
|
103
90
|
expect(subject.can_exec?).to eq(true)
|
104
91
|
end
|
105
92
|
end
|
106
|
-
|
107
|
-
context '.exec not working' do
|
108
|
-
it 'returns false' do
|
109
|
-
config.helm_exec = 'not-helm'
|
110
|
-
expect(subject.can_exec?).to eq(false)
|
111
|
-
end
|
112
|
-
end
|
113
93
|
end
|
114
94
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative './../spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Kerbi::Utils::K8sAuth do
|
4
|
+
|
5
|
+
def make_client(bundle)
|
6
|
+
Kubeclient::Client.new(
|
7
|
+
bundle[:endpoint],
|
8
|
+
"v1",
|
9
|
+
**bundle[:options]
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".kube_config_client" do
|
14
|
+
context "with valid kube-config options" do
|
15
|
+
context "using the system default" do
|
16
|
+
it "returns a working client" do
|
17
|
+
bundle = subject.kube_config_bundle(path: nil, name: nil)
|
18
|
+
namespaces = make_client(bundle).get_namespaces
|
19
|
+
expect(namespaces.any?).to be_truthy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with an invalid kube-config options" do
|
25
|
+
it "returns a working client" do
|
26
|
+
expect {
|
27
|
+
subject.kube_config_bundle(path: "bad-path")
|
28
|
+
}. to raise_exception(Exception)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -6,9 +6,9 @@ RSpec.describe Kerbi::Utils::Values do
|
|
6
6
|
let(:root) { Kerbi::Testing::TEST_YAMLS_DIR }
|
7
7
|
before(:each) { Kerbi::Testing.reset_test_yamls_dir }
|
8
8
|
|
9
|
-
describe ".resolve_fname_expr" do
|
10
|
-
def func(
|
11
|
-
subject.
|
9
|
+
describe ".resolve_fname_expr (old)" do
|
10
|
+
def func(fname)
|
11
|
+
subject.resolve_fname_exprs([fname], root: root)
|
12
12
|
end
|
13
13
|
|
14
14
|
context "when the expression can be resolved" do
|
@@ -19,9 +19,9 @@ RSpec.describe Kerbi::Utils::Values do
|
|
19
19
|
Kerbi::Testing.make_yaml("x.yaml.erb", "n/a")
|
20
20
|
end
|
21
21
|
it "returns that file instead over similar ones" do
|
22
|
-
expect(func("x")).to eq("#{root}/x")
|
23
|
-
expect(func("x.yaml")).to eq("#{root}/x.yaml")
|
24
|
-
expect(func("x.yaml.erb")).to eq("#{root}/x.yaml.erb")
|
22
|
+
expect(func("x")).to eq(["#{root}/x"])
|
23
|
+
expect(func("x.yaml")).to eq(["#{root}/x.yaml"])
|
24
|
+
expect(func("x.yaml.erb")).to eq(["#{root}/x.yaml.erb"])
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -32,16 +32,18 @@ RSpec.describe Kerbi::Utils::Values do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns the closes match" do
|
35
|
-
expect(func("y")).to eq("#{root}/y.yaml")
|
35
|
+
expect(func("y")).to eq(["#{root}/y.yaml"])
|
36
36
|
Kerbi::Testing.del_testfile("y.yaml")
|
37
|
-
expect(func("y")).to eq("#{root}/y.yaml.erb")
|
37
|
+
expect(func("y")).to eq(["#{root}/y.yaml.erb"])
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context "when the expression cannot be resolved" do
|
43
|
-
it "
|
44
|
-
|
43
|
+
it "raises a Kerbi::ValuesFileNotFoundError with the right message" do
|
44
|
+
cls = Kerbi::ValuesFileNotFoundError
|
45
|
+
msg = "Could not resolve values file 'dne' in /tmp/kerbi-yamls"
|
46
|
+
expect { func("dne") }.to raise_error(cls, msg)
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -57,15 +59,6 @@ RSpec.describe Kerbi::Utils::Values do
|
|
57
59
|
Kerbi::Testing.make_yaml("y.yaml", "n/a")
|
58
60
|
end
|
59
61
|
|
60
|
-
context "with no missing files and values present" do
|
61
|
-
let(:expected) { %W[#{root}/values.yaml #{root}/x.yaml ] }
|
62
|
-
|
63
|
-
it "returns the expect list of final paths" do
|
64
|
-
Kerbi::Testing.make_yaml("values.yaml", "n/a")
|
65
|
-
expect(func(["x.yaml"])).to eq(expected)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
62
|
context "with no missing file other than 'values'" do
|
70
63
|
it "returns the expect list of final paths" do
|
71
64
|
expect(func(["x.yaml"])).to eq(["#{root}/x.yaml"])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kerbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Millot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -90,6 +90,26 @@ dependencies:
|
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 0.8.1
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: kubeclient
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '4.9'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 4.9.1
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '4.9'
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 4.9.1
|
93
113
|
description: Kerbi is a multi-strategy Kubernetes manifest templating engine.
|
94
114
|
email: xavier@nmachine.io
|
95
115
|
executables:
|
@@ -101,36 +121,84 @@ files:
|
|
101
121
|
- boilerplate/Gemfile.erb
|
102
122
|
- boilerplate/kerbifile.rb.erb
|
103
123
|
- boilerplate/values.yaml.erb
|
104
|
-
- lib/cli/
|
124
|
+
- lib/cli/base_handler.rb
|
125
|
+
- lib/cli/base_serializer.rb
|
126
|
+
- lib/cli/config_handler.rb
|
127
|
+
- lib/cli/entry_serializers.rb
|
105
128
|
- lib/cli/project_handler.rb
|
106
129
|
- lib/cli/root_handler.rb
|
130
|
+
- lib/cli/state_handler.rb
|
107
131
|
- lib/cli/values_handler.rb
|
108
|
-
- lib/config/cli_opts.rb
|
109
132
|
- lib/config/cli_schema.rb
|
133
|
+
- lib/config/config_file.rb
|
110
134
|
- lib/config/globals.rb
|
111
|
-
- lib/config/
|
135
|
+
- lib/config/run_opts.rb
|
136
|
+
- lib/config/state_consts.rb
|
112
137
|
- lib/kerbi.rb
|
113
138
|
- lib/main/code_gen.rb
|
139
|
+
- lib/main/errors.rb
|
114
140
|
- lib/main/mixer.rb
|
115
|
-
- lib/
|
141
|
+
- lib/mixins/cli_state_helpers.rb
|
142
|
+
- lib/mixins/cm_backend_testing.rb
|
143
|
+
- lib/mixins/entry_tag_logic.rb
|
116
144
|
- lib/mixins/mixer.rb
|
145
|
+
- lib/state/base_backend.rb
|
146
|
+
- lib/state/config_map_backend.rb
|
147
|
+
- lib/state/entry.rb
|
148
|
+
- lib/state/entry_set.rb
|
149
|
+
- lib/state/metadata.yaml.erb
|
150
|
+
- lib/state/mixers.rb
|
151
|
+
- lib/state/resources.yaml.erb
|
117
152
|
- lib/utils/cli.rb
|
118
153
|
- lib/utils/helm.rb
|
119
|
-
- lib/utils/
|
154
|
+
- lib/utils/k8s_auth.rb
|
120
155
|
- lib/utils/misc.rb
|
121
156
|
- lib/utils/mixing.rb
|
122
157
|
- lib/utils/values.rb
|
158
|
+
- spec/cli/config_handler_spec.rb
|
159
|
+
- spec/cli/root_handler_spec.rb
|
160
|
+
- spec/cli/state_handler_spec.rb
|
161
|
+
- spec/cli/values_handler_spec.rb
|
162
|
+
- spec/expectations/common/bad-tag.txt
|
163
|
+
- spec/expectations/config/bad-set.txt
|
164
|
+
- spec/expectations/config/set.txt
|
165
|
+
- spec/expectations/config/show-default.yaml
|
166
|
+
- spec/expectations/root/template-inlines.yaml
|
167
|
+
- spec/expectations/root/template-production.yaml
|
168
|
+
- spec/expectations/root/template-read-inlines.yaml
|
169
|
+
- spec/expectations/root/template-read.yaml
|
170
|
+
- spec/expectations/root/template-write.yaml
|
171
|
+
- spec/expectations/root/template.yaml
|
172
|
+
- spec/expectations/root/values.json
|
173
|
+
- spec/expectations/state/delete.txt
|
174
|
+
- spec/expectations/state/demote.txt
|
175
|
+
- spec/expectations/state/init-already-existed.txt
|
176
|
+
- spec/expectations/state/init-both-created.txt
|
177
|
+
- spec/expectations/state/list.json
|
178
|
+
- spec/expectations/state/list.txt
|
179
|
+
- spec/expectations/state/list.yaml
|
180
|
+
- spec/expectations/state/promote.txt
|
181
|
+
- spec/expectations/state/prune-candidates.txt
|
182
|
+
- spec/expectations/state/retag.txt
|
183
|
+
- spec/expectations/state/set.txt
|
184
|
+
- spec/expectations/state/show.json
|
185
|
+
- spec/expectations/state/show.txt
|
186
|
+
- spec/expectations/state/show.yaml
|
187
|
+
- spec/expectations/state/status-all-working.txt
|
188
|
+
- spec/expectations/state/status-not-provisioned.txt
|
189
|
+
- spec/expectations/values/order-of-precedence.yaml
|
123
190
|
- spec/fixtures/embedding.yaml.erb
|
124
|
-
- spec/main/
|
191
|
+
- spec/main/configmap_backend_spec.rb
|
125
192
|
- spec/main/mixer_spec.rb
|
126
193
|
- spec/main/project_code_gen_spec.rb
|
127
|
-
- spec/main/
|
194
|
+
- spec/main/state_entry_set_spec.rb
|
195
|
+
- spec/main/state_entry_spec.rb
|
128
196
|
- spec/mixins/mixer_mixin_spec.rb
|
129
197
|
- spec/spec_helper.rb
|
130
198
|
- spec/utils/helm_spec.rb
|
199
|
+
- spec/utils/k8s_auth_spec.rb
|
131
200
|
- spec/utils/misc_utils_spec.rb
|
132
201
|
- spec/utils/mixing_utils_spec.rb
|
133
|
-
- spec/utils/state_utils.rb
|
134
202
|
- spec/utils/values_utils_spec.rb
|
135
203
|
homepage: https://nmachine-io.github.io/kerbi
|
136
204
|
licenses:
|
@@ -160,11 +228,44 @@ test_files:
|
|
160
228
|
- spec/mixins/mixer_mixin_spec.rb
|
161
229
|
- spec/main/mixer_spec.rb
|
162
230
|
- spec/main/project_code_gen_spec.rb
|
163
|
-
- spec/main/
|
164
|
-
- spec/main/
|
231
|
+
- spec/main/configmap_backend_spec.rb
|
232
|
+
- spec/main/state_entry_set_spec.rb
|
233
|
+
- spec/main/state_entry_spec.rb
|
234
|
+
- spec/expectations/common/bad-tag.txt
|
235
|
+
- spec/expectations/root/template-read-inlines.yaml
|
236
|
+
- spec/expectations/root/values.json
|
237
|
+
- spec/expectations/root/template-write.yaml
|
238
|
+
- spec/expectations/root/template-read.yaml
|
239
|
+
- spec/expectations/root/template-inlines.yaml
|
240
|
+
- spec/expectations/root/template.yaml
|
241
|
+
- spec/expectations/root/template-production.yaml
|
242
|
+
- spec/expectations/values/order-of-precedence.yaml
|
243
|
+
- spec/expectations/state/prune-candidates.txt
|
244
|
+
- spec/expectations/state/list.txt
|
245
|
+
- spec/expectations/state/status-all-working.txt
|
246
|
+
- spec/expectations/state/init-both-created.txt
|
247
|
+
- spec/expectations/state/list.json
|
248
|
+
- spec/expectations/state/status-not-provisioned.txt
|
249
|
+
- spec/expectations/state/show.yaml
|
250
|
+
- spec/expectations/state/demote.txt
|
251
|
+
- spec/expectations/state/delete.txt
|
252
|
+
- spec/expectations/state/set.txt
|
253
|
+
- spec/expectations/state/init-already-existed.txt
|
254
|
+
- spec/expectations/state/show.json
|
255
|
+
- spec/expectations/state/list.yaml
|
256
|
+
- spec/expectations/state/promote.txt
|
257
|
+
- spec/expectations/state/retag.txt
|
258
|
+
- spec/expectations/state/show.txt
|
259
|
+
- spec/expectations/config/bad-set.txt
|
260
|
+
- spec/expectations/config/set.txt
|
261
|
+
- spec/expectations/config/show-default.yaml
|
165
262
|
- spec/fixtures/embedding.yaml.erb
|
263
|
+
- spec/utils/k8s_auth_spec.rb
|
166
264
|
- spec/utils/helm_spec.rb
|
167
|
-
- spec/utils/state_utils.rb
|
168
265
|
- spec/utils/values_utils_spec.rb
|
169
266
|
- spec/utils/mixing_utils_spec.rb
|
170
267
|
- spec/utils/misc_utils_spec.rb
|
268
|
+
- spec/cli/values_handler_spec.rb
|
269
|
+
- spec/cli/root_handler_spec.rb
|
270
|
+
- spec/cli/config_handler_spec.rb
|
271
|
+
- spec/cli/state_handler_spec.rb
|
data/lib/cli/base.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
module Kerbi
|
2
|
-
module Cli
|
3
|
-
|
4
|
-
##
|
5
|
-
# Superclass for all Thor CLI handlers.
|
6
|
-
class BaseHandler < Thor
|
7
|
-
|
8
|
-
protected
|
9
|
-
|
10
|
-
##
|
11
|
-
# Convenience method for printing dicts as YAML or JSON,
|
12
|
-
# according to the CLI options.
|
13
|
-
# @param [Hash|Array<Hash>] dicts
|
14
|
-
def print_dicts(dicts)
|
15
|
-
if self.cli_opts.outputs_yaml?
|
16
|
-
printable_str = Kerbi::Utils::Cli.dicts_to_yaml(dicts)
|
17
|
-
elsif self.cli_opts.outputs_json?
|
18
|
-
printable_str = Kerbi::Utils::Cli.dicts_to_json(dicts)
|
19
|
-
else
|
20
|
-
raise "Unknown output format '#{cli_opts.output_format}'"
|
21
|
-
end
|
22
|
-
puts printable_str
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
# Returns single merged dict containing all values given or
|
27
|
-
# pointed to by the CLI args, plus the default values.yaml file.
|
28
|
-
# This includes values from files, inline expressions, and the
|
29
|
-
# state ConfigMap.
|
30
|
-
# @return [Hash] symbol-keyed dict of all loaded values
|
31
|
-
def compile_values
|
32
|
-
utils = Kerbi::Utils::Values
|
33
|
-
file_values = utils.from_files(cli_opts.fname_exprs)
|
34
|
-
inline_values = utils.from_inlines(cli_opts.inline_val_exprs)
|
35
|
-
file_values.deep_merge(inline_values)
|
36
|
-
end
|
37
|
-
|
38
|
-
##
|
39
|
-
# Returns a re-usable instance of the CLI-args
|
40
|
-
# wrapper Kerbi::CliOpts
|
41
|
-
# @return [Kerbi::CliOpts] re-usable instance
|
42
|
-
def cli_opts
|
43
|
-
@_options_obj ||= Kerbi::CliOpts.new(self.options)
|
44
|
-
end
|
45
|
-
|
46
|
-
##
|
47
|
-
# Convenience class method for declaring a Thor subcommand
|
48
|
-
# metadata bundle, in accordance with the schema in
|
49
|
-
# Kerbi::Consts::OptionSchemas.
|
50
|
-
# @param [Hash] _schema a dict from Kerbi::Consts::OptionSchemas
|
51
|
-
# @param [Class<Thor>] handler_cls the handler
|
52
|
-
def self.thor_sub_meta(_schema, handler_cls)
|
53
|
-
schema = _schema.deep_dup
|
54
|
-
desc(schema[:name], schema[:desc])
|
55
|
-
subcommand schema[:name], handler_cls
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# Convenience class method for declaring a Thor command
|
60
|
-
# metadata bundle, in accordance with the schema in
|
61
|
-
# Kerbi::Consts::OptionSchemas.
|
62
|
-
# @param [Hash] _schema a dict from Kerbi::Consts::OptionSchemas
|
63
|
-
def self.thor_meta(_schema)
|
64
|
-
schema = _schema.deep_dup
|
65
|
-
desc(schema[:name], schema[:desc])
|
66
|
-
(schema[:options] || []).each do |opt_schema|
|
67
|
-
opt_key = opt_schema.delete(:key).to_sym
|
68
|
-
self.option opt_key, opt_schema
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.exit_on_failure?
|
73
|
-
true
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def utils
|
79
|
-
Kerbi::Utils
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/lib/config/cli_opts.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module Kerbi
|
2
|
-
|
3
|
-
##
|
4
|
-
# Convenience accessor struct for getting values from
|
5
|
-
# the CLI args.
|
6
|
-
class CliOpts
|
7
|
-
|
8
|
-
attr_reader :options
|
9
|
-
|
10
|
-
def initialize(options={})
|
11
|
-
@options = options.deep_dup
|
12
|
-
end
|
13
|
-
|
14
|
-
def output_format
|
15
|
-
value = options[consts::OUTPUT_FMT]
|
16
|
-
value || "yaml"
|
17
|
-
end
|
18
|
-
|
19
|
-
def outputs_yaml?
|
20
|
-
self.output_format == 'yaml'
|
21
|
-
end
|
22
|
-
|
23
|
-
def outputs_json?
|
24
|
-
self.output_format == 'json'
|
25
|
-
end
|
26
|
-
|
27
|
-
def ruby_version
|
28
|
-
options[consts::RUBY_VER]
|
29
|
-
end
|
30
|
-
|
31
|
-
def fname_exprs
|
32
|
-
options[consts::VALUE_FNAMES] || []
|
33
|
-
end
|
34
|
-
|
35
|
-
def inline_val_exprs
|
36
|
-
options[consts::INLINE_ASSIGNMENT] || []
|
37
|
-
end
|
38
|
-
|
39
|
-
def use_state?
|
40
|
-
options[consts::USE_STATE_VALUES].present?
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def consts
|
46
|
-
Kerbi::Consts::OptionKeys
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
data/lib/config/manager.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module Kerbi
|
2
|
-
module Config
|
3
|
-
class Manager
|
4
|
-
attr_reader :bundle
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
# TODO load me from filesystem
|
8
|
-
@bundle = {
|
9
|
-
tmp_helm_values_path: '/tmp/kerbi-helm-vals.yaml',
|
10
|
-
helm_exec: "helm"
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.inst
|
15
|
-
# TODO create ~/.config/kerbi etc...
|
16
|
-
@_instance ||= self.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.tmp_helm_values_path
|
20
|
-
inst.bundle[:tmp_helm_values_path]
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.helm_exec
|
24
|
-
inst.bundle[:helm_exec]
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.tmp_helm_values_path=(val)
|
28
|
-
inst.bundle[:tmp_helm_values_path] = val
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.helm_exec=(val)
|
32
|
-
inst.bundle[:helm_exec] = val
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/main/state_manager.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
module Kerbi
|
2
|
-
class StateManager
|
3
|
-
def self.patch
|
4
|
-
self.create_configmap_if_missing
|
5
|
-
patch_values = self.compile_patch
|
6
|
-
config_map = utils::State.kubectl_get_cm("state", raise_on_err: false)
|
7
|
-
crt_values = utils::State.read_cm_data(config_map)
|
8
|
-
merged_vars = crt_values.deep_merge(patch_values)
|
9
|
-
new_body = { **config_map, data: { variables: JSON.dump(merged_vars) } }
|
10
|
-
yaml_body = YAML.dump(new_body.deep_stringify_keys)
|
11
|
-
Utils::Kubectl.apply_tmpfile(yaml_body, args_manager.get_kmd_arg_str)
|
12
|
-
end
|
13
|
-
|
14
|
-
def compile_patch
|
15
|
-
values = {}
|
16
|
-
|
17
|
-
args_manager.get_fnames.each do |fname|
|
18
|
-
new_values = YAML.load_file(fname).deep_symbolize_keys
|
19
|
-
values.deep_merge!(new_values)
|
20
|
-
end
|
21
|
-
|
22
|
-
args_manager.get_inlines.each do |assignment_str|
|
23
|
-
assignment = Utils::Utils.str_assign_to_h(assignment_str)
|
24
|
-
values.deep_merge!(assignment)
|
25
|
-
end
|
26
|
-
values
|
27
|
-
end
|
28
|
-
|
29
|
-
def get_crt_vars
|
30
|
-
create_configmap_if_missing
|
31
|
-
get_configmap_values(get_configmap)
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_configmap_if_missing
|
35
|
-
unless get_configmap(raise_on_er: false)
|
36
|
-
kmd = "create cm state #{args_manager.get_kmd_arg_str}"
|
37
|
-
Utils::Kubectl.kmd(kmd)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def utils
|
44
|
-
Kerbi::Utils
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/utils/kubectl.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module Kerbi
|
2
|
-
module Utils
|
3
|
-
module Kubectl
|
4
|
-
def self.kmd(cmd, options = {})
|
5
|
-
cmd = "kubectl #{cmd}"
|
6
|
-
self.eval_shell_cmd(cmd, options)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.jkmd(cmd, options={})
|
10
|
-
cmd = "kubectl #{cmd} -o json"
|
11
|
-
begin
|
12
|
-
output = self.eval_shell_cmd(cmd, options)
|
13
|
-
as_hash = JSON.parse(output).deep_symbolize_keys
|
14
|
-
if as_hash.has_key?(:items)
|
15
|
-
as_hash[:items]
|
16
|
-
else
|
17
|
-
as_hash
|
18
|
-
end
|
19
|
-
rescue
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.eval_shell_cmd(cmd, options={})
|
25
|
-
print_err = options[:print_err]
|
26
|
-
raise_on_err = options[:raise_on_err]
|
27
|
-
begin
|
28
|
-
output, status = Open3.capture2e(cmd)
|
29
|
-
if status.success?
|
30
|
-
output = output[0..output.length - 2] if output.end_with?("\n")
|
31
|
-
output
|
32
|
-
else
|
33
|
-
if print_err
|
34
|
-
puts "Command \"#{cmd}\" error status #{status} with message:"
|
35
|
-
puts output
|
36
|
-
puts "---"
|
37
|
-
end
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
rescue Exception => e
|
41
|
-
if print_err
|
42
|
-
puts "Command \"#{cmd}\" failed with message:"
|
43
|
-
puts e.message
|
44
|
-
puts "---"
|
45
|
-
end
|
46
|
-
nil
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.apply_tmpfile(yaml_str, append)
|
51
|
-
tmp_fname = "/tmp/man-#{SecureRandom.hex(32)}.yaml"
|
52
|
-
File.write(tmp_fname, yaml_str)
|
53
|
-
kmd("apply -f #{tmp_fname} #{append}", print_err: true)
|
54
|
-
File.delete(tmp_fname)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/spec/main/examples_spec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require_relative './../spec_helper'
|
2
|
-
require_relative './../../examples/hello-kerbi/kerbifile'
|
3
|
-
|
4
|
-
RSpec.describe "Examples Directory" do
|
5
|
-
describe "The mixer" do
|
6
|
-
describe "#run" do
|
7
|
-
it "runs" do
|
8
|
-
# puts Kerbi::Globals.mixers.first.new({ }).run
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|