minfra-cli 1.11.0 → 1.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/minfra/cli/commands/kube.rb +11 -13
- data/lib/minfra/cli/helm_runner.rb +11 -0
- data/lib/minfra/cli/kubectl_runner.rb +11 -0
- data/lib/minfra/cli/runner.rb +48 -15
- data/lib/minfra/cli/version.rb +1 -1
- data/lib/minfra/cli.rb +2 -0
- data/lib/orchparty/kubernetes_application.rb +102 -92
- data/minfra-cli.gemspec +2 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca90567af36553b84c7a69020e85970c56591d65f7546d1c22c1969cc9bd58f3
|
4
|
+
data.tar.gz: 451949094ac8fe4a3bc502b10ad1f8924f2cb5688da1297594061ab4c4e4780d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6007ef02b33c582bb9bd002cb4b22adda6dd4e5ec32cf7646beb9597ef03181b8944a463fe5db943c84d19c6ed50c8b324a5bb383cfa975b0f4301e1ffb214d5
|
7
|
+
data.tar.gz: 1908c4e6f95565dc3ebdf2bf371808021166997691c0fcb3514a89b2d47cf379d551b1f5f1934032cfe08afcc180f6f4d75b39d694c584d036f46a5f86aa8f05
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 1.12.1
|
2
|
+
* replaced all relevant system calls with new runners (fixed apply and
|
3
|
+
generic_secrets)
|
4
|
+
# 1.12.0
|
5
|
+
* refactoring Runner
|
6
|
+
* adding runner type system (popen is default)
|
7
|
+
* adding HelmRunner, KubectlRunner
|
8
|
+
* adding support for infra::allow_insecure_k8s_connections
|
9
|
+
* easing active support requirement
|
10
|
+
|
1
11
|
# 1.11.0
|
2
12
|
* generating helm output with resolved vairables in "helm_expanded"
|
3
13
|
* adding template_dir to templater to render whole directories
|
@@ -15,7 +15,10 @@ module Minfra
|
|
15
15
|
|
16
16
|
def dashboard(stack_name,env,deployment,cluster)
|
17
17
|
stack = init(stack_name,env,deployment,cluster)
|
18
|
-
|
18
|
+
insecure_flag = l("infra::allow_insecure_k8s_connections") ? "--insecure-skip-tls-verify" : ""
|
19
|
+
cmd = "k9s #{insecure_flag} --kubeconfig #{kube_config_path} --context #{stack.cluster_name} --namespace #{stack_name} --command pod"
|
20
|
+
debug(cmd)
|
21
|
+
exec(cmd)
|
19
22
|
end
|
20
23
|
|
21
24
|
def restart
|
@@ -154,9 +157,7 @@ module Minfra
|
|
154
157
|
|
155
158
|
extra_args = extra_args.join(' ')
|
156
159
|
|
157
|
-
|
158
|
-
#puts cmd
|
159
|
-
run_cmd(cmd, :exec)
|
160
|
+
run_helm("--kube-context #{cluster} rollback #{options[:stack]} #{extra_args}")
|
160
161
|
end
|
161
162
|
|
162
163
|
def list
|
@@ -195,9 +196,9 @@ module Minfra
|
|
195
196
|
|
196
197
|
cluster = stack.cluster_name
|
197
198
|
if [resource, implicit_resource].include?('pod') && ['delete', 'describe', 'exec', 'logs', 'port-forward'].include?(subcommand)
|
198
|
-
cmd_get_pods = "
|
199
|
+
cmd_get_pods = "--kubeconfig #{kube_config_path} --context #{cluster} --namespace #{options[:stack]} get pod -o jsonpath='{range .items[*]}{.metadata.name}{\"\\n\"}'"
|
199
200
|
|
200
|
-
pods_list =
|
201
|
+
pods_list = run_kubectl(cmd_get_pods).stdout_lines
|
201
202
|
|
202
203
|
fuzzy_pod_name = args.shift
|
203
204
|
|
@@ -230,9 +231,8 @@ module Minfra
|
|
230
231
|
|
231
232
|
extra_args = extra_args.join(' ')
|
232
233
|
|
233
|
-
cmd = "
|
234
|
-
|
235
|
-
run_cmd(cmd, :exec)
|
234
|
+
cmd = "--kubeconfig #{kube_config_path} --context #{cluster} --namespace #{options[:stack]} #{subcommand} #{resource} #{pod_name} #{extra_args}"
|
235
|
+
KubeCtlRunner.run(cmd, runner: :exec)
|
236
236
|
end
|
237
237
|
|
238
238
|
private
|
@@ -252,13 +252,11 @@ module Minfra
|
|
252
252
|
end
|
253
253
|
|
254
254
|
def run_kubectl(cmd)
|
255
|
-
|
256
|
-
run(%{kubectl #{cmd}})
|
255
|
+
KubeCtlRunner.run(cmd, runner: :system)
|
257
256
|
end
|
258
257
|
|
259
258
|
def run_helm(cmd)
|
260
|
-
|
261
|
-
run(%{helm #{cmd}})
|
259
|
+
HelmRunner.run(cmd, runner: :system)
|
262
260
|
end
|
263
261
|
|
264
262
|
def helm_path
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Minfra
|
2
|
+
module Cli
|
3
|
+
class HelmRunner < Runner
|
4
|
+
def initialize(cmd, **args)
|
5
|
+
insecure_flag = l("infra::allow_insecure_k8s_connections") ? "--kube-insecure-skip-tls-verify" : ""
|
6
|
+
cmd = "helm #{insecure_flag} #{cmd}"
|
7
|
+
super(cmd, **args)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Minfra
|
2
|
+
module Cli
|
3
|
+
class KubeCtlRunner < Runner
|
4
|
+
def initialize(cmd, **args)
|
5
|
+
insecure_flag = l("infra::allow_insecure_k8s_connections") ? "--insecure-skip-tls-verify" : ""
|
6
|
+
cmd = "kubectl #{insecure_flag} #{cmd}"
|
7
|
+
super(cmd, **args)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/minfra/cli/runner.rb
CHANGED
@@ -11,6 +11,8 @@ module Minfra
|
|
11
11
|
|
12
12
|
attr_writer :status
|
13
13
|
|
14
|
+
attr_reader :stdout_lines
|
15
|
+
|
14
16
|
def initialize
|
15
17
|
@stderr_lines = []
|
16
18
|
@stdout_lines = []
|
@@ -58,18 +60,58 @@ module Minfra
|
|
58
60
|
new(cmd, **args).run
|
59
61
|
end
|
60
62
|
|
61
|
-
attr_reader :exit_on_error
|
63
|
+
attr_reader :exit_on_error, :runner, :cmd
|
62
64
|
|
63
|
-
def initialize(cmd, exit_on_error: true)
|
65
|
+
def initialize(cmd, exit_on_error: true, runner: :popen)
|
64
66
|
@cmd = cmd
|
65
67
|
@exit_on_error = exit_on_error
|
68
|
+
@runner = runner
|
66
69
|
end
|
67
70
|
|
68
71
|
def run
|
69
|
-
debug("running: #{@cmd}")
|
70
|
-
res
|
72
|
+
debug("running (#{@runner}): #{@cmd}")
|
73
|
+
res=case @runner
|
74
|
+
when :system
|
75
|
+
run_system(Result.new)
|
76
|
+
when :popen
|
77
|
+
run_threaded(Result.new)
|
78
|
+
when :exec
|
79
|
+
run_exec(Result.new)
|
80
|
+
else
|
81
|
+
raise "unknown runner #{@runner}"
|
82
|
+
end
|
83
|
+
|
84
|
+
if res.error?
|
85
|
+
error "command failed: #{@cmd}"
|
86
|
+
debug res.stdout
|
87
|
+
info res.stderr
|
88
|
+
end
|
89
|
+
if exit_on_error && res.error?
|
90
|
+
info "command exiting on error (#{res.exitstatus})"
|
91
|
+
exit 1
|
92
|
+
end
|
93
|
+
res
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def run_exec(_res)
|
99
|
+
exec(@cmd)
|
100
|
+
end
|
101
|
+
# you don't get stderr .... yet
|
102
|
+
def run_system(res)
|
103
|
+
#https://stackoverflow.com/questions/6338908/ruby-difference-between-exec-system-and-x-or-backticks
|
104
|
+
begin
|
105
|
+
out=`#{@cmd}`
|
106
|
+
out.each_line do |line| res.add(line, :stdout) end
|
107
|
+
rescue StandardError
|
108
|
+
end
|
109
|
+
res.status = $?
|
110
|
+
res
|
111
|
+
end
|
112
|
+
|
113
|
+
def run_threaded(res)
|
71
114
|
begin
|
72
|
-
res = Result.new
|
73
115
|
# see: http://stackoverflow.com/a/1162850/83386
|
74
116
|
# the whole implementation is problematic as we migth miss some output lines
|
75
117
|
# Open4 might be a solution. Using Select might be a solution. Using Process.fork might be a solution....
|
@@ -91,18 +133,9 @@ module Minfra
|
|
91
133
|
end
|
92
134
|
rescue StandardError
|
93
135
|
end
|
94
|
-
|
95
|
-
if res.error?
|
96
|
-
error "command failed: #{@cmd}"
|
97
|
-
debug res.stdout
|
98
|
-
info res.stderr
|
99
|
-
end
|
100
|
-
if exit_on_error && res.error?
|
101
|
-
info "command exiting on error (#{res.exitstatus})"
|
102
|
-
exit 1
|
103
|
-
end
|
104
136
|
res
|
105
137
|
end
|
138
|
+
|
106
139
|
end
|
107
140
|
end
|
108
141
|
end
|
data/lib/minfra/cli/version.rb
CHANGED
data/lib/minfra/cli.rb
CHANGED
@@ -16,6 +16,8 @@ require_relative 'cli/command'
|
|
16
16
|
require_relative 'cli/ask'
|
17
17
|
require_relative 'cli/document'
|
18
18
|
require_relative 'cli/runner'
|
19
|
+
require_relative 'cli/helm_runner'
|
20
|
+
require_relative 'cli/kubectl_runner'
|
19
21
|
require_relative 'cli/plugins'
|
20
22
|
|
21
23
|
require 'active_support'
|
@@ -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
|
20
19
|
|
21
|
-
def initialize(cluster_name
|
20
|
+
def initialize(cluster_name:, namespace:, file_path:, app_config:, app:, 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.options = options
|
29
28
|
end
|
30
29
|
|
31
|
-
def template(file_path, helm, flag:
|
32
|
-
return
|
30
|
+
def template(file_path, helm, flag: '-f ', fix_file_path: nil)
|
31
|
+
return '' unless file_path
|
32
|
+
|
33
33
|
puts "Rendering: #{file_path}"
|
34
|
-
file_path = File.join(
|
35
|
-
|
34
|
+
file_path = File.join(dir_path, file_path)
|
35
|
+
|
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(
|
41
|
+
file = Tempfile.new('kube-deploy.yaml')
|
41
42
|
file.write(yaml)
|
42
43
|
file.close
|
43
44
|
file_path = file.path
|
@@ -46,11 +47,11 @@ module Orchparty
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def print_install(helm)
|
49
|
-
@out_io.puts
|
50
|
-
@out_io.puts install_cmd(helm, value_path(helm))
|
51
|
-
@out_io.puts upgrade_cmd(helm, value_path(helm))
|
52
|
-
@out_io.puts
|
53
|
-
@out_io.puts File.read(template(value_path(helm), helm, flag:
|
50
|
+
@out_io.puts '---'
|
51
|
+
@out_io.puts install_cmd(helm, value_path(helm)).cmd
|
52
|
+
@out_io.puts upgrade_cmd(helm, value_path(helm)).cmd
|
53
|
+
@out_io.puts '---'
|
54
|
+
@out_io.puts File.read(template(value_path(helm), helm, flag: '')) if value_path(helm)
|
54
55
|
end
|
55
56
|
|
56
57
|
# On 05.02.2021 we have decided that it would be best to print both commands.
|
@@ -60,11 +61,11 @@ module Orchparty
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def upgrade(helm)
|
63
|
-
@out_io.puts
|
64
|
+
@out_io.puts upgrade_cmd(helm).run.stdout
|
64
65
|
end
|
65
66
|
|
66
67
|
def install(helm)
|
67
|
-
@out_io.puts
|
68
|
+
@out_io.puts install_cmd(helm).run.stdout
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
@@ -74,11 +75,15 @@ module Orchparty
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def upgrade_cmd(helm, fix_file_path = nil)
|
77
|
-
"
|
78
|
+
Minfra::Cli::HelmRunner.new("upgrade --namespace #{namespace} --kube-context #{cluster_name} --version #{helm.version} #{helm.name} #{helm.chart} #{template(
|
79
|
+
value_path(helm), helm, fix_file_path: fix_file_path
|
80
|
+
)}")
|
78
81
|
end
|
79
82
|
|
80
83
|
def install_cmd(helm, fix_file_path = nil)
|
81
|
-
"
|
84
|
+
Minfra::Cli::HelmRunner.new("install --create-namespace --namespace #{namespace} --kube-context #{cluster_name} --version #{helm.version} #{helm.name} #{helm.chart} #{template(
|
85
|
+
value_path(helm), helm, fix_file_path: fix_file_path
|
86
|
+
)}")
|
82
87
|
end
|
83
88
|
end
|
84
89
|
|
@@ -88,11 +93,15 @@ module Orchparty
|
|
88
93
|
end
|
89
94
|
|
90
95
|
def upgrade_cmd(apply, fix_file_path = nil)
|
91
|
-
"
|
96
|
+
Minfra::Cli::KubeCtlRunner.new("apply --namespace #{namespace} --context #{cluster_name} #{template(
|
97
|
+
value_path(apply), apply, fix_file_path: fix_file_path
|
98
|
+
)}")
|
92
99
|
end
|
93
100
|
|
94
101
|
def install_cmd(apply, fix_file_path = nil)
|
95
|
-
"
|
102
|
+
Minfra::Cli::KubeCtlRunner.new("apply --namespace #{namespace} --context #{cluster_name} #{template(
|
103
|
+
value_path(apply), apply, fix_file_path: fix_file_path
|
104
|
+
)}")
|
96
105
|
end
|
97
106
|
end
|
98
107
|
|
@@ -101,43 +110,51 @@ module Orchparty
|
|
101
110
|
secret[:from_file]
|
102
111
|
end
|
103
112
|
|
104
|
-
def upgrade_cmd(secret, fix_file_path=nil)
|
105
|
-
"
|
113
|
+
def upgrade_cmd(secret, fix_file_path = nil)
|
114
|
+
Minfra::Cli::KubeCtlRunner.new("--namespace #{namespace} --context #{cluster_name} create secret generic --dry-run -o yaml #{secret[:name]} #{template(
|
115
|
+
value_path(secret), secret, flag: '--from-file=', fix_file_path: fix_file_path
|
116
|
+
)} | #{apply_cmd(cluster_name).cmd}")
|
106
117
|
end
|
107
118
|
|
108
|
-
def install_cmd(secret, fix_file_path=nil)
|
109
|
-
"
|
119
|
+
def install_cmd(secret, fix_file_path = nil)
|
120
|
+
Minfra::Cli::KubeCtlRunner.new("--namespace #{namespace} --context #{cluster_name} create secret generic --dry-run -o yaml #{secret[:name]} #{template(
|
121
|
+
value_path(secret), secret, flag: '--from-file=', fix_file_path: fix_file_path
|
122
|
+
)} | #{apply_cmd(cluster_name).cmd}")
|
123
|
+
end
|
124
|
+
|
125
|
+
def apply_cmd(cluster_name)
|
126
|
+
Minfra::Cli::KubeCtlRunner.new("--context #{cluster_name} apply -f -")
|
110
127
|
end
|
111
128
|
end
|
112
129
|
|
113
130
|
class Label < Context
|
114
131
|
def print_install(label)
|
115
|
-
@out_io.puts
|
132
|
+
@out_io.puts '---'
|
116
133
|
@out_io.puts install_cmd(label)
|
117
134
|
end
|
118
135
|
|
119
136
|
def print_upgrade(label)
|
120
|
-
@out_io.puts
|
137
|
+
@out_io.puts '---'
|
121
138
|
@out_io.puts upgrade_cmd(label)
|
122
139
|
end
|
123
140
|
|
124
141
|
def upgrade_cmd(label)
|
125
|
-
"
|
142
|
+
Minfra::Cli::KubeCtlRunner.new("--namespace #{namespace} --context #{cluster_name} label --overwrite #{label[:resource]} #{label[:name]} #{label['value']}")
|
126
143
|
end
|
127
144
|
|
128
145
|
def install_cmd(label)
|
129
|
-
"
|
146
|
+
Minfra::Cli::KubeCtlRunner.new("--namespace #{namespace} --context #{cluster_name} label --overwrite #{label[:resource]} #{label[:name]} #{label['value']}")
|
130
147
|
end
|
131
148
|
end
|
132
149
|
|
133
150
|
class Wait < Context
|
134
151
|
def print_install(wait)
|
135
|
-
@out_io.puts
|
152
|
+
@out_io.puts '---'
|
136
153
|
@out_io.puts wait.cmd
|
137
154
|
end
|
138
155
|
|
139
156
|
def print_upgrade(wait)
|
140
|
-
@out_io.puts
|
157
|
+
@out_io.puts '---'
|
141
158
|
@out_io.puts wait.cmd
|
142
159
|
end
|
143
160
|
|
@@ -159,19 +176,19 @@ module Orchparty
|
|
159
176
|
end
|
160
177
|
end
|
161
178
|
|
162
|
-
|
163
179
|
def print_install(chart)
|
164
|
-
|
165
180
|
build_chart(chart) do |chart_path|
|
166
|
-
cmd="helm template --namespace #{namespace} --debug --kube-context #{cluster_name} --output-dir #{chart_path.join(
|
181
|
+
cmd = "helm template --namespace #{namespace} --debug --kube-context #{cluster_name} --output-dir #{chart_path.join(
|
182
|
+
'..', 'helm_expanded'
|
183
|
+
)} #{chart.name} #{chart_path}"
|
167
184
|
@out_io.puts `$cmd`
|
168
185
|
if system("#{cmd} > /dev/null")
|
169
|
-
|
186
|
+
|
187
|
+
info('helm template check: OK')
|
170
188
|
else
|
171
|
-
error(
|
172
|
-
end
|
189
|
+
error('helm template check: FAIL')
|
190
|
+
end
|
173
191
|
end
|
174
|
-
|
175
192
|
end
|
176
193
|
|
177
194
|
def print_upgrade(chart)
|
@@ -181,52 +198,49 @@ module Orchparty
|
|
181
198
|
def install(chart)
|
182
199
|
info("Install: #{chart.name}")
|
183
200
|
build_chart(chart) do |chart_path|
|
184
|
-
|
201
|
+
res = Minfra::Cli::HelmRunner.new("install --create-namespace --namespace #{namespace} --kube-context #{cluster_name} #{chart.name} #{chart_path}").run
|
202
|
+
@out_io.puts res.stdout
|
185
203
|
end
|
186
204
|
end
|
187
205
|
|
188
206
|
def upgrade(chart)
|
189
207
|
info("Upgrade: #{chart}")
|
190
208
|
build_chart(chart) do |chart_path|
|
191
|
-
|
209
|
+
res = Minfra::Cli::HelmRunner.new("upgrade --namespace #{namespace} --kube-context #{cluster_name} #{chart.name} #{chart_path}").run
|
210
|
+
@out_io.puts res.stdout
|
192
211
|
end
|
193
212
|
end
|
213
|
+
|
194
214
|
private
|
195
|
-
|
215
|
+
|
196
216
|
def build_chart(chart)
|
197
|
-
|
198
|
-
|
199
217
|
dir = @app.status_dir.join('helm') # duplication
|
200
|
-
|
201
|
-
params = chart._services.map {|s| app_config.services[s.to_sym] }.map{|s| [s.name, s]}.to_h
|
202
|
-
run(templates_path: File.expand_path(chart.template,
|
218
|
+
|
219
|
+
params = chart._services.map { |s| app_config.services[s.to_sym] }.map { |s| [s.name, s] }.to_h
|
220
|
+
run(templates_path: File.expand_path(chart.template, dir_path), params: params, output_chart_path: dir,
|
221
|
+
chart: chart)
|
203
222
|
yield dir
|
204
223
|
end
|
205
224
|
|
206
|
-
|
207
|
-
|
208
225
|
# remember:
|
209
226
|
# this is done for an app
|
210
227
|
# that app can have multiple charts with multiple services!
|
211
|
-
|
212
|
-
def run(templates_path:, params:, output_chart_path:, chart: )
|
213
228
|
|
214
|
-
|
215
|
-
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|
|
216
231
|
params.each do |app_name, subparams|
|
217
232
|
subparams[:chart] = chart
|
218
|
-
used_vars=generate_documents_from_erbs(
|
233
|
+
used_vars = generate_documents_from_erbs(
|
219
234
|
templates_path: templates_path,
|
220
235
|
app_name: app_name,
|
221
236
|
params: subparams,
|
222
237
|
output_chart_path: output_chart_path
|
223
238
|
)
|
224
|
-
used_vars.each do |variable,value|
|
239
|
+
used_vars.each do |variable, value|
|
225
240
|
helm_values.puts "#{variable}: \"#{value}\""
|
226
241
|
end
|
227
242
|
end
|
228
243
|
end
|
229
|
-
|
230
244
|
end
|
231
245
|
|
232
246
|
def generate_documents_from_erbs(templates_path:, app_name:, params:, output_chart_path:)
|
@@ -236,13 +250,13 @@ module Orchparty
|
|
236
250
|
end
|
237
251
|
|
238
252
|
kind = params.fetch(:kind)
|
239
|
-
params._used_vars = {} #here we'll collect all used vars
|
253
|
+
params._used_vars = {} # here we'll collect all used vars
|
240
254
|
|
241
255
|
Dir[File.join(templates_path, kind, '*.erb')].each do |template_path|
|
242
256
|
info("Rendering Template: #{template_path}")
|
243
257
|
template_name = File.basename(template_path, '.erb')
|
244
258
|
output_path = File.join(output_chart_path, 'templates', "#{app_name}-#{template_name}")
|
245
|
-
|
259
|
+
|
246
260
|
template = Erubis::Eruby.new(File.read(template_path))
|
247
261
|
template.filename = template_path
|
248
262
|
|
@@ -252,14 +266,13 @@ module Orchparty
|
|
252
266
|
begin
|
253
267
|
document = template.result(CleanBinding.new.get_binding(params))
|
254
268
|
rescue Exception
|
255
|
-
error "#{template_path} has a problem: #{
|
269
|
+
error "#{template_path} has a problem: #{$ERROR_INFO.inspect}"
|
256
270
|
raise
|
257
271
|
end
|
258
272
|
File.write(output_path, document)
|
259
273
|
end
|
260
274
|
params._used_vars
|
261
275
|
end
|
262
|
-
|
263
276
|
end
|
264
277
|
end
|
265
278
|
end
|
@@ -267,19 +280,16 @@ end
|
|
267
280
|
class KubernetesApplication
|
268
281
|
include Minfra::Cli::Logging
|
269
282
|
|
270
|
-
attr_accessor :cluster_name
|
271
|
-
attr_accessor :file_path
|
272
|
-
attr_accessor :namespace
|
273
|
-
attr_accessor :app_config
|
283
|
+
attr_accessor :cluster_name, :file_path, :namespace, :app_config
|
274
284
|
attr_reader :status_dir
|
275
285
|
|
276
|
-
def initialize(
|
277
|
-
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
|
278
288
|
self.cluster_name = cluster_name
|
279
289
|
self.namespace = namespace
|
280
290
|
self.app_config = app_config
|
281
291
|
@status_dir = status_dir
|
282
|
-
@out_io= out_io
|
292
|
+
@out_io = out_io
|
283
293
|
end
|
284
294
|
|
285
295
|
def install
|
@@ -295,17 +305,17 @@ class KubernetesApplication
|
|
295
305
|
end
|
296
306
|
|
297
307
|
private
|
308
|
+
|
298
309
|
def prepare
|
299
|
-
|
300
310
|
output_chart_path = @status_dir.join('helm')
|
301
311
|
output_chart_path.rmtree if output_chart_path.exist?
|
302
312
|
output_chart_path.mkpath
|
303
|
-
templates_path = file_path.join('../../chart-templates').expand_path #don't ask. the whole concept of multiple charts in an app stinks...
|
304
|
-
|
313
|
+
templates_path = file_path.join('../../chart-templates').expand_path # don't ask. the whole concept of multiple charts in an app stinks...
|
314
|
+
|
305
315
|
generate_chart_yaml(
|
306
|
-
|
307
|
-
|
308
|
-
|
316
|
+
templates_path: templates_path,
|
317
|
+
output_chart_path: output_chart_path,
|
318
|
+
chart_name: namespace
|
309
319
|
)
|
310
320
|
|
311
321
|
info("generating base helm structure from: #{output_chart_path} from #{templates_path}")
|
@@ -313,26 +323,26 @@ class KubernetesApplication
|
|
313
323
|
|
314
324
|
system("cp #{File.join(templates_path, 'values.yaml')} #{File.join(output_chart_path, 'values.yaml')}")
|
315
325
|
system("cp #{File.join(templates_path, '.helmignore')} #{File.join(output_chart_path, '.helmignore')}")
|
316
|
-
system("cp #{File.join(templates_path,
|
317
|
-
|
326
|
+
system("cp #{File.join(templates_path,
|
327
|
+
'templates/_helpers.tpl')} #{File.join(output_chart_path, 'templates/_helpers.tpl')}")
|
318
328
|
end
|
319
329
|
|
320
|
-
def generate_chart_yaml(templates_path:, output_chart_path:, chart_name:
|
330
|
+
def generate_chart_yaml(templates_path:, output_chart_path:, chart_name:)
|
321
331
|
template_path = File.join(templates_path, 'Chart.yaml.erb')
|
322
332
|
output_path = File.join(output_chart_path, 'Chart.yaml')
|
323
333
|
|
324
|
-
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 })
|
325
335
|
File.write(output_path, res)
|
326
336
|
end
|
327
|
-
|
337
|
+
|
328
338
|
def combine_charts(app_config)
|
329
339
|
services = app_config._service_order.map(&:to_s)
|
330
340
|
app_config._service_order.each do |name|
|
331
341
|
current_service = app_config[:services][name]
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
342
|
+
next unless current_service._type == 'chart'
|
343
|
+
|
344
|
+
current_service._services.each do |n|
|
345
|
+
services.delete n.to_s
|
336
346
|
end
|
337
347
|
end
|
338
348
|
services
|
@@ -344,14 +354,14 @@ class KubernetesApplication
|
|
344
354
|
services.each do |name|
|
345
355
|
service = app_config[:services][name]
|
346
356
|
info "Service: #{name}(#{service._type}) #{method}"
|
347
|
-
deployable_class="::Orchparty::Services::#{service._type.classify}".constantize
|
348
|
-
deployable=deployable_class.new(cluster_name: cluster_name,
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
357
|
+
deployable_class = "::Orchparty::Services::#{service._type.classify}".constantize
|
358
|
+
deployable = deployable_class.new(cluster_name: cluster_name,
|
359
|
+
namespace: namespace,
|
360
|
+
file_path: file_path,
|
361
|
+
app_config: app_config,
|
362
|
+
out_io: @out_io,
|
363
|
+
app: self)
|
364
|
+
|
355
365
|
deployable.send(method, service)
|
356
366
|
end
|
357
367
|
end
|
data/minfra-cli.gemspec
CHANGED
@@ -31,9 +31,10 @@ 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", "
|
34
|
+
spec.add_runtime_dependency "activesupport", ">= 6.1"
|
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"
|
38
38
|
spec.add_runtime_dependency "hiera-eyaml-gpg", "0.7.4"
|
39
39
|
end
|
40
|
+
|
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.
|
4
|
+
version: 1.12.1
|
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-
|
11
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -76,14 +76,14 @@ dependencies:
|
|
76
76
|
name: activesupport
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '6.1'
|
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
88
|
version: '6.1'
|
89
89
|
- !ruby/object:Gem::Dependency
|
@@ -185,7 +185,9 @@ files:
|
|
185
185
|
- lib/minfra/cli/common.rb
|
186
186
|
- lib/minfra/cli/config.rb
|
187
187
|
- lib/minfra/cli/document.rb
|
188
|
+
- lib/minfra/cli/helm_runner.rb
|
188
189
|
- lib/minfra/cli/hook.rb
|
190
|
+
- lib/minfra/cli/kubectl_runner.rb
|
189
191
|
- lib/minfra/cli/logging.rb
|
190
192
|
- lib/minfra/cli/main_command.rb
|
191
193
|
- lib/minfra/cli/plugins.rb
|
@@ -237,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
239
|
- !ruby/object:Gem::Version
|
238
240
|
version: '0'
|
239
241
|
requirements: []
|
240
|
-
rubygems_version: 3.
|
242
|
+
rubygems_version: 3.3.7
|
241
243
|
signing_key:
|
242
244
|
specification_version: 4
|
243
245
|
summary: A cli framework for k8s based development and deployment.
|