kuberun 0.2.1 → 0.3.1

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: 5569141234bbe2c667168f5ca0587f27a4633b20c5ce14a6d0cf61dd3ed84895
4
- data.tar.gz: 4897e0ca010cb47047e0983f94490178f69008712897be77b3cfbed5b897af57
3
+ metadata.gz: 9866a7b293e3bf832f66ee91b61ce7054c0d0dd91219343dae1eee009f87d9f5
4
+ data.tar.gz: 4bb59f1eebabb62e001541b834c35ba35336da052e3d068f18dd020c7258b618
5
5
  SHA512:
6
- metadata.gz: f62784bfabb71b553ca570887d08086fffe5ef5d652cb1f9ab0dbecb596b7d0b3ce443bc44efe8293e3e4e74531604df0b0586620ae2cbb2785c75e03bc6c37d
7
- data.tar.gz: f5308fb809a4184af4ce0238be81fb87654d342c76520ed9ed462ecadcf86ed84c32fe14f69356774452b2434199ac672abe8550b6dfd41fd537ccaa0db524c7
6
+ metadata.gz: 943de6924ab8d02a74fb49efab138a974bd6d510cb92aac6cf951058d04092a89860da0fbfb93a91c0cfb09bec992d6d66dc3f38906a4b2ee38d84fac293a50f
7
+ data.tar.gz: 1559d02c2ae020f8d8a291086145ed1ef5856940ff7ff02524de6d48639d62a186801778b955e80b17d60d0f038ca04ecc2400f2616a5c2867d97d82f289f84e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuberun (0.2.0)
4
+ kuberun (0.3.1)
5
5
  pastel (~> 0.8.0)
6
6
  thor (~> 1.2.1)
7
7
  tty-command (~> 0.10.1)
@@ -94,4 +94,4 @@ DEPENDENCIES
94
94
  rubocop (~> 0.58.0)
95
95
 
96
96
  BUNDLED WITH
97
- 2.3.20
97
+ 2.3.19
data/exe/kuberun CHANGED
@@ -3,8 +3,9 @@
3
3
 
4
4
  lib_path = File.expand_path('../lib', __dir__)
5
5
  $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
6
- require 'kuberun/cli'
7
6
  require 'kuberun'
7
+ require 'kuberun/cli'
8
+
8
9
 
9
10
  Signal.trap('INT') do
10
11
  warn("\n#{caller.join("\n")}: interrupted")
data/lib/kuberun/cli.rb CHANGED
@@ -9,19 +9,7 @@ module Kuberun
9
9
  # @api public
10
10
  class CLI < Thor
11
11
  DEFAULT_OPTIONS_FOR_KUBECTL_OPTIONS = { type: :string, default: '', desc: 'See kubectl options' }.freeze
12
- BASE_KUBECTL_OPTIONS = {
13
- 'certificate-authority': {},
14
- 'client-certificate': {},
15
- 'client-key': {},
16
- 'cluster': {},
17
- 'context': {},
18
- 'insecure-skip-tls-verify': {},
19
- 'kubeconfig': {},
20
- 'namespace': { aliases: :'-n' },
21
- 'token': {},
22
- 'v': { type: :numeric, default: 0, desc: 'Log level passed to kubectl' }
23
- }.freeze
24
- BASE_KUBECTL_OPTIONS.each do |option_name, hash|
12
+ ::Kubectl::OPTIONS.each do |option_name, hash|
25
13
  class_option option_name, DEFAULT_OPTIONS_FOR_KUBECTL_OPTIONS.merge(hash)
26
14
  end
27
15
  class_option :debug, type: :boolean, default: false, desc: 'Debug logging'
@@ -14,23 +14,31 @@ module Kuberun
14
14
  end
15
15
 
16
16
  def execute(input: $stdin, output: $stdout)
17
- output.puts(Kuberun::Pastel.yellow('Checking access to needed commands...'))
18
- Kuberun::Kubectl.auth_check('create', resource: 'pods')
19
- Kuberun::Kubectl.auth_check('exec', resource: 'pods')
20
- output.puts(Kuberun::Pastel.green('You have all permissions needed.'))
17
+ if @options['perform-auth-check']
18
+ output.print(Kuberun::Pastel.yellow('Checking access to needed commands'))
19
+ Kuberun::Kubectl.auth_check('create', resource: 'pods')
20
+ Kuberun::Kubectl.auth_check('exec', resource: 'pods')
21
21
 
22
- output.puts(Kuberun::Pastel.yellow('Searching for existing pods'))
22
+ output.puts
23
+ output.puts(Kuberun::Pastel.green('You have all permissions needed'))
24
+ end
25
+
26
+ output.print(Kuberun::Pastel.yellow('Searching for existing pods'))
23
27
  existing_pods = Kuberun::Kubectl.get(resource: 'pods', options: "-l kuberun-provisioned=true,kuberun-source=#{@deployment_name}")
24
28
  if existing_pods['items'].size > 0
25
- select = existing_pods['items'].map { |item| item.dig('metadata', 'name') }
26
- select << NEW_POD
29
+ if @options['use-first-pod']
30
+ @generated_pod_name = existing_pods['items'].first.dig('metadata', 'name')
31
+ else
32
+ select = existing_pods['items'].map { |item| item.dig('metadata', 'name') }
33
+ select << NEW_POD
27
34
 
28
- selection = prompt.select('I found some already running pods. Do you want to use one?', select)
35
+ selection = prompt.select('I found some already running pods. Do you want to use one?', select)
29
36
 
30
- if selection == NEW_POD
31
- create_pod_from_deployment(output)
32
- else
33
- @generated_pod_name = selection
37
+ if selection == NEW_POD
38
+ create_pod_from_deployment(output)
39
+ else
40
+ @generated_pod_name = selection
41
+ end
34
42
  end
35
43
  else
36
44
  create_pod_from_deployment(output)
@@ -38,12 +46,12 @@ module Kuberun
38
46
 
39
47
  execute_command(input, output)
40
48
 
41
- if prompt.yes?(Kuberun::Pastel.yellow('Should I delete pod?'))
49
+ if @options['cleanup-pod'] || prompt.yes?(Kuberun::Pastel.yellow('Should I delete pod?'))
42
50
  Kuberun::Kubectl.delete(resource: 'pod', resource_name: generated_pod_name)
43
51
  Kuberun::Pastel.green("Pod #{generated_pod_name} has been deleted!")
44
52
  end
45
53
 
46
- output.puts(Kuberun::Pastel.green('Done!'))
54
+ output.puts
47
55
  end
48
56
 
49
57
  private
@@ -59,6 +67,7 @@ module Kuberun
59
67
  pod.dig('status', 'phase') == 'Running'
60
68
  end
61
69
 
70
+ output.puts
62
71
  output.puts(Kuberun::Pastel.green('Pod is running!'))
63
72
  end
64
73
 
@@ -122,7 +131,7 @@ module Kuberun
122
131
  def execute_command(_input, output)
123
132
  output.puts(Kuberun::Pastel.green('Executing command'))
124
133
 
125
- Kuberun::Kubectl.exec(pod: generated_pod_name, command: '-it -- /bin/bash')
134
+ Kuberun::Kubectl.exec(generated_pod_name, @options)
126
135
 
127
136
  output.puts(Kuberun::Pastel.green('Kubectl exec exited'))
128
137
  end
@@ -14,11 +14,16 @@ class Kubectl
14
14
  @kubectl = kubectl
15
15
  end
16
16
 
17
- def exec(pod:, command:)
18
- old_state = `stty -g`
17
+ def exec(pod, options)
18
+ command = "#{kubectl_base_command('exec', resource: pod)} -it -- #{options['cluster-command']}"
19
19
 
20
- PTY.spawn("#{kubectl_base_command('exec', resource: pod)} #{command}") do |out, inp, pid|
21
- pty_process(out, inp, pid, old_state)
20
+ if options['pty']
21
+ old_state = `stty -g`
22
+ PTY.spawn(command) do |out, inp, pid|
23
+ pty_process(out, inp, pid, old_state)
24
+ end
25
+ else
26
+ system(command)
22
27
  end
23
28
  end
24
29
 
@@ -8,7 +8,27 @@ require 'kuberun/kubectl/exec'
8
8
  # Handles running kubectl
9
9
  class Kubectl
10
10
  CAT_MULTILINE = 'EOFCONFIG'
11
- KUBECTL_OPTIONS = Kuberun::CLI::BASE_KUBECTL_OPTIONS.keys.map(&:to_s)
11
+
12
+ KUBECTL_OPTIONS = {
13
+ 'certificate-authority': {},
14
+ 'client-certificate': {},
15
+ 'client-key': {},
16
+ 'cluster': {},
17
+ 'context': {},
18
+ 'insecure-skip-tls-verify': {},
19
+ 'kubeconfig': {},
20
+ 'namespace': { aliases: :'-n' },
21
+ 'token': {},
22
+ 'v': { type: :numeric, default: 0, desc: 'Log level passed to kubectl' },
23
+ }.freeze
24
+ SCRIPT_OPTIONS = {
25
+ 'cluster-command': { type: 'string', default: '/bin/bash', desc: 'Command to run on cluster' },
26
+ 'use-first-pod': { type: 'boolean', default: false, desc: 'Should first existing pod be used automatically?' },
27
+ 'cleanup-pod': { type: 'boolean', default: false, desc: 'Should pod be removed after finishing?' },
28
+ 'perform-auth-check': { type: 'boolean', default: true, desc: 'Should auth check be performed?' },
29
+ 'pty': { type: 'boolean', default: false, desc: 'Should PTY be used?' },
30
+ }.freeze
31
+ OPTIONS = KUBECTL_OPTIONS.merge(SCRIPT_OPTIONS).freeze
12
32
 
13
33
  def load_options(options)
14
34
  self.options = options
@@ -30,8 +50,8 @@ class Kubectl
30
50
  cmd.run(kubectl_base_input_command('create', configuration: configuration, options: options))
31
51
  end
32
52
 
33
- def exec(pod:, command:)
34
- Kubectl::Exec.new(self).exec(pod: pod, command: command)
53
+ def exec(pod, options = {})
54
+ Kubectl::Exec.new(self).exec(pod, options)
35
55
  end
36
56
 
37
57
  def delete(resource:, resource_name:)
@@ -63,7 +83,7 @@ class Kubectl
63
83
 
64
84
  def parsed_options(options)
65
85
  options.each_with_object([]) do |(option_name, option_value), arr|
66
- next if !KUBECTL_OPTIONS.include?(option_name) || option_value == ''
86
+ next if !KUBECTL_OPTIONS.keys.map(&:to_s).include?(option_name) || option_value == ''
67
87
 
68
88
  arr << "--#{option_name}=#{option_value}"
69
89
  end.join(' ')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kuberun
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuberun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kruczjak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-23 00:00:00.000000000 Z
11
+ date: 2022-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel