kuberun 0.2.1 → 0.3.1
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 +2 -2
- data/exe/kuberun +2 -1
- data/lib/kuberun/cli.rb +1 -13
- data/lib/kuberun/commands/run_pod.rb +24 -15
- 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: 9866a7b293e3bf832f66ee91b61ce7054c0d0dd91219343dae1eee009f87d9f5
|
4
|
+
data.tar.gz: 4bb59f1eebabb62e001541b834c35ba35336da052e3d068f18dd020c7258b618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 943de6924ab8d02a74fb49efab138a974bd6d510cb92aac6cf951058d04092a89860da0fbfb93a91c0cfb09bec992d6d66dc3f38906a4b2ee38d84fac293a50f
|
7
|
+
data.tar.gz: 1559d02c2ae020f8d8a291086145ed1ef5856940ff7ff02524de6d48639d62a186801778b955e80b17d60d0f038ca04ecc2400f2616a5c2867d97d82f289f84e
|
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,31 @@ 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.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
|
-
|
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
|
-
|
26
|
-
|
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
|
-
|
35
|
+
selection = prompt.select('I found some already running pods. Do you want to use one?', select)
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
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(
|
134
|
+
Kuberun::Kubectl.exec(generated_pod_name, @options)
|
126
135
|
|
127
136
|
output.puts(Kuberun::Pastel.green('Kubectl exec exited'))
|
128
137
|
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: 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
|
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.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-
|
11
|
+
date: 2022-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|