minfra-cli 1.12.0 → 1.13.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b4880a484c8d4d18875f3b3c355162c0f49eb1fcae69f8a870ee4c5ad8d04d0
4
- data.tar.gz: 1d34cb69b8b8e5a5476dcec8d14463d02a00a2fbdc47ccb12f761a93413a3df9
3
+ metadata.gz: 013e2aad3df9fffb13eaceeac4ccc3306ac4dfedb9ef7f0019251ee4238e9dbf
4
+ data.tar.gz: 266a3cbfbcbc27eda6411806a20c1f3d5547d4b02fda404531861eb538f1be2b
5
5
  SHA512:
6
- metadata.gz: 851fbc24107b2efd086f2e69adaaf2580f1ceed98eee55a71067348d4283360be440b14bf94b586f56a3a5180d0432a76553602cad02b6aef3e2715441bef236
7
- data.tar.gz: cffdcda6203c63f9efcc12b7f57dea382caf82f2a2cd8cca605c14b36ef8fe77a82695c72a8cddac31113c311f24fc753de8df7506a03894474d83d360b282ee
6
+ metadata.gz: ab2a2990bec284c339aaee8b49998cbf93c5cc53179a70ac6ddc6c6d557eb30b3b5b594877d744875bbeb200b90533630e61d60a84b016dab044e128b74aa6b0
7
+ data.tar.gz: b2e7767759e9c2eb7391974a46d1c1bec649f5247f580a7f7aef3b3bbc98e451d1ef882bdae0fc52fbfa12ad2d572a3d8daefb0a7a05f774909bf1aab1e2f129
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 1.13.0
2
+ * secrets can be rendered with apply (currently hardcoded)
3
+ * moved most output to debug level
4
+ # 1.12.1
5
+ * replaced all relevant system calls with new runners (fixed apply and
6
+ generic_secrets)
1
7
  # 1.12.0
2
8
  * refactoring Runner
3
9
  * adding runner type system (popen is default)
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minfra-cli (1.7.0)
5
- activesupport (~> 6.1)
4
+ minfra-cli (1.12.0)
5
+ activesupport (= 7.0.7.2)
6
6
  erubis (~> 2.7)
7
7
  hashie (~> 3.5)
8
8
  hiera (= 3.9.0)
@@ -15,16 +15,14 @@ PATH
15
15
  GEM
16
16
  remote: https://rubygems.org/
17
17
  specs:
18
- activesupport (6.1.7.2)
18
+ activesupport (7.0.7.2)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 1.6, < 2)
21
21
  minitest (>= 5.1)
22
22
  tzinfo (~> 2.0)
23
- zeitwerk (~> 2.3)
24
- concurrent-ruby (1.2.0)
23
+ concurrent-ruby (1.2.2)
25
24
  diff-lcs (1.5.0)
26
- domain_name (0.5.20190701)
27
- unf (>= 0.0.5, < 1.0.0)
25
+ domain_name (0.6.20231109)
28
26
  erubis (2.7.0)
29
27
  hashie (3.6.0)
30
28
  hiera (3.9.0)
@@ -37,42 +35,38 @@ GEM
37
35
  http-accept (1.7.0)
38
36
  http-cookie (1.0.5)
39
37
  domain_name (~> 0.5)
40
- i18n (1.12.0)
38
+ i18n (1.14.1)
41
39
  concurrent-ruby (~> 1.0)
42
- mime-types (3.4.1)
40
+ mime-types (3.5.1)
43
41
  mime-types-data (~> 3.2015)
44
- mime-types-data (3.2022.0105)
45
- minitest (5.17.0)
42
+ mime-types-data (3.2023.1205)
43
+ minitest (5.20.0)
46
44
  netrc (0.11.0)
47
- optimist (3.0.1)
45
+ optimist (3.1.0)
48
46
  rake (12.3.3)
49
47
  rest-client (2.1.0)
50
48
  http-accept (>= 1.7.0, < 2.0)
51
49
  http-cookie (>= 1.0.2, < 2.0)
52
50
  mime-types (>= 1.16, < 4.0)
53
51
  netrc (~> 0.8)
54
- rspec (3.11.0)
55
- rspec-core (~> 3.11.0)
56
- rspec-expectations (~> 3.11.0)
57
- rspec-mocks (~> 3.11.0)
58
- rspec-core (3.11.0)
59
- rspec-support (~> 3.11.0)
60
- rspec-expectations (3.11.1)
52
+ rspec (3.12.0)
53
+ rspec-core (~> 3.12.0)
54
+ rspec-expectations (~> 3.12.0)
55
+ rspec-mocks (~> 3.12.0)
56
+ rspec-core (3.12.2)
57
+ rspec-support (~> 3.12.0)
58
+ rspec-expectations (3.12.3)
61
59
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.11.0)
63
- rspec-mocks (3.11.1)
60
+ rspec-support (~> 3.12.0)
61
+ rspec-mocks (3.12.6)
64
62
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.11.0)
66
- rspec-support (3.11.1)
63
+ rspec-support (~> 3.12.0)
64
+ rspec-support (3.12.1)
67
65
  table_print (1.5.6)
68
- thor (1.2.1)
69
- timecop (0.9.5)
66
+ thor (1.3.0)
67
+ timecop (0.9.8)
70
68
  tzinfo (2.0.6)
71
69
  concurrent-ruby (~> 1.0)
72
- unf (0.1.4)
73
- unf_ext
74
- unf_ext (0.0.8.2)
75
- zeitwerk (2.6.6)
76
70
 
77
71
  PLATFORMS
78
72
  ruby
data/README.md CHANGED
@@ -7,7 +7,7 @@ Is a KIND (k8s in docker) based development environment.
7
7
 
8
8
  ## Expected hiera data
9
9
 
10
- * l("cluster").id: the k8s name of the cluster
10
+ * l("cluster.id"): the k8s name of the cluster
11
11
 
12
12
 
13
13
 
@@ -1,5 +1,5 @@
1
1
  module Minfra
2
2
  module Cli
3
- VERSION = '1.12.0'.freeze
3
+ VERSION = '1.13.0'.freeze
4
4
  end
5
5
  end
@@ -378,12 +378,39 @@ module Orchparty
378
378
  self
379
379
  end
380
380
 
381
- def secrets(name, &block)
381
+ # secrets can be aprt of the helm chart or we write them to
382
+ # a file and later apply it
383
+ # apiVersion: v1
384
+ # kind: Secret
385
+ # metadata:
386
+ # name: dotfile-secret
387
+ # data:
388
+ # key: base64_encoded_value
389
+
390
+ def secrets(name, deploy: :helm, &block)
391
+ case deploy
392
+ when :helm
382
393
  result = ServiceBuilder.build(name, "chart-secret", block)
383
394
  @application.services[name] = result
384
395
  @application._service_order << name
385
396
  @node._services << name
386
397
  self
398
+ when :apply
399
+ result = ServiceBuilder.build(name, "apply", block)
400
+ file = Tempfile.create(name)
401
+ result.tmp_file=file.path
402
+ file.puts "apiVersion: v1\nkind: Secret\nmetadata:\n name: #{name}\ntype: Opaque\ndata:"
403
+ result._.each do |key, value|
404
+ file.puts " #{key}: #{Base64.strict_encode64(value.respond_to?(:call) ? value.call : value)}"
405
+ end
406
+ file.close
407
+ @application.services[name] = result
408
+ @application._service_order << name
409
+ when :none
410
+
411
+ else
412
+ raise "unknown secret type: #{type}, known tpyes: [helm, apply]"
413
+ end
387
414
  end
388
415
 
389
416
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
1
4
  require 'erb'
2
5
  require 'erubis'
3
6
  require 'open3'
@@ -10,34 +13,32 @@ require 'active_support/core_ext'
10
13
  module Orchparty
11
14
  module Services
12
15
  class Context
13
- include ::Minfra::Cli::Logging
16
+ include ::Minfra::Cli::Logging
14
17
 
15
- attr_accessor :cluster_name
16
- attr_accessor :namespace
17
- attr_accessor :dir_path
18
- attr_accessor :app_config
19
- attr_accessor :options
18
+ attr_accessor :cluster_name, :namespace, :dir_path, :app_config, :options, :service
20
19
 
21
- def initialize(cluster_name: , namespace:, file_path: , app_config:, out_io: STDOUT, app: )
20
+ def initialize(cluster_name:, namespace:, file_path:, app_config:, app:, service:, out_io: $stdout)
22
21
  self.cluster_name = cluster_name
23
22
  self.namespace = namespace
24
23
  self.dir_path = file_path
25
24
  self.app_config = app_config
26
25
  @app = app
27
26
  @out_io = out_io
28
- self.options=options
27
+ self.service = service # ugly naming, should be 'context'?
28
+ self.options = options
29
29
  end
30
30
 
31
- def template(file_path, helm, flag: "-f ", fix_file_path: nil)
32
- return "" unless file_path
33
- puts "Rendering: #{file_path}"
34
- file_path = File.join(self.dir_path, file_path)
35
- if(file_path.end_with?(".erb"))
31
+ def template(file_path, helm, flag: '-f ', fix_file_path: nil)
32
+ return '' unless file_path
33
+
34
+ debug "Rendering: #{file_path}"
35
+ file_path = File.join(dir_path, file_path) unless file_path.start_with?('/')
36
+ if file_path.end_with?('.erb')
36
37
  helm.application = OpenStruct.new(cluster_name: cluster_name, namespace: namespace)
37
38
  template = Erubis::Eruby.new(File.read(file_path))
38
39
  template.filename = file_path
39
40
  yaml = template.result(helm.get_binding)
40
- file = Tempfile.new("kube-deploy.yaml")
41
+ file = Tempfile.new('kube-deploy.yaml')
41
42
  file.write(yaml)
42
43
  file.close
43
44
  file_path = file.path
@@ -45,108 +46,125 @@ module Orchparty
45
46
  "#{flag}#{fix_file_path || file_path}"
46
47
  end
47
48
 
48
- def print_install(helm)
49
- @out_io.puts "---"
50
- @out_io.puts install_cmd(helm, value_path(helm)).cmd
51
- @out_io.puts upgrade_cmd(helm, value_path(helm)).cmd
52
- @out_io.puts "---"
53
- @out_io.puts File.read(template(value_path(helm), helm, flag: "")) if value_path(helm)
49
+ def print_install
50
+ @out_io.puts '---'
51
+ @out_io.puts install_cmd(value_path).cmd
52
+ @out_io.puts upgrade_cmd(value_path).cmd
53
+ @out_io.puts '---'
54
+ @out_io.puts File.read(template(value_path, service, flag: '')) if value_path
55
+ cleanup
54
56
  end
55
57
 
56
58
  # On 05.02.2021 we have decided that it would be best to print both commands.
57
59
  # This way it would be possible to debug both upgrade and install and also people would not see git diffs all the time.
58
- def print_upgrade(helm)
59
- print_install(helm)
60
+ def print_upgrade
61
+ print_install
60
62
  end
61
63
 
62
- def upgrade(helm)
63
- @out_io.puts upgrade_cmd(helm).run.stdout
64
+ def upgrade
65
+ @out_io.puts upgrade_cmd.run.stdout
66
+ cleanup if respond_to?(:cleanup)
64
67
  end
65
68
 
66
- def install(helm)
67
- @out_io.puts install_cmd(helm).run.stdout
69
+ def install
70
+ @out_io.puts install_cmd.run.stdout
71
+ cleanup if respond_to?(:cleanup)
68
72
  end
69
73
  end
70
74
 
71
75
  class Helm < Context
72
- def value_path(helm)
73
- helm[:values]
76
+ def value_path
77
+ service[:values]
74
78
  end
75
79
 
76
- def upgrade_cmd(helm, fix_file_path = nil)
77
- Minfra::Cli::HelmRunner.new("upgrade --namespace #{namespace} --kube-context #{cluster_name} --version #{helm.version} #{helm.name} #{helm.chart} #{template(value_path(helm), helm, fix_file_path: fix_file_path)}")
80
+ def upgrade_cmd(fix_file_path = nil)
81
+ Minfra::Cli::HelmRunner.new("upgrade --namespace #{namespace} --kube-context #{cluster_name} --version #{service.version} #{service.name} #{service.chart} #{template(
82
+ value_path, service, fix_file_path: fix_file_path
83
+ )}")
78
84
  end
79
85
 
80
- def install_cmd(helm, fix_file_path = nil)
81
- Minfra::Cli::HelmRunner.new("install --create-namespace --namespace #{namespace} --kube-context #{cluster_name} --version #{helm.version} #{helm.name} #{helm.chart} #{template(value_path(helm), helm, fix_file_path: fix_file_path)}")
86
+ def install_cmd(fix_file_path = nil)
87
+ Minfra::Cli::HelmRunner.new("install --create-namespace --namespace #{namespace} --kube-context #{cluster_name} --version #{service.version} #{service.name} #{service.chart} #{template(
88
+ value_path, service, fix_file_path: fix_file_path
89
+ )}")
82
90
  end
83
91
  end
84
92
 
85
93
  class Apply < Context
86
- def value_path(apply)
87
- apply[:name]
94
+ def value_path
95
+ service[:tmp_file] || service[:name]
88
96
  end
89
97
 
90
- def upgrade_cmd(apply, fix_file_path = nil)
91
- "kubectl apply --namespace #{namespace} --context #{cluster_name} #{template(value_path(apply), apply, fix_file_path: fix_file_path)}"
98
+ def upgrade_cmd(fix_file_path = nil)
99
+ Minfra::Cli::KubeCtlRunner.new("apply --namespace #{namespace} --context #{cluster_name} #{template(value_path,
100
+ service, fix_file_path: fix_file_path)}")
92
101
  end
93
102
 
94
- def install_cmd(apply, fix_file_path = nil)
95
- "kubectl apply --namespace #{namespace} --context #{cluster_name} #{template(value_path(apply), apply, fix_file_path: fix_file_path)}"
103
+ def install_cmd(fix_file_path = nil)
104
+ Minfra::Cli::KubeCtlRunner.new("apply --namespace #{namespace} --context #{cluster_name} #{template(value_path,
105
+ service, fix_file_path: fix_file_path)}")
106
+ end
107
+
108
+ def cleanup
109
+ File.unlink(service[:tmp_file]) if service[:tmp_file]
96
110
  end
97
111
  end
98
112
 
99
113
  class SecretGeneric < Context
100
- def value_path(secret)
101
- secret[:from_file]
114
+ def value_path
115
+ service[:from_file]
102
116
  end
103
117
 
104
- def upgrade_cmd(secret, fix_file_path=nil)
105
- "kubectl --namespace #{namespace} --context #{cluster_name} create secret generic --dry-run -o yaml #{secret[:name]} #{template(value_path(secret), secret, flag: "--from-file=", fix_file_path: fix_file_path)} | kubectl --context #{cluster_name} apply -f -"
118
+ def upgrade_cmd(fix_file_path = nil)
119
+ "kubectl --namespace #{namespace} --context #{cluster_name} create secret generic --dry-run -o yaml #{service[:name]} #{template(
120
+ value_path, service, flag: '--from-file=', fix_file_path: fix_file_path
121
+ )} | kubectl --context #{cluster_name} apply -f -"
106
122
  end
107
123
 
108
- def install_cmd(secret, fix_file_path=nil)
109
- "kubectl --namespace #{namespace} --context #{cluster_name} create secret generic --dry-run -o yaml #{secret[:name]} #{template(value_path(secret), secret, flag: "--from-file=", fix_file_path: fix_file_path)} | kubectl --context #{cluster_name} apply -f -"
124
+ def install_cmd(fix_file_path = nil)
125
+ "kubectl --namespace #{namespace} --context #{cluster_name} create secret generic --dry-run -o yaml #{service[:name]} #{template(
126
+ value_path, service, flag: '--from-file=', fix_file_path: fix_file_path
127
+ )} | kubectl --context #{cluster_name} apply -f -"
110
128
  end
111
129
  end
112
130
 
113
131
  class Label < Context
114
- def print_install(label)
115
- @out_io.puts "---"
116
- @out_io.puts install_cmd(label)
132
+ def print_install
133
+ @out_io.puts '---'
134
+ @out_io.puts install_cmd
117
135
  end
118
136
 
119
- def print_upgrade(label)
120
- @out_io.puts "---"
121
- @out_io.puts upgrade_cmd(label)
137
+ def print_upgrade
138
+ @out_io.puts '---'
139
+ @out_io.puts upgrade_cmd
122
140
  end
123
141
 
124
- def upgrade_cmd(label)
125
- "kubectl --namespace #{namespace} --context #{cluster_name} label --overwrite #{label[:resource]} #{label[:name]} #{label["value"]}"
142
+ def upgrade_cmd
143
+ "kubectl --namespace #{namespace} --context #{cluster_name} label --overwrite #{service[:resource]} #{service[:name]} #{service['value']}"
126
144
  end
127
145
 
128
- def install_cmd(label)
129
- "kubectl --namespace #{namespace} --context #{cluster_name} label --overwrite #{label[:resource]} #{label[:name]} #{label["value"]}"
146
+ def install_cmd
147
+ "kubectl --namespace #{namespace} --context #{cluster_name} label --overwrite #{service[:resource]} #{service[:name]} #{service['value']}"
130
148
  end
131
149
  end
132
150
 
133
151
  class Wait < Context
134
- def print_install(wait)
135
- @out_io.puts "---"
136
- @out_io.puts wait.cmd
152
+ def print_install
153
+ @out_io.puts '---'
154
+ @out_io.puts service.cmd
137
155
  end
138
156
 
139
- def print_upgrade(wait)
140
- @out_io.puts "---"
141
- @out_io.puts wait.cmd
157
+ def print_upgrade
158
+ @out_io.puts '---'
159
+ @out_io.puts service.cmd
142
160
  end
143
161
 
144
- def upgrade(wait)
145
- eval(wait.cmd)
162
+ def upgrade
163
+ eval(service.cmd)
146
164
  end
147
165
 
148
- def install(wait)
149
- eval(wait.cmd)
166
+ def install
167
+ eval(service.cmd)
150
168
  end
151
169
  end
152
170
 
@@ -159,75 +177,70 @@ module Orchparty
159
177
  end
160
178
  end
161
179
 
180
+ def print_install
181
+ build_chart do |chart_path|
182
+ cmd = "helm template --namespace #{namespace} --debug --kube-context #{cluster_name} --output-dir #{chart_path.join(
183
+ '..', 'helm_expanded'
184
+ )} #{service.name} #{chart_path}"
185
+ @out_io.puts `$cmd`
186
+ if system("#{cmd} > /dev/null")
162
187
 
163
- def print_install(chart)
164
-
165
- build_chart(chart) do |chart_path|
166
- cmd="helm template --namespace #{namespace} --debug --kube-context #{cluster_name} --output-dir #{chart_path.join('..','helm_expanded')} #{chart.name} #{chart_path}"
167
- @out_io.puts `$cmd`
168
- if system("#{cmd} > /dev/null")
169
-
170
- info("helm template check: OK")
188
+ debug('Helm: template check: OK')
171
189
  else
172
- error("helm template check: FAIL")
173
- end
190
+ error('Helm: template check: FAIL')
191
+ end
174
192
  end
175
-
176
193
  end
177
194
 
178
- def print_upgrade(chart)
179
- print_install(chart)
195
+ def print_upgrade
196
+ print_install
180
197
  end
181
198
 
182
- def install(chart)
183
- info("Install: #{chart.name}")
184
- build_chart(chart) do |chart_path|
185
- res=Minfra::Cli::HelmRunner.new("install --create-namespace --namespace #{namespace} --kube-context #{cluster_name} #{chart.name} #{chart_path}").run
199
+ def install
200
+ debug("Install: #{service.name}")
201
+ build_chart do |chart_path|
202
+ res = Minfra::Cli::HelmRunner.new("install --create-namespace --namespace #{namespace} --kube-context #{cluster_name} #{service.name} #{chart_path}").run
186
203
  @out_io.puts res.stdout
187
204
  end
188
205
  end
189
206
 
190
- def upgrade(chart)
191
- info("Upgrade: #{chart}")
192
- build_chart(chart) do |chart_path|
193
- res=Minfra::Cli::HelmRunner.new("upgrade --namespace #{namespace} --kube-context #{cluster_name} #{chart.name} #{chart_path}").run
207
+ def upgrade
208
+ debug("Upgrade: #{service.name}: #{service._services.join(', ')}")
209
+ build_chart do |chart_path|
210
+ res = Minfra::Cli::HelmRunner.new("upgrade --namespace #{namespace} --kube-context #{cluster_name} #{service.name} #{chart_path}").run
194
211
  @out_io.puts res.stdout
195
212
  end
196
213
  end
214
+
197
215
  private
198
-
199
- def build_chart(chart)
216
+
217
+ def build_chart
200
218
  dir = @app.status_dir.join('helm') # duplication
201
-
202
- params = chart._services.map {|s| app_config.services[s.to_sym] }.map{|s| [s.name, s]}.to_h
203
- run(templates_path: File.expand_path(chart.template, self.dir_path), params: params, output_chart_path: dir, chart: chart)
219
+ params = service._services.map { |s| app_config.services[s.to_sym] }.map { |s| [s.name, s] }.to_h
220
+ run(templates_path: File.expand_path(service.template, dir_path), params: params, output_chart_path: dir,
221
+ chart: service)
204
222
  yield dir
205
223
  end
206
224
 
207
-
208
-
209
225
  # remember:
210
226
  # this is done for an app
211
227
  # that app can have multiple charts with multiple services!
212
-
213
- def run(templates_path:, params:, output_chart_path:, chart: )
214
228
 
215
-
216
- File.open(File.join(output_chart_path, 'values.yaml'),'a') do |helm_values|
229
+ def run(templates_path:, params:, output_chart_path:, chart:)
230
+ File.open(File.join(output_chart_path, 'values.yaml'), 'a') do |helm_values|
217
231
  params.each do |app_name, subparams|
218
232
  subparams[:chart] = chart
219
- used_vars=generate_documents_from_erbs(
233
+ used_vars = generate_documents_from_erbs(
220
234
  templates_path: templates_path,
221
235
  app_name: app_name,
222
236
  params: subparams,
223
237
  output_chart_path: output_chart_path
224
238
  )
225
- used_vars.each do |variable,value|
239
+ used_vars.each do |variable, value|
226
240
  helm_values.puts "#{variable}: \"#{value}\""
227
241
  end
228
242
  end
229
243
  end
230
-
231
244
  end
232
245
 
233
246
  def generate_documents_from_erbs(templates_path:, app_name:, params:, output_chart_path:)
@@ -237,13 +250,13 @@ module Orchparty
237
250
  end
238
251
 
239
252
  kind = params.fetch(:kind)
240
- params._used_vars = {} #here we'll collect all used vars
253
+ params._used_vars = {} # here we'll collect all used vars
241
254
 
242
255
  Dir[File.join(templates_path, kind, '*.erb')].each do |template_path|
243
- info("Rendering Template: #{template_path}")
256
+ debug("Rendering Template: #{template_path}")
244
257
  template_name = File.basename(template_path, '.erb')
245
258
  output_path = File.join(output_chart_path, 'templates', "#{app_name}-#{template_name}")
246
-
259
+
247
260
  template = Erubis::Eruby.new(File.read(template_path))
248
261
  template.filename = template_path
249
262
 
@@ -253,14 +266,13 @@ module Orchparty
253
266
  begin
254
267
  document = template.result(CleanBinding.new.get_binding(params))
255
268
  rescue Exception
256
- error "#{template_path} has a problem: #{$!.inspect}"
269
+ error "#{template_path} has a problem: #{$ERROR_INFO.inspect}"
257
270
  raise
258
271
  end
259
272
  File.write(output_path, document)
260
273
  end
261
274
  params._used_vars
262
275
  end
263
-
264
276
  end
265
277
  end
266
278
  end
@@ -268,19 +280,16 @@ end
268
280
  class KubernetesApplication
269
281
  include Minfra::Cli::Logging
270
282
 
271
- attr_accessor :cluster_name
272
- attr_accessor :file_path
273
- attr_accessor :namespace
274
- attr_accessor :app_config
283
+ attr_accessor :cluster_name, :file_path, :namespace, :app_config
275
284
  attr_reader :status_dir
276
285
 
277
- def initialize(app_config: [], namespace:, cluster_name:, file_name:, status_dir:, out_io: STDOUT)
278
- self.file_path = Pathname.new(file_name).parent.expand_path #path of the stack
286
+ def initialize(namespace:, cluster_name:, file_name:, status_dir:, app_config: [], out_io: $stdout)
287
+ self.file_path = Pathname.new(file_name).parent.expand_path # path of the stack
279
288
  self.cluster_name = cluster_name
280
289
  self.namespace = namespace
281
290
  self.app_config = app_config
282
291
  @status_dir = status_dir
283
- @out_io= out_io
292
+ @out_io = out_io
284
293
  end
285
294
 
286
295
  def install
@@ -296,45 +305,47 @@ class KubernetesApplication
296
305
  end
297
306
 
298
307
  private
308
+
299
309
  def prepare
300
-
301
310
  output_chart_path = @status_dir.join('helm')
302
311
  output_chart_path.rmtree if output_chart_path.exist?
303
312
  output_chart_path.mkpath
304
- templates_path = file_path.join('../../chart-templates').expand_path #don't ask. the whole concept of multiple charts in an app stinks...
305
-
313
+ templates_path = file_path.join('../../chart-templates').expand_path # don't ask. the whole concept of multiple charts in an app stinks...
314
+
306
315
  generate_chart_yaml(
307
- templates_path: templates_path,
308
- output_chart_path: output_chart_path,
309
- chart_name: namespace,
316
+ templates_path: templates_path,
317
+ output_chart_path: output_chart_path,
318
+ chart_name: namespace
310
319
  )
311
320
 
312
- info("generating base helm structure from: #{output_chart_path} from #{templates_path}")
321
+ debug("Minfra: generating base helm structure from: #{output_chart_path} from #{templates_path}")
313
322
  system("mkdir -p #{File.join(output_chart_path, 'templates')}")
314
323
 
315
324
  system("cp #{File.join(templates_path, 'values.yaml')} #{File.join(output_chart_path, 'values.yaml')}")
316
325
  system("cp #{File.join(templates_path, '.helmignore')} #{File.join(output_chart_path, '.helmignore')}")
317
- system("cp #{File.join(templates_path, 'templates/_helpers.tpl')} #{File.join(output_chart_path, 'templates/_helpers.tpl')}")
318
-
326
+ system("cp #{File.join(templates_path,
327
+ 'templates/_helpers.tpl')} #{File.join(output_chart_path, 'templates/_helpers.tpl')}")
319
328
  end
320
329
 
321
- def generate_chart_yaml(templates_path:, output_chart_path:, chart_name: )
330
+ def generate_chart_yaml(templates_path:, output_chart_path:, chart_name:)
322
331
  template_path = File.join(templates_path, 'Chart.yaml.erb')
323
332
  output_path = File.join(output_chart_path, 'Chart.yaml')
324
333
 
325
- res=Minfra::Cli::Templater.read(template_path, params: {chart_name: chart_name})
334
+ res = Minfra::Cli::Templater.read(template_path, params: { chart_name: chart_name })
326
335
  File.write(output_path, res)
327
336
  end
328
-
337
+
329
338
  def combine_charts(app_config)
330
339
  services = app_config._service_order.map(&:to_s)
331
340
  app_config._service_order.each do |name|
332
341
  current_service = app_config[:services][name]
333
- if current_service._type == "chart"
334
- current_service._services.each do |n|
335
- services.delete n.to_s
336
- end
342
+ next unless current_service._type == 'chart'
343
+
344
+ current_service._services.each do |n|
345
+ services.delete n.to_s
337
346
  end
347
+ # else
348
+ # puts "unkown service: #{name}: #{current_service._type}"
338
349
  end
339
350
  services
340
351
  end
@@ -342,18 +353,19 @@ class KubernetesApplication
342
353
  def each_service(method)
343
354
  prepare
344
355
  services = combine_charts(app_config)
356
+
345
357
  services.each do |name|
346
358
  service = app_config[:services][name]
347
- info "Service: #{name}(#{service._type}) #{method}"
348
- deployable_class="::Orchparty::Services::#{service._type.classify}".constantize
349
- deployable=deployable_class.new(cluster_name: cluster_name,
350
- namespace: namespace,
351
- file_path: file_path,
352
- app_config: app_config,
353
- out_io: @out_io,
354
- app: self)
355
-
356
- deployable.send(method, service)
359
+ debug("Generating Service: #{name}(#{service._type}) #{method}")
360
+ deployable_class = "::Orchparty::Services::#{service._type.classify}".constantize
361
+ deployable = deployable_class.new(cluster_name: cluster_name,
362
+ namespace: namespace,
363
+ file_path: file_path,
364
+ app_config: app_config,
365
+ out_io: @out_io,
366
+ app: self,
367
+ service: service)
368
+ deployable.send(method)
357
369
  end
358
370
  end
359
371
  end
data/minfra-cli.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_runtime_dependency "table_print", "1.5.6"
32
32
  spec.add_runtime_dependency "rest-client", "~>2.0"
33
33
  spec.add_runtime_dependency "hashie", "~>3.5"
34
- spec.add_runtime_dependency "activesupport", ">= 6.1"
34
+ spec.add_runtime_dependency "activesupport", "= 7.0.7.2"
35
35
  spec.add_runtime_dependency "erubis", "~> 2.7"
36
36
  spec.add_runtime_dependency "hiera", "3.9.0"
37
37
  spec.add_runtime_dependency "hiera-eyaml", "3.3.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minfra-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schrammel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-01 00:00:00.000000000 Z
11
+ date: 2023-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -76,16 +76,16 @@ dependencies:
76
76
  name: activesupport
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">="
79
+ - - '='
80
80
  - !ruby/object:Gem::Version
81
- version: '6.1'
81
+ version: 7.0.7.2
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ">="
86
+ - - '='
87
87
  - !ruby/object:Gem::Version
88
- version: '6.1'
88
+ version: 7.0.7.2
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: erubis
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  - !ruby/object:Gem::Version
240
240
  version: '0'
241
241
  requirements: []
242
- rubygems_version: 3.4.10
242
+ rubygems_version: 3.3.7
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: A cli framework for k8s based development and deployment.