Class: Kubectl::Exec

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/kuberun/kubectl/exec.rb

Overview

Handles running kubectl exec

Instance Method Summary collapse

Constructor Details

#initialize(kubectl) ⇒ Exec

Returns a new instance of Exec.



13
14
15
# File 'lib/kuberun/kubectl/exec.rb', line 13

def initialize(kubectl)
  @kubectl = kubectl
end

Instance Method Details

#exec(pod, options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kuberun/kubectl/exec.rb', line 17

def exec(pod, options)
  command = "#{kubectl_base_command('exec', resource: pod)} -it -- #{options['cluster-command']}"

  if options['pty']
    old_state = `stty -g`
    PTY.spawn(command) do |out, inp, pid|
      pty_process(out, inp, pid, old_state)
    end
  else
    system(command)
  end
end