kuberun 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/exe/kuberun +2 -1
- data/lib/kuberun/cli.rb +1 -13
- data/lib/kuberun/commands/run_pod.rb +19 -13
- data/lib/kuberun/kubectl/exec.rb +9 -4
- data/lib/kuberun/kubectl.rb +24 -4
- data/lib/kuberun/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c64caef5ffc4e1578751e44ca133f0f608d8f3a24ca93d0a864434e1cd0add
|
4
|
+
data.tar.gz: f404f4e23c941d0aa992f1d10ba4e6a3dd38fa1285210bb71f4acdff0bd4e484
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9abde70e3c0a339c4d5c3ad94c9b242c64f88a3b73c220736da21d025c6fd0a5ee287a8248dc5bcd4a68a33f47e55ba22fb85d815371c8ffdc267ea947243286
|
7
|
+
data.tar.gz: 434e29139e6da16f13202735c7fd647e2828dfb82bceebf12228f780588ea36479044fd37d43b1daa5418de3c82b13c3f153fefa18907abbc3486c2f29c14015
|
data/Gemfile.lock
CHANGED
data/exe/kuberun
CHANGED
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
|
-
|
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,29 @@ module Kuberun
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def execute(input: $stdin, output: $stdout)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
if @options['perform-auth-check']
|
18
|
+
output.puts(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
|
+
output.puts(Kuberun::Pastel.green('You have all permissions needed.'))
|
22
|
+
end
|
21
23
|
|
22
24
|
output.puts(Kuberun::Pastel.yellow('Searching for existing pods'))
|
23
25
|
existing_pods = Kuberun::Kubectl.get(resource: 'pods', options: "-l kuberun-provisioned=true,kuberun-source=#{@deployment_name}")
|
24
26
|
if existing_pods['items'].size > 0
|
25
|
-
|
26
|
-
|
27
|
+
if @options['use-first-pod']
|
28
|
+
@generated_pod_name = existing_pods['items'].first.dig('metadata', 'name')
|
29
|
+
else
|
30
|
+
select = existing_pods['items'].map { |item| item.dig('metadata', 'name') }
|
31
|
+
select << NEW_POD
|
27
32
|
|
28
|
-
|
33
|
+
selection = prompt.select('I found some already running pods. Do you want to use one?', select)
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
if selection == NEW_POD
|
36
|
+
create_pod_from_deployment(output)
|
37
|
+
else
|
38
|
+
@generated_pod_name = selection
|
39
|
+
end
|
34
40
|
end
|
35
41
|
else
|
36
42
|
create_pod_from_deployment(output)
|
@@ -38,7 +44,7 @@ module Kuberun
|
|
38
44
|
|
39
45
|
execute_command(input, output)
|
40
46
|
|
41
|
-
|
47
|
+
if @options['cleanup-pod'] || prompt.yes?(Kuberun::Pastel.yellow('Should I delete pod?'))
|
42
48
|
Kuberun::Kubectl.delete(resource: 'pod', resource_name: generated_pod_name)
|
43
49
|
Kuberun::Pastel.green("Pod #{generated_pod_name} has been deleted!")
|
44
50
|
end
|
@@ -122,7 +128,7 @@ module Kuberun
|
|
122
128
|
def execute_command(_input, output)
|
123
129
|
output.puts(Kuberun::Pastel.green('Executing command'))
|
124
130
|
|
125
|
-
Kuberun::Kubectl.exec(
|
131
|
+
Kuberun::Kubectl.exec(generated_pod_name, @options)
|
126
132
|
|
127
133
|
output.puts(Kuberun::Pastel.green('Kubectl exec exited'))
|
128
134
|
end
|
data/lib/kuberun/kubectl/exec.rb
CHANGED
@@ -14,11 +14,16 @@ class Kubectl
|
|
14
14
|
@kubectl = kubectl
|
15
15
|
end
|
16
16
|
|
17
|
-
def exec(pod
|
18
|
-
|
17
|
+
def exec(pod, options)
|
18
|
+
command = "#{kubectl_base_command('exec', resource: pod)} -it -- #{options['cluster-command']}"
|
19
19
|
|
20
|
-
|
21
|
-
|
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
|
|
data/lib/kuberun/kubectl.rb
CHANGED
@@ -8,7 +8,27 @@ require 'kuberun/kubectl/exec'
|
|
8
8
|
# Handles running kubectl
|
9
9
|
class Kubectl
|
10
10
|
CAT_MULTILINE = 'EOFCONFIG'
|
11
|
-
|
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: true, 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
|
34
|
-
Kubectl::Exec.new(self).exec(pod
|
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(' ')
|
data/lib/kuberun/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kruczjak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|