deis-interactive 0.0.3 → 0.0.4

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: 1650e0c2a5a4cedc3f0b96b5295ddbca67abded1
4
- data.tar.gz: ab4b1fcc90cba3860fe71d21e7f21d0bd494aec4
3
+ metadata.gz: a5f83196b1200c69ff190f99918194896970ef25
4
+ data.tar.gz: c94a10bb6aec193ad8c570875910a37b67081044
5
5
  SHA512:
6
- metadata.gz: 315d3534f8b14bad83b5fdbb3c80cbcefe0d431de7e135859e7817810ec5ff3975f1358ebd273495d862577d79bf0fec1eb55dd83f9741a302bfbc0630cf7d31
7
- data.tar.gz: d30d620da15a99839d869dcb95ae58f5a1f3aa3423d84e1d87e8fe99a8f2279555f6d9ba6debf813e3388f92fdef122ba7a4f64df6cf71cdefee73a36b5fba01
6
+ metadata.gz: 1700bd2ce706c77a0d350950ffb3bbf7733cb6b45ce5054400a2ad841405b2bec8be19c1ce9ac55e19d645f811dbe4b96b961af5502443acf6fd4f6486071b3b
7
+ data.tar.gz: 4a93b6c21f8ebeb4011ac7210e0289e0dc57eef782b3e89799e611e7a75e912d7e59897887ba67e506286c8885337bf93ecdada21663a65f863c38aeb3eadfc3
data/bin/deis-rails CHANGED
@@ -11,7 +11,7 @@ class DeisRails < Thor
11
11
  DeisInteractive::Rails::Console.new(app).perform
12
12
  end
13
13
 
14
- desc "exec -a APP COMMAND PARAMS", "run console on an app"
14
+ desc "exec -a APP COMMAND PARAMS", "run any command on an app"
15
15
  method_option :app, aliases: ["a"], type: :string, required: true, desc: "Name of the app"
16
16
  def exec(command, *params)
17
17
  require_relative "../lib/deis-interactive/rails/exec"
@@ -21,7 +21,6 @@ class DeisRails < Thor
21
21
  DeisInteractive::Rails::Exec.new(app, command, params).perform
22
22
  end
23
23
 
24
-
25
24
  desc "logs [-f] -a APP [-d PROCESS]", "logs on an app"
26
25
  method_option :app, aliases: ["a"], type: :string, required: true, desc: "Name of the app"
27
26
  method_option :process, aliases: ["p"], type: :string, required: false, desc: "Processes to be logged on"
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "thor"
23
+ spec.add_development_dependency "concurrent-ruby"
23
24
  end
@@ -1,14 +1,26 @@
1
1
  require_relative 'base'
2
2
  require "shellwords"
3
+ require 'concurrent'
4
+ require 'open3'
3
5
 
4
6
  module DeisInteractive
5
7
  module Rails
6
8
  class Logs < Base
7
9
  attr_reader :follow
10
+ attr_reader :pids
11
+ attr_reader :outputs
8
12
 
9
13
  def initialize(app, process, follow: false)
10
14
  super(app, process)
11
15
  @follow = follow
16
+ @pids = Concurrent::Array.new
17
+ @outputs = Concurrent::Array.new
18
+
19
+ at_exit do
20
+ pids.each do |pid|
21
+ Process.kill("KILL", pid) if pid_alive?(pid)
22
+ end
23
+ end
12
24
  end
13
25
 
14
26
  def perform
@@ -21,6 +33,25 @@ module DeisInteractive
21
33
  log_pods
22
34
  end
23
35
 
36
+ def pid_alive?(pid)
37
+ begin
38
+ Process.getpgid( pid )
39
+ true
40
+ rescue Errno::ESRCH
41
+ false
42
+ end
43
+ end
44
+
45
+ def any_pid_alive?
46
+ 20.times {
47
+ break if pids.count > 0
48
+ sleep 0.1
49
+ }
50
+
51
+ return false if pids.count == 0
52
+ pids.any? { |pid| pid_alive?(pid) }
53
+ end
54
+
24
55
  def kube_options
25
56
  if follow
26
57
  "-f"
@@ -31,11 +62,27 @@ module DeisInteractive
31
62
  pod_ids.each do |pod_id|
32
63
  log_pod(pod_id)
33
64
  end
65
+
66
+ loop do
67
+ while (outputs.count > 0)
68
+ puts outputs.shift
69
+ end
70
+ if any_pid_alive?
71
+ sleep 0.01
72
+ else
73
+ break
74
+ end
75
+ end
34
76
  end
35
77
 
36
78
  def log_pod(pod_id)
37
- fork do
38
- exec "kubectl logs #{kube_options} #{pod_id} --namespace #{app}"
79
+ Thread.new do
80
+ cmd = "kubectl logs #{kube_options} #{pod_id} --namespace #{app}"
81
+ Open3.popen2e(cmd) do |_, out_err, wait_thr|
82
+ puts "Tracking #{wait_thr.pid}"
83
+ pids << wait_thr.pid
84
+ out_err.each { |line| outputs << line }
85
+ end
39
86
  end
40
87
  end
41
88
  end
@@ -1,3 +1,3 @@
1
1
  module DeisInteractive
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deis-interactive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phuong Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-10 00:00:00.000000000 Z
11
+ date: 2018-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: concurrent-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Wrapper for kubectl to quickly launch console to a deis app
42
56
  email:
43
57
  - phuongnd08@gmail.com