kuber_kit 0.1.9 → 0.2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/TODO.md +1 -0
- data/lib/kuber_kit.rb +1 -0
- data/lib/kuber_kit/actions/configuration_loader.rb +6 -2
- data/lib/kuber_kit/actions/kubectl_attacher.rb +19 -0
- data/lib/kuber_kit/cli.rb +43 -18
- data/lib/kuber_kit/container.rb +4 -0
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +24 -0
- data/lib/kuber_kit/shell/commands/rsync_commands.rb +8 -2
- data/lib/kuber_kit/ui/interactive.rb +8 -0
- data/lib/kuber_kit/ui/simple.rb +6 -0
- data/lib/kuber_kit/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f53003404cfe3339fb14d864f9b217dd93332d1c0d451ff34909a3a7224e2ab
|
4
|
+
data.tar.gz: c603662e4f86eebe2d0b4fa114576cef1518b4ce7c879c46a3bca8753f37eed9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cc09c80cd1506066efc6ddb86b0bc01d7767fadaeab87fc5d7ca7275034505420d09c45f08566e42afe7e4bee0e89f16c298f8d3ee1010aef03c898b8c5de29
|
7
|
+
data.tar.gz: 89276b25a1de67c89386c86f584c558e4becb0ae100ae8a9f34bc230be6d81a9f1948965a5aa148173d005922757de8598ef7306561a4547700433b5cbc7ca08
|
data/Gemfile.lock
CHANGED
data/TODO.md
CHANGED
data/lib/kuber_kit.rb
CHANGED
@@ -157,6 +157,7 @@ module KuberKit
|
|
157
157
|
autoload :ServiceDeployer, 'actions/service_deployer'
|
158
158
|
autoload :ConfigurationLoader, 'actions/configuration_loader'
|
159
159
|
autoload :KubectlApplier, 'actions/kubectl_applier'
|
160
|
+
autoload :KubectlAttacher, 'actions/kubectl_attacher'
|
160
161
|
end
|
161
162
|
|
162
163
|
module Extensions
|
@@ -65,13 +65,17 @@ class KuberKit::Actions::ConfigurationLoader
|
|
65
65
|
configuration_name ||= :_default_
|
66
66
|
end
|
67
67
|
|
68
|
+
all_configurations = configuration_store.all_definitions.values
|
68
69
|
if configuration_store.count == 1 && configuration_name.nil?
|
69
|
-
first_configurations =
|
70
|
+
first_configurations = all_configurations.first
|
70
71
|
configuration_name = first_configurations.configuration_name
|
71
72
|
end
|
72
73
|
|
73
74
|
if configuration_store.count > 1 && configuration_name.nil?
|
74
|
-
|
75
|
+
options = all_configurations.map(&:configuration_name).map(&:to_s)
|
76
|
+
ui.prompt("Please select configuration name (or set it using -C option)", options) do |selection|
|
77
|
+
configuration_name = selection
|
78
|
+
end
|
75
79
|
end
|
76
80
|
|
77
81
|
KuberKit.set_configuration_name(configuration_name)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class KuberKit::Actions::KubectlAttacher
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.kubectl_commands",
|
4
|
+
"shell.local_shell",
|
5
|
+
"ui"
|
6
|
+
]
|
7
|
+
|
8
|
+
Contract String, Hash => Any
|
9
|
+
def call(pod_name, options)
|
10
|
+
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
11
|
+
kubectl_commands.exec(local_shell, pod_name, "bash", args: "-it", kubeconfig_path: kubeconfig_path, interactive: true)
|
12
|
+
|
13
|
+
true
|
14
|
+
rescue KuberKit::Error => e
|
15
|
+
ui.print_error("Error", e.message)
|
16
|
+
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -14,11 +14,12 @@ class KuberKit::CLI < Thor
|
|
14
14
|
|
15
15
|
image_names = image_names_str.split(",").map(&:strip).map(&:to_sym)
|
16
16
|
|
17
|
-
KuberKit::Container['actions.configuration_loader'].call(options)
|
18
|
-
|
17
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
18
|
+
result = KuberKit::Container['actions.image_compiler'].call(image_names, options)
|
19
|
+
end
|
19
20
|
|
21
|
+
logger = KuberKit::Container['tools.logger']
|
20
22
|
if result
|
21
|
-
logger = KuberKit::Container['tools.logger']
|
22
23
|
logger.info("---------------------------")
|
23
24
|
logger.info("Image compilation finished!")
|
24
25
|
logger.info("---------------------------")
|
@@ -29,47 +30,71 @@ class KuberKit::CLI < Thor
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
33
|
+
desc "deploy CONTEXT_NAME", "Deploy CONTEXT_NAME with kubectl"
|
34
|
+
method_option :services, :type => :array, aliases: ["-s"]
|
35
|
+
method_option :tags, :type => :array, aliases: ["-t"]
|
36
|
+
def deploy
|
37
|
+
KuberKit.set_debug_mode(options[:debug])
|
38
|
+
|
39
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
40
|
+
result = KuberKit::Container['actions.service_deployer'].call(services: options[:services], tags: options[:tags])
|
41
|
+
end
|
42
|
+
|
43
|
+
logger = KuberKit::Container['tools.logger']
|
44
|
+
if result
|
45
|
+
logger.info("---------------------------")
|
46
|
+
logger.info("Service deployment finished!")
|
47
|
+
logger.info("---------------------------")
|
48
|
+
else
|
49
|
+
logger.info("-------------------------".red)
|
50
|
+
logger.info("Service deployment failed!".red)
|
51
|
+
logger.info("-------------------------".red)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
32
55
|
desc "env ENV_FILE_NAME", "Return content of Env File ENV_FILE_NAME"
|
33
56
|
def env(env_file_name)
|
34
57
|
KuberKit.set_debug_mode(options[:debug])
|
35
58
|
|
36
|
-
KuberKit::Container['actions.configuration_loader'].call(options)
|
37
|
-
|
59
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
60
|
+
KuberKit::Container['actions.env_file_reader'].call(env_file_name.to_sym, options)
|
61
|
+
end
|
38
62
|
end
|
39
63
|
|
40
64
|
desc "template TEMPLATE_NAME", "Return content of Template TEMPLATE_NAME"
|
41
65
|
def template(template_name)
|
42
66
|
KuberKit.set_debug_mode(options[:debug])
|
43
67
|
|
44
|
-
KuberKit::Container['actions.configuration_loader'].call(options)
|
45
|
-
|
68
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
69
|
+
KuberKit::Container['actions.template_reader'].call(template_name.to_sym, options)
|
70
|
+
end
|
46
71
|
end
|
47
72
|
|
48
73
|
desc "service SERVICE_NAME", "Return content of Service SERVICE_NAME"
|
49
74
|
def service(service_name)
|
50
75
|
KuberKit.set_debug_mode(options[:debug])
|
51
76
|
|
52
|
-
KuberKit::Container['actions.configuration_loader'].call(options)
|
53
|
-
|
77
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
78
|
+
KuberKit::Container['actions.service_reader'].call(service_name.to_sym, options)
|
79
|
+
end
|
54
80
|
end
|
55
81
|
|
56
82
|
desc "apply FILE_PATH", "Apply FILE_PATH with kubectl"
|
57
83
|
def apply(file_path)
|
58
84
|
KuberKit.set_debug_mode(options[:debug])
|
59
85
|
|
60
|
-
KuberKit::Container['actions.configuration_loader'].call(options)
|
61
|
-
|
86
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
87
|
+
KuberKit::Container['actions.kubectl_applier'].call(File.expand_path(file_path), options)
|
88
|
+
end
|
62
89
|
end
|
63
90
|
|
64
|
-
desc "
|
65
|
-
|
66
|
-
method_option :tags, :type => :array, aliases: ["-t"]
|
67
|
-
def deploy
|
91
|
+
desc "attach POD_NAME", "Attach to POD_NAME with kubectl"
|
92
|
+
def attach(pod_name)
|
68
93
|
KuberKit.set_debug_mode(options[:debug])
|
69
94
|
|
70
|
-
KuberKit::Container['actions.configuration_loader'].call(options)
|
71
|
-
|
72
|
-
|
95
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
96
|
+
KuberKit::Container['actions.kubectl_attacher'].call(pod_name, options)
|
97
|
+
end
|
73
98
|
end
|
74
99
|
|
75
100
|
def self.exit_on_failure?
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -13,6 +13,30 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
13
13
|
shell.exec!(command_parts.join(" "))
|
14
14
|
end
|
15
15
|
|
16
|
+
def exec(shell, pod_name, command, args: nil, kubeconfig_path: nil, interactive: false)
|
17
|
+
command_parts = []
|
18
|
+
|
19
|
+
if kubeconfig_path
|
20
|
+
command_parts << "KUBECONFIG=#{kubeconfig_path}"
|
21
|
+
end
|
22
|
+
|
23
|
+
command_parts << "kubectl exec"
|
24
|
+
|
25
|
+
if args
|
26
|
+
command_parts << args
|
27
|
+
end
|
28
|
+
|
29
|
+
command_parts << pod_name
|
30
|
+
command_parts << "-- #{command}"
|
31
|
+
|
32
|
+
# TODO: investigate how to do it with shell.
|
33
|
+
if interactive
|
34
|
+
system(command_parts.join(" "))
|
35
|
+
else
|
36
|
+
shell.exec!(command_parts.join(" "))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
16
40
|
def rolling_restart(shell, deployment_name, kubeconfig_path: nil)
|
17
41
|
patch_deployment(shell, deployment_name, {
|
18
42
|
spec: {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class KuberKit::Shell::Commands::RsyncCommands
|
2
|
-
def rsync(shell, source_path, target_path, target_host: nil, exclude: nil)
|
2
|
+
def rsync(shell, source_path, target_path, target_host: nil, exclude: nil, delete: true)
|
3
3
|
# Add a trailing slash to directory to have behavior similar to CP command
|
4
4
|
if path_is_directory?(source_path) && !source_path.end_with?("/")
|
5
5
|
source_path = "#{source_path}/"
|
@@ -13,7 +13,13 @@ class KuberKit::Shell::Commands::RsyncCommands
|
|
13
13
|
|
14
14
|
args = [source_path, destination]
|
15
15
|
if exclude
|
16
|
-
|
16
|
+
Array(exclude).each do |e|
|
17
|
+
args << "--exclude=#{e}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
if delete
|
22
|
+
args << "--delete"
|
17
23
|
end
|
18
24
|
|
19
25
|
shell.exec!(%Q{rsync -a #{args.join(' ')}})
|
@@ -26,6 +26,14 @@ class KuberKit::UI::Interactive
|
|
26
26
|
print_in_frame(title, text, color: :yellow)
|
27
27
|
end
|
28
28
|
|
29
|
+
def prompt(text, options, &callback)
|
30
|
+
CLI::UI::Prompt.ask(text) do |handler|
|
31
|
+
options.each do |option|
|
32
|
+
handler.option(option, &callback)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
private
|
30
38
|
def init
|
31
39
|
@initialized = true
|
data/lib/kuber_kit/ui/simple.rb
CHANGED
@@ -68,6 +68,12 @@ class KuberKit::UI::Simple
|
|
68
68
|
print_text(title, text, color: String::Colors::YELLOW)
|
69
69
|
end
|
70
70
|
|
71
|
+
def prompt(text, options, &callback)
|
72
|
+
print_info("Select", text)
|
73
|
+
result = $stdin.gets.chomp
|
74
|
+
callback.call(result)
|
75
|
+
end
|
76
|
+
|
71
77
|
private
|
72
78
|
def print_text(title, text, color:)
|
73
79
|
puts "#{title.colorize(color)}\r\n #{text.colorize(color)}"
|
data/lib/kuber_kit/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module KuberKit
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.2.0"
|
3
|
+
end
|
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
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/kuber_kit/actions/env_file_reader.rb
|
188
188
|
- lib/kuber_kit/actions/image_compiler.rb
|
189
189
|
- lib/kuber_kit/actions/kubectl_applier.rb
|
190
|
+
- lib/kuber_kit/actions/kubectl_attacher.rb
|
190
191
|
- lib/kuber_kit/actions/service_deployer.rb
|
191
192
|
- lib/kuber_kit/actions/service_reader.rb
|
192
193
|
- lib/kuber_kit/actions/template_reader.rb
|