class Podjumper::Command

Attributes

container[R]
namespace[R]
pod[R]

Public Class Methods

new(info) click to toggle source
# File lib/podjumper/command.rb, line 3
def initialize(info)
  @namespace = info.namespace
  @pod       = info.pod_name
  @container = info.container_name
end

Public Instance Methods

exec(command) click to toggle source
# File lib/podjumper/command.rb, line 9
def exec(command)
  IO.popen(exec_command + command, in: :in) do |io|
    io.each_char(&method(:print))
  end
end
logs() click to toggle source
# File lib/podjumper/command.rb, line 15
def logs
  tty = TTY::Command.new(printer: :null)
  tty.run(*logs_command) do |out, _|
    puts out unless ping?(out)
  end
end

Private Instance Methods

exec_command() click to toggle source
# File lib/podjumper/command.rb, line 26
def exec_command
  [
    'kubectl',
    'exec',
    '-ti', pod,
    '-c', container,
    '--namespace', namespace,
    '--'
  ]
end
logs_command() click to toggle source
# File lib/podjumper/command.rb, line 37
def logs_command
  [
    'kubectl',
    'logs',
    pod,
    container,
    '--namespace', namespace,
    '-f',
    '--since=1s'
  ]
end
ping?(log_line) click to toggle source
# File lib/podjumper/command.rb, line 49
def ping?(log_line)
  ping_matchers.any? { |regex| log_line =~ regex }
end
ping_matchers() click to toggle source
# File lib/podjumper/command.rb, line 53
def ping_matchers
  [/api\/ping/, /Api::SystemController#ping/, /Completed 200 OK/]
end