podjumper 0.1.1 → 0.1.2
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/bin/podj +10 -2
- data/lib/podjumper/command.rb +26 -8
- data/lib/podjumper/jump_info.rb +1 -1
- data/lib/podjumper/pod.rb +11 -7
- data/lib/podjumper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 305b1f24dc6713ce147f47eda09fe946a3123212
|
4
|
+
data.tar.gz: 5022d3ae52bb2c67c15b556ab5b2f34352da948f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd31a2ca2f2f15b30445eec0d1b97e546968a7822c1f7ffd4c26d09eb3cf307fdf0b30951aadb30c04d92ec125247dfcf9c498883ee8c9e146e6229422183631
|
7
|
+
data.tar.gz: 795b80482e478e318cece638dd6fa004ec9a1d683239b402ca7c2a71519f0936d38de7415a95c2377abf2368b7275450b16f97358dd79f822ae935ad7bb8998b
|
data/bin/podj
CHANGED
@@ -9,6 +9,12 @@ include GLI::App
|
|
9
9
|
|
10
10
|
using Refinements
|
11
11
|
|
12
|
+
def handle_interrupts
|
13
|
+
yield
|
14
|
+
rescue Interrupt
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
12
18
|
version Podjumper::VERSION
|
13
19
|
|
14
20
|
desc 'Navigate to a container by picking through namespaces and subdomains.'
|
@@ -53,7 +59,7 @@ desc 'Shorthand command runs given command on nearest pod with subdomain label'
|
|
53
59
|
command [:exec] do |j|
|
54
60
|
j.action do |_, _, args|
|
55
61
|
subdomain = args[0]
|
56
|
-
command = args[1...args.length]
|
62
|
+
command = args[1...args.length]
|
57
63
|
info = JumpInfo.load_rails_from_subdomain(subdomain)
|
58
64
|
Command.new(info).exec(command)
|
59
65
|
end
|
@@ -64,7 +70,9 @@ command [:logs] do |l|
|
|
64
70
|
l.action do |_, _, args|
|
65
71
|
subdomain = args[0]
|
66
72
|
info = JumpInfo.load_rails_from_subdomain(subdomain)
|
67
|
-
|
73
|
+
handle_interrupts do
|
74
|
+
Command.new(info).logs
|
75
|
+
end
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
data/lib/podjumper/command.rb
CHANGED
@@ -7,29 +7,47 @@ module Podjumper
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def exec(command)
|
10
|
-
|
11
|
-
|
10
|
+
IO.popen(exec_command + command, in: :in) do |io|
|
11
|
+
io.each_char(&method(:print))
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
15
|
def logs
|
15
16
|
tty = TTY::Command.new(printer: :null)
|
16
|
-
tty.run(logs_command) do |out, _|
|
17
|
-
puts out
|
17
|
+
tty.run(*logs_command) do |out, _|
|
18
|
+
puts out unless ping?(out)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
attr_reader :namespace, :pod, :container
|
25
|
+
|
26
|
+
def exec_command
|
27
|
+
[
|
28
|
+
'kubectl',
|
29
|
+
'exec',
|
30
|
+
'-ti', pod,
|
31
|
+
'-c', container,
|
32
|
+
'--namespace', namespace,
|
33
|
+
'--'
|
34
|
+
]
|
25
35
|
end
|
26
36
|
|
27
37
|
def logs_command
|
28
|
-
|
38
|
+
[
|
39
|
+
'kubectl',
|
40
|
+
'logs',
|
41
|
+
pod,
|
42
|
+
container,
|
43
|
+
'--namespace', namespace,
|
44
|
+
'-f',
|
45
|
+
'--since=1s'
|
46
|
+
]
|
29
47
|
end
|
30
48
|
|
31
49
|
def ping?(log_line)
|
32
|
-
|
50
|
+
ping_matchers.any? { |regex| log_line =~ regex }
|
33
51
|
end
|
34
52
|
|
35
53
|
def ping_matchers
|
data/lib/podjumper/jump_info.rb
CHANGED
data/lib/podjumper/pod.rb
CHANGED
@@ -68,16 +68,20 @@ module Podjumper
|
|
68
68
|
end
|
69
69
|
|
70
70
|
class << Pod
|
71
|
-
def where(
|
72
|
-
|
73
|
-
subdomain_flag = subdomain ? "-l 'subdomain=#{subdomain}'" : ''
|
74
|
-
json = JSON.parse(`kubectl get pods --output=json #{namespace_flag} #{subdomain_flag}`)
|
71
|
+
def where(**opts)
|
72
|
+
output = TTY::Command.new(printer: :null).run(*_get_pods(opts)).out
|
75
73
|
|
76
|
-
|
74
|
+
JSON.parse(output)
|
75
|
+
.fetch('items', [])
|
76
|
+
.map { |h| Pod.new(h) }
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
80
|
-
|
79
|
+
def _get_pods(namespace: nil, subdomain: nil)
|
80
|
+
ns_flag = namespace ? "--namespace=#{namespace}" : '--all-namespaces'
|
81
|
+
sd_flag = subdomain ? "--selector=subdomain=#{subdomain}" : nil
|
82
|
+
%w[kubectl get pods --output=json]
|
83
|
+
.push(ns_flag, sd_flag)
|
84
|
+
.compact
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
data/lib/podjumper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: podjumper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- johndavidmartinez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|