kuber_kit 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/TODO.md +3 -2
- data/example/configurations/review.rb +1 -1
- data/example/images/ruby_app/Dockerfile +3 -1
- data/example/services/docker_app.rb +1 -1
- data/lib/kuber_kit.rb +2 -0
- data/lib/kuber_kit/actions/service_deployer.rb +3 -0
- data/lib/kuber_kit/cli.rb +17 -0
- data/lib/kuber_kit/container.rb +8 -0
- data/lib/kuber_kit/shell/commands/system_commands.rb +32 -0
- data/lib/kuber_kit/shell/local_shell.rb +6 -2
- data/lib/kuber_kit/shell/ssh_shell.rb +1 -1
- data/lib/kuber_kit/tools/process_cleaner.rb +38 -0
- data/lib/kuber_kit/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d221b8cd2f09dc4a239e125c2d53ebed3b6ba85c07cbf47f13b13f064b4acc35
|
4
|
+
data.tar.gz: fe87b38b80cf8e76bcd8f24a8c12e5e1564cf39ca184065d7f10463419ae3472
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9820d98b32ddb5876ad536c3a785360db92e6301b9d359f7fd6cc795cfdc996408eb52685d891b3ef7a058f7e6022247afa057ac0ed65f1db33adff7eb5d6274
|
7
|
+
data.tar.gz: 51376794f59eb73726187455144309c957b04850fd9c1c92b98de82109536105db94f4babd0734ff422907ae65a4722fad0fd2f271ee030819ff40173953d8fe
|
data/Gemfile.lock
CHANGED
data/TODO.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
- do not show result for images list, if list is too large (Mikhail)
|
1
2
|
- add kit get method for interactive kubernetes
|
2
|
-
- do not show result for images list, if list is too large
|
3
3
|
- kit status should show the list of services and their status, with ability to select & view logs
|
4
4
|
- find a way to always deploy some service, e.g. for migrations and env_files
|
5
5
|
- template should be able to set default attributes
|
6
6
|
- template should be able to depend on image?
|
7
|
-
- cleanup image builds older than some date
|
7
|
+
- cleanup image builds older than some date
|
8
|
+
- add some rotation for deploy log
|
data/lib/kuber_kit.rb
CHANGED
@@ -76,6 +76,7 @@ module KuberKit
|
|
76
76
|
module Tools
|
77
77
|
autoload :FilePresenceChecker, 'tools/file_presence_checker'
|
78
78
|
autoload :LoggerFactory, 'tools/logger_factory'
|
79
|
+
autoload :ProcessCleaner, 'tools/process_cleaner'
|
79
80
|
end
|
80
81
|
|
81
82
|
module Shell
|
@@ -92,6 +93,7 @@ module KuberKit
|
|
92
93
|
autoload :GitCommands, 'shell/commands/git_commands'
|
93
94
|
autoload :RsyncCommands, 'shell/commands/rsync_commands'
|
94
95
|
autoload :KubectlCommands, 'shell/commands/kubectl_commands'
|
96
|
+
autoload :SystemCommands, 'shell/commands/system_commands'
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
@@ -4,6 +4,7 @@ class KuberKit::Actions::ServiceDeployer
|
|
4
4
|
"service_deployer.service_list_resolver",
|
5
5
|
"core.service_store",
|
6
6
|
"shell.local_shell",
|
7
|
+
"tools.process_cleaner",
|
7
8
|
"ui",
|
8
9
|
service_deployer: "service_deployer.action_handler",
|
9
10
|
]
|
@@ -56,6 +57,8 @@ class KuberKit::Actions::ServiceDeployer
|
|
56
57
|
ui.print_error("Error", e.message)
|
57
58
|
|
58
59
|
false
|
60
|
+
rescue Interrupt => e
|
61
|
+
process_cleaner.clean
|
59
62
|
end
|
60
63
|
|
61
64
|
def deploy_services(service_names)
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -160,4 +160,21 @@ class KuberKit::CLI < Thor
|
|
160
160
|
def print_result(message, data = {})
|
161
161
|
KuberKit::Container['ui'].print_result(message, data)
|
162
162
|
end
|
163
|
+
|
164
|
+
def cleanup_processes
|
165
|
+
# Stop all threads
|
166
|
+
Thread.list.each do |t|
|
167
|
+
t.abort_on_exception = false
|
168
|
+
t.report_on_exception = false
|
169
|
+
Thread.kill(t) if t != Thread.current
|
170
|
+
end
|
171
|
+
|
172
|
+
# Find all system calls
|
173
|
+
child_pids_raw = `ps auxww | grep '[K]IT=#{Process.pid}' | awk '{print $2}'`
|
174
|
+
child_pids = child_pids_raw.to_s.split("\n").reject(&:empty?)
|
175
|
+
child_pids.each do |pid|
|
176
|
+
puts "Killing child process: #{pid}"
|
177
|
+
Process.kill("SIGHUP", pid.to_i)
|
178
|
+
end
|
179
|
+
end
|
163
180
|
end
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -121,6 +121,10 @@ class KuberKit::Container
|
|
121
121
|
KuberKit::Container["tools.logger_factory"].create()
|
122
122
|
end
|
123
123
|
|
124
|
+
register "tools.process_cleaner" do
|
125
|
+
KuberKit::Tools::ProcessCleaner.new
|
126
|
+
end
|
127
|
+
|
124
128
|
register "shell.bash_commands" do
|
125
129
|
KuberKit::Shell::Commands::BashCommands.new
|
126
130
|
end
|
@@ -145,6 +149,10 @@ class KuberKit::Container
|
|
145
149
|
KuberKit::Shell::Commands::KubectlCommands.new
|
146
150
|
end
|
147
151
|
|
152
|
+
register "shell.system_commands" do
|
153
|
+
KuberKit::Shell::Commands::SystemCommands.new
|
154
|
+
end
|
155
|
+
|
148
156
|
register "shell.local_shell" do
|
149
157
|
KuberKit::Shell::LocalShell.new
|
150
158
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class KuberKit::Shell::Commands::SystemCommands
|
2
|
+
def kill_process(shell, pid)
|
3
|
+
# we need to use kill command directly sometimes,
|
4
|
+
# because Process.kill doesn't kill processes created by system() call
|
5
|
+
shell.exec!("kill -9 #{pid}")
|
6
|
+
true
|
7
|
+
rescue
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_pids_by_name(shell, name)
|
12
|
+
shell
|
13
|
+
.exec!("ps auxww | grep '#{name}' | grep -v 'grep' | awk '{print $2}'")
|
14
|
+
.split("\n")
|
15
|
+
.reject(&:empty?)
|
16
|
+
.map(&:chomp)
|
17
|
+
.map(&:to_i)
|
18
|
+
rescue
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_child_pids(shell, pid)
|
23
|
+
shell
|
24
|
+
.exec!("pgrep -P #{pid}")
|
25
|
+
.split("\n")
|
26
|
+
.reject(&:empty?)
|
27
|
+
.map(&:chomp)
|
28
|
+
.map(&:to_i)
|
29
|
+
rescue
|
30
|
+
[]
|
31
|
+
end
|
32
|
+
end
|
@@ -15,7 +15,7 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
15
15
|
end
|
16
16
|
|
17
17
|
result = nil
|
18
|
-
IO.popen(command, err: [:child, :out]) do |io|
|
18
|
+
IO.popen(wrap_command_with_pid(command), err: [:child, :out]) do |io|
|
19
19
|
result = io.read.chomp.strip
|
20
20
|
end
|
21
21
|
|
@@ -37,7 +37,7 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
37
37
|
ui.print_debug("LocalShell", "Interactive: [#{command_number}]: #{command.to_s.cyan}")
|
38
38
|
end
|
39
39
|
|
40
|
-
result = system(command)
|
40
|
+
result = system(wrap_command_with_pid(command))
|
41
41
|
|
42
42
|
if !$?.success?
|
43
43
|
raise ShellError, "Shell command failed: #{command}\r\n#{result}"
|
@@ -86,6 +86,10 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
def wrap_command_with_pid(command)
|
90
|
+
"KIT=#{Process.pid} #{command}"
|
91
|
+
end
|
92
|
+
|
89
93
|
private
|
90
94
|
def ensure_directory_exists(file_path)
|
91
95
|
dir_path = File.dirname(file_path)
|
@@ -27,7 +27,7 @@ class KuberKit::Shell::SshShell < KuberKit::Shell::LocalShell
|
|
27
27
|
ui.print_debug("SshShell", "#{ssh_session.host.green} > Execute: [#{command_number}]: #{command.to_s.cyan}")
|
28
28
|
end
|
29
29
|
|
30
|
-
result = ssh_session.exec!(command)
|
30
|
+
result = ssh_session.exec!(wrap_command_with_pid(command))
|
31
31
|
|
32
32
|
if result && result != "" && log_command
|
33
33
|
ui.print_debug("SshShell", "#{ssh_session.host.green} > Finished [#{command_number}] with result: \n#{result.grey}")
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class KuberKit::Tools::ProcessCleaner
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.system_commands",
|
4
|
+
"shell.local_shell"
|
5
|
+
]
|
6
|
+
|
7
|
+
def clean
|
8
|
+
stop_threads
|
9
|
+
stop_child_proceses
|
10
|
+
end
|
11
|
+
|
12
|
+
def stop_threads
|
13
|
+
Thread.list.each do |t|
|
14
|
+
t.abort_on_exception = false
|
15
|
+
t.report_on_exception = false
|
16
|
+
Thread.kill(t) if t != Thread.current
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def stop_child_proceses
|
21
|
+
find_all_child_processes.each do |pid|
|
22
|
+
system_commands.kill_process(local_shell, pid)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def find_all_child_processes
|
29
|
+
pids = system_commands.find_pids_by_name(local_shell, "KIT=#{Process.pid}")
|
30
|
+
pids + get_child_pids(pids)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_child_pids(pids)
|
34
|
+
pids
|
35
|
+
.map{ |p| system_commands.get_child_pids(local_shell, p) }
|
36
|
+
.flatten
|
37
|
+
end
|
38
|
+
end
|
data/lib/kuber_kit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuber_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -294,6 +294,7 @@ files:
|
|
294
294
|
- lib/kuber_kit/shell/commands/git_commands.rb
|
295
295
|
- lib/kuber_kit/shell/commands/kubectl_commands.rb
|
296
296
|
- lib/kuber_kit/shell/commands/rsync_commands.rb
|
297
|
+
- lib/kuber_kit/shell/commands/system_commands.rb
|
297
298
|
- lib/kuber_kit/shell/local_shell.rb
|
298
299
|
- lib/kuber_kit/shell/ssh_session.rb
|
299
300
|
- lib/kuber_kit/shell/ssh_shell.rb
|
@@ -303,6 +304,7 @@ files:
|
|
303
304
|
- lib/kuber_kit/template_reader/strategies/artifact_file.rb
|
304
305
|
- lib/kuber_kit/tools/file_presence_checker.rb
|
305
306
|
- lib/kuber_kit/tools/logger_factory.rb
|
307
|
+
- lib/kuber_kit/tools/process_cleaner.rb
|
306
308
|
- lib/kuber_kit/ui.rb
|
307
309
|
- lib/kuber_kit/ui/api.rb
|
308
310
|
- lib/kuber_kit/ui/debug.rb
|