Class: KubeclientExec::Execute::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/kubeclient_exec/execute/executor.rb

Constant Summary collapse

EXEC_STDIN =
0
EXEC_STDOUT =
1
EXEC_STDERR =
2
EXEC_DCKERR =

Seems like this is used for docker errors

3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, url, kubeclient_options, options, &block) ⇒ Executor

Returns a new instance of Executor.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kubeclient_exec/execute/executor.rb', line 15

def initialize(command, url, kubeclient_options, options, &block)
  @last_command = command
  @url = url
  @kubeclient_options = kubeclient_options
  @options = options
  @on_open = block
  @suppress_errors = options[:suppress_errors]

  if options[:mode] == :adhoc
    @on_stdout = ->(_) { stop }
    @on_stderr = ->(_) { stop }
  end

  setup
end

Instance Attribute Details

#last_commandObject (readonly)

Returns the value of attribute last_command.



13
14
15
# File 'lib/kubeclient_exec/execute/executor.rb', line 13

def last_command
  @last_command
end

#last_stderrObject (readonly)

Returns the value of attribute last_stderr.



13
14
15
# File 'lib/kubeclient_exec/execute/executor.rb', line 13

def last_stderr
  @last_stderr
end

#last_stdoutObject (readonly)

Returns the value of attribute last_stdout.



13
14
15
# File 'lib/kubeclient_exec/execute/executor.rb', line 13

def last_stdout
  @last_stdout
end

Instance Method Details

#done?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/kubeclient_exec/execute/executor.rb', line 67

def done?
  @ws.instance_variable_get(:@driver).instance_variable_get(:@queue).empty?
end

#execute(command) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/kubeclient_exec/execute/executor.rb', line 31

def execute(command)
  raise 'ws not initialized' unless @ws

  @last_command = command

  @ws.send((command + "\n").unpack("C*").unshift(EXEC_STDIN))
end

#on_close(&block) ⇒ Object



53
54
55
# File 'lib/kubeclient_exec/execute/executor.rb', line 53

def on_close(&block)
  @on_close = block
end

#on_stderr(&block) ⇒ Object



49
50
51
# File 'lib/kubeclient_exec/execute/executor.rb', line 49

def on_stderr(&block)
  @on_stderr = block
end

#on_stdout(&block) ⇒ Object



45
46
47
# File 'lib/kubeclient_exec/execute/executor.rb', line 45

def on_stdout(&block)
  @on_stdout = block
end

#ready_stateObject



71
72
73
# File 'lib/kubeclient_exec/execute/executor.rb', line 71

def ready_state
  @ws.ready_state
end

#stopObject



57
58
59
60
# File 'lib/kubeclient_exec/execute/executor.rb', line 57

def stop
  @ws.instance_variable_get(:@stream).close_connection_after_writing
  @on_close.call if @on_close
end

#stop!Object



62
63
64
65
# File 'lib/kubeclient_exec/execute/executor.rb', line 62

def stop!
  stop
  EM.stop_event_loop
end

#write(content) ⇒ Object



39
40
41
42
43
# File 'lib/kubeclient_exec/execute/executor.rb', line 39

def write(content)
  raise 'ws not initialized' unless @ws

  @ws.send(content.unpack("C*").unshift(EXEC_STDIN))
end