kuber_kit 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7fcc957995bcc680107ef41f95ef77d5ee20dda2c0063d31e21bf339ccdae2d
4
- data.tar.gz: 80561e6e2562b9f195e6725c9dfcd785d36d741b4cf1779c7ccf1d071193c5ec
3
+ metadata.gz: 3f53003404cfe3339fb14d864f9b217dd93332d1c0d451ff34909a3a7224e2ab
4
+ data.tar.gz: c603662e4f86eebe2d0b4fa114576cef1518b4ce7c879c46a3bca8753f37eed9
5
5
  SHA512:
6
- metadata.gz: bd95c6391e1880cbe6e92eb43fc13278da1cef2bcf47c0bd0e2aab66932c640bf8c709dae8df5b36961baf19d41acd6c846907f27cab237a7d37113642d6b8ee
7
- data.tar.gz: 433d47c04f1a8f61e55e6dd664ab0818c0e687769cd29e9985acd74886abd2e5f4a2dacede60839c85797d71fa887e1196c61076837f6813c4fb55ac00fc25c2
6
+ metadata.gz: 6cc09c80cd1506066efc6ddb86b0bc01d7767fadaeab87fc5d7ca7275034505420d09c45f08566e42afe7e4bee0e89f16c298f8d3ee1010aef03c898b8c5de29
7
+ data.tar.gz: 89276b25a1de67c89386c86f584c558e4becb0ae100ae8a9f34bc230be6d81a9f1948965a5aa148173d005922757de8598ef7306561a4547700433b5cbc7ca08
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.1.9)
4
+ kuber_kit (0.2.0)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject
data/TODO.md CHANGED
@@ -1,3 +1,4 @@
1
+ - implement interactive shell.exec!
1
2
  - list services and require confirmation before deployment
2
3
  - add build vars support (use images instead of containers)
3
4
  - template should be able to set default attributes
@@ -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 = configuration_store.all_definitions.values.first
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
- raise KuberKit::Error, "Please set configuration name using -C option"
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
@@ -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
- result = KuberKit::Container['actions.image_compiler'].call(image_names, options)
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
- KuberKit::Container['actions.env_file_reader'].call(env_file_name.to_sym, options)
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
- KuberKit::Container['actions.template_reader'].call(template_name.to_sym, options)
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
- KuberKit::Container['actions.service_reader'].call(service_name.to_sym, options)
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
- KuberKit::Container['actions.kubectl_applier'].call(File.expand_path(file_path), options)
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 "deploy CONTEXT_NAME", "Deploy CONTEXT_NAME with kubectl"
65
- method_option :services, :type => :array, aliases: ["-s"]
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
- KuberKit::Container['actions.service_deployer'].call(services: options[:services], tags: options[:tags])
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?
@@ -29,6 +29,10 @@ class KuberKit::Container
29
29
  KuberKit::Actions::KubectlApplier.new
30
30
  end
31
31
 
32
+ register "actions.kubectl_attacher" do
33
+ KuberKit::Actions::KubectlAttacher.new
34
+ end
35
+
32
36
  register "configs" do
33
37
  KuberKit::Configs.new
34
38
  end
@@ -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
- args << "--exclude=#{exclude}"
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
@@ -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)}"
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.1.9"
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.1.9
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-13 00:00:00.000000000 Z
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