Class: TrainPlugins::TrainKubernetes::KubectlClient

Inherits:
Object
  • Object
show all
Defined in:
lib/train-kubernetes-docs/kubectl_client.rb

Constant Summary collapse

DEFAULT_NAMESPACE =
'default'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pod:, namespace: nil, container: nil) ⇒ KubectlClient

Returns a new instance of KubectlClient.



11
12
13
14
15
# File 'lib/train-kubernetes-docs/kubectl_client.rb', line 11

def initialize(pod:, namespace: nil, container: nil)
  @pod = pod
  @container = container
  @namespace = namespace || DEFAULT_NAMESPACE
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



7
8
9
# File 'lib/train-kubernetes-docs/kubectl_client.rb', line 7

def container
  @container
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



7
8
9
# File 'lib/train-kubernetes-docs/kubectl_client.rb', line 7

def namespace
  @namespace
end

#podObject (readonly)

Returns the value of attribute pod.



7
8
9
# File 'lib/train-kubernetes-docs/kubectl_client.rb', line 7

def pod
  @pod
end

Instance Method Details

#execute(command, stdin: true, tty: true) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/train-kubernetes-docs/kubectl_client.rb', line 17

def execute(command, stdin: true, tty: true)
  instruction = build_instruction(command, stdin, tty)
  shell = Mixlib::ShellOut.new(instruction)
  res = shell.run_command
  Train::Extras::CommandResult.new(res.stdout, res.stderr, res.exitstatus)
rescue Errno::ENOENT => _e
  Train::Extras::CommandResult.new('', '', 1)
end