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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20feea954a12a81227f2ef8bff7f62697a159525
4
- data.tar.gz: 8cc529ef8186915511690c17c0b205ef95131bf3
3
+ metadata.gz: 305b1f24dc6713ce147f47eda09fe946a3123212
4
+ data.tar.gz: 5022d3ae52bb2c67c15b556ab5b2f34352da948f
5
5
  SHA512:
6
- metadata.gz: 4934b0b9d82315c32bfd67594f6c84caf1eda555c21f097dff57d1432576aac241fa8795d7df6b6868cf4e7c6b779bbeda6724dfc939b1bba2fc8e76a359e13d
7
- data.tar.gz: ae7355ddff207b2c07a2192ea29ac3c0d72d90aadfc2be9682906f6ba8dca9031644bbc70f8fdf6606e4f894e21bfeeed3c262efe113a7f9b581c0d38fee4778
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].join(' ')
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
- Command.new(info).logs
73
+ handle_interrupts do
74
+ Command.new(info).logs
75
+ end
68
76
  end
69
77
  end
70
78
 
@@ -7,29 +7,47 @@ module Podjumper
7
7
  end
8
8
 
9
9
  def exec(command)
10
- tty = TTY::Command.new
11
- tty.run(exec_command(command))
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 if !ping?(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
- def exec_command(command)
24
- "kubectl exec -ti #{@pod} -c #{@container} --namespace #{@namespace} -- #{command}"
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
- "kubectl logs #{@pod} #{@container} --namespace #{@namespace} -f --since=1s"
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
- return ping_matchers.any? { |regex| log_line =~ regex }
50
+ ping_matchers.any? { |regex| log_line =~ regex }
33
51
  end
34
52
 
35
53
  def ping_matchers
@@ -37,7 +37,7 @@ module Podjumper
37
37
  end
38
38
 
39
39
  def load_rails_from_subdomain(subdomain)
40
- pod = Pod.find_by_subdomain(subdomain)
40
+ pod = Pod.where(subdomain: subdomain).first
41
41
  new(pod.namespace, pod, pod.container('rails'))
42
42
  end
43
43
 
@@ -68,16 +68,20 @@ module Podjumper
68
68
  end
69
69
 
70
70
  class << Pod
71
- def where(namespace: nil, subdomain: nil)
72
- namespace_flag = namespace ? "-n '#{namespace}'" : '--all-namespaces'
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
- json['items'].map(&Pod.method(:new))
74
+ JSON.parse(output)
75
+ .fetch('items', [])
76
+ .map { |h| Pod.new(h) }
77
77
  end
78
78
 
79
- def find_by_subdomain(subdomain)
80
- new(JSON.parse(`kubectl get pods --output=json --all-namespaces --selector='subdomain=#{subdomain}'`)['items'].first)
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
@@ -1,3 +1,3 @@
1
1
  module Podjumper
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-02 00:00:00.000000000 Z
11
+ date: 2018-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler