kuber_kit 0.3.5 → 0.3.6

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: 3b85ab09260c91266ffa73aec6ce0b3b369b82a232254f4e18c1ef787f960d25
4
- data.tar.gz: a93383f2184b54c84e5b25b22fe49d9eca085039031ee97ed97bffa48916b91c
3
+ metadata.gz: 1a2b626e99cbab815d586f4ca2c05796f367f25058502ab7f7b801a0d5191c70
4
+ data.tar.gz: 281a2179e9e15d017c65d76c95e1ee863e370fa405ac80571747c2bebaca8e2c
5
5
  SHA512:
6
- metadata.gz: 9bc50814f964e962ce3ce1470c7675278290989f7f0c15ec7ce9d91f5d987e20ed339fffb2a1e7d1cfea562803866cd94964abf7f49432b0fa0760dca8ef97c1
7
- data.tar.gz: c4affe9ecf83edc6b529d4d6fcdc2eb58b64e0c75e8d8e66b8ca790cb71d6c2adb093bb648d63450797dbd5280e4823d3ff206828c6f1317fe65cb46100802ab
6
+ metadata.gz: c755057ec72e897bce215977d2fef6e2b5bd2e72ae6b7bf6bd58774605bed91d22a73dda41a68783ea36e4c1a375eff432db6764ff1295baae243a0a2ca8a7e4
7
+ data.tar.gz: fbb4da6342592b1f5506911787f763f567804aa71fc975a76650e7b8e04137f10be5062e1bafa7ef89ec8bc1c0d86d53d73b9771cb2a90edc6debd7666c1212d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.3.5)
4
+ kuber_kit (0.3.6)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject
data/TODO.md CHANGED
@@ -1,8 +1,8 @@
1
+ - https://ttytoolkit.org/
2
+ - kit status should show the list of services and their status, with ability to select & view logs
1
3
  - list services and require confirmation before deployment
2
- - kit attach should list available deployments/pods, and ask for specific container if it has multiple containers
3
4
  - add kit logs support, should work similar to kit attach
4
5
  - allow deploying only services enabled for specific configuration
5
6
  - find a way to always deploy some service, e.g. for migrations and env_files
6
- - add ability to set container health checks
7
7
  - template should be able to set default attributes
8
8
  - template should be able to depend on image?
@@ -166,6 +166,8 @@ module KuberKit
166
166
  autoload :ConfigurationLoader, 'actions/configuration_loader'
167
167
  autoload :KubectlApplier, 'actions/kubectl_applier'
168
168
  autoload :KubectlAttacher, 'actions/kubectl_attacher'
169
+ autoload :KubectlConsole, 'actions/kubectl_console'
170
+ autoload :KubectlLogs, 'actions/kubectl_logs'
169
171
  end
170
172
 
171
173
  module Extensions
@@ -5,11 +5,17 @@ class KuberKit::Actions::KubectlAttacher
5
5
  "ui"
6
6
  ]
7
7
 
8
- Contract String, Hash => Any
8
+ Contract Maybe[String], Hash => Any
9
9
  def call(pod_name, options)
10
10
  kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
11
11
  deployer_namespace = KuberKit.current_configuration.deployer_namespace
12
12
 
13
+ if !pod_name
14
+ resources = kubectl_commands.get_resources(local_shell, "deployments", jsonpath: ".items[*].metadata.name")
15
+ options = resources.split(" ").map{|d| "deploy/#{d}" }
16
+ pod_name = ui.prompt("Please select deployment to attach", options)
17
+ end
18
+
13
19
  kubectl_commands.exec(
14
20
  local_shell, pod_name, "bash", args: "-it",
15
21
  kubeconfig_path: kubeconfig_path,
@@ -0,0 +1,32 @@
1
+ class KuberKit::Actions::KubectlConsole
2
+ include KuberKit::Import[
3
+ "shell.kubectl_commands",
4
+ "shell.local_shell",
5
+ "ui"
6
+ ]
7
+
8
+ Contract Maybe[String], Hash => Any
9
+ def call(pod_name, options)
10
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
11
+ deployer_namespace = KuberKit.current_configuration.deployer_namespace
12
+
13
+ if !pod_name
14
+ resources = kubectl_commands.get_resources(local_shell, "deployments", jsonpath: ".items[*].metadata.name")
15
+ options = resources.split(" ").map{|d| "deploy/#{d}" }
16
+ pod_name = ui.prompt("Please select deployment to attach", options)
17
+ end
18
+
19
+ kubectl_commands.exec(
20
+ local_shell, pod_name, "bin/console", args: "-it",
21
+ kubeconfig_path: kubeconfig_path,
22
+ interactive: true,
23
+ namespace: deployer_namespace
24
+ )
25
+
26
+ true
27
+ rescue KuberKit::Error => e
28
+ ui.print_error("Error", e.message)
29
+
30
+ false
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ class KuberKit::Actions::KubectlLogs
2
+ include KuberKit::Import[
3
+ "shell.kubectl_commands",
4
+ "shell.local_shell",
5
+ "ui"
6
+ ]
7
+
8
+ Contract Maybe[String], Hash => Any
9
+ def call(pod_name, options)
10
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
11
+ deployer_namespace = KuberKit.current_configuration.deployer_namespace
12
+
13
+ if !pod_name
14
+ deployments = kubectl_commands.get_resources(local_shell, "deployments", jsonpath: ".items[*].metadata.name")
15
+ deploy_options = deployments.split(" ").map{|d| "deploy/#{d}" }
16
+ pod_name = ui.prompt("Please select deployment to attach", deploy_options)
17
+ end
18
+
19
+ args = ""
20
+ if options[:follow]
21
+ args = "-f"
22
+ end
23
+
24
+ kubectl_commands.logs(
25
+ local_shell, pod_name,
26
+ args: args,
27
+ kubeconfig_path: kubeconfig_path,
28
+ namespace: deployer_namespace
29
+ )
30
+
31
+ true
32
+ rescue KuberKit::Error => e
33
+ ui.print_error("Error", e.message)
34
+
35
+ false
36
+ end
37
+ end
@@ -93,8 +93,8 @@ class KuberKit::CLI < Thor
93
93
  end
94
94
  end
95
95
 
96
- desc "attach POD_NAME", "Attach to POD_NAME with kubectl"
97
- def attach(pod_name)
96
+ desc "attach POD_NAME", "Attach to POD_NAME using kubectl"
97
+ def attach(pod_name = nil)
98
98
  KuberKit.set_debug_mode(options[:debug])
99
99
 
100
100
  if KuberKit::Container['actions.configuration_loader'].call(options)
@@ -102,6 +102,25 @@ class KuberKit::CLI < Thor
102
102
  end
103
103
  end
104
104
 
105
+ desc "launch console in POD_NAME", "Attach to POD_NAME using kubectl & launch bin/console"
106
+ def console(pod_name = nil)
107
+ KuberKit.set_debug_mode(options[:debug])
108
+
109
+ if KuberKit::Container['actions.configuration_loader'].call(options)
110
+ KuberKit::Container['actions.kubectl_console'].call(pod_name, options)
111
+ end
112
+ end
113
+
114
+ desc "show logs for POD_NAME", "Show logs for POD_NAME using kubectl"
115
+ method_option :follow, :type => :boolean, aliases: ["-f"]
116
+ def logs(pod_name = nil)
117
+ KuberKit.set_debug_mode(options[:debug])
118
+
119
+ if KuberKit::Container['actions.configuration_loader'].call(options)
120
+ KuberKit::Container['actions.kubectl_logs'].call(pod_name, options)
121
+ end
122
+ end
123
+
105
124
  desc "version", "Print current version"
106
125
  def version
107
126
  puts KuberKit::VERSION
@@ -33,6 +33,14 @@ class KuberKit::Container
33
33
  KuberKit::Actions::KubectlAttacher.new
34
34
  end
35
35
 
36
+ register "actions.kubectl_console" do
37
+ KuberKit::Actions::KubectlConsole.new
38
+ end
39
+
40
+ register "actions.kubectl_logs" do
41
+ KuberKit::Actions::KubectlLogs.new
42
+ end
43
+
36
44
  register "configs" do
37
45
  KuberKit::Configs.new
38
46
  end
@@ -40,15 +40,38 @@ class KuberKit::Shell::Commands::KubectlCommands
40
40
  kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, interactive: interactive, namespace: namespace)
41
41
  end
42
42
 
43
- def resource_exists?(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
44
- result = find_resources(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
45
- result && result != ""
43
+ def logs(shell, pod_name, args: nil, kubeconfig_path: nil, namespace: nil)
44
+ command_parts = []
45
+ command_parts << "logs"
46
+
47
+ if args
48
+ command_parts << args
49
+ end
50
+
51
+ command_parts << pod_name
52
+ kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, interactive: true, namespace: namespace)
46
53
  end
47
54
 
48
- def find_resources(shell, resource_type, resource_name, jsonpath: ".items[*].metadata.name", kubeconfig_path: nil, namespace: nil)
49
- command = %Q{get #{resource_type} --field-selector=metadata.name=#{resource_name} -o jsonpath='{#{jsonpath}}'}
55
+ def get_resources(shell, resource_type, field_selector: nil, jsonpath: ".items[*].metadata.name", kubeconfig_path: nil, namespace: nil)
56
+ command_parts = []
57
+ command_parts << "get #{resource_type}"
50
58
 
51
- kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
59
+ if field_selector
60
+ command_parts << "--field-selector=#{field_selector}"
61
+ end
62
+
63
+ if jsonpath
64
+ command_parts << "-o jsonpath='{#{jsonpath}}'"
65
+ end
66
+
67
+ kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace)
68
+ end
69
+
70
+ def resource_exists?(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
71
+ result = get_resources(shell, resource_type,
72
+ field_selector: "metadata.name=#{resource_name}", kubeconfig_path: kubeconfig_path, namespace: namespace
73
+ )
74
+ result && result != ""
52
75
  end
53
76
 
54
77
  def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
@@ -29,7 +29,13 @@ class KuberKit::UI::Interactive
29
29
  def prompt(text, options, &callback)
30
30
  CLI::UI::Prompt.ask(text) do |handler|
31
31
  options.each do |option|
32
- handler.option(option, &callback)
32
+ if callback
33
+ handler.option(option, &callback)
34
+ else
35
+ handler.option(option) do |selection|
36
+ selection
37
+ end
38
+ end
33
39
  end
34
40
  end
35
41
  end
@@ -71,7 +71,8 @@ class KuberKit::UI::Simple
71
71
  def prompt(text, options, &callback)
72
72
  print_info("Select", text)
73
73
  result = $stdin.gets.chomp
74
- callback.call(result)
74
+ callback.call(result) if callback
75
+ result
75
76
  end
76
77
 
77
78
  private
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
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.3.5
4
+ version: 0.3.6
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-01-06 00:00:00.000000000 Z
11
+ date: 2021-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts-lite
@@ -191,6 +191,8 @@ files:
191
191
  - lib/kuber_kit/actions/image_compiler.rb
192
192
  - lib/kuber_kit/actions/kubectl_applier.rb
193
193
  - lib/kuber_kit/actions/kubectl_attacher.rb
194
+ - lib/kuber_kit/actions/kubectl_console.rb
195
+ - lib/kuber_kit/actions/kubectl_logs.rb
194
196
  - lib/kuber_kit/actions/service_deployer.rb
195
197
  - lib/kuber_kit/actions/service_reader.rb
196
198
  - lib/kuber_kit/actions/template_reader.rb