Class: Train::Transports::KubernetesHack::Connection
- Inherits:
-
BaseConnection
- Object
- BaseConnection
- Train::Transports::KubernetesHack::Connection
- Defined in:
- lib/kitchen/verifier/train_kubernetes_hack.rb
Instance Method Summary collapse
- #file(path) ⇒ Object
- #file_via_connection(path) ⇒ Object
-
#os ⇒ Object
The API for a connection changed a lot in 0.30, this is a compat shim.
- #run_command(cmd) ⇒ Object
- #run_command_via_connection(cmd) ⇒ Object
- #uri ⇒ Object
Instance Method Details
#file(path) ⇒ Object
52 53 54 |
# File 'lib/kitchen/verifier/train_kubernetes_hack.rb', line 52 def file(path) @files[path] ||= file_via_connection(path) end |
#file_via_connection(path) ⇒ Object
61 62 63 |
# File 'lib/kitchen/verifier/train_kubernetes_hack.rb', line 61 def file_via_connection(path) defined?(Train::File::Remote::Linux) ? Train::File::Remote::Linux.new(self, path) : LinuxFile.new(self, path) end |
#os ⇒ Object
The API for a connection changed a lot in 0.30, this is a compat shim.
48 49 50 |
# File 'lib/kitchen/verifier/train_kubernetes_hack.rb', line 48 def os @os ||= OSCommon.new(self, family: 'unix') end |
#run_command(cmd) ⇒ Object
56 57 58 |
# File 'lib/kitchen/verifier/train_kubernetes_hack.rb', line 56 def run_command(cmd) run_command_via_connection(cmd) end |
#run_command_via_connection(cmd) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kitchen/verifier/train_kubernetes_hack.rb', line 65 def run_command_via_connection(cmd) kubectl_cmd = [[:kubectl_path], 'exec'] kubectl_cmd.concat(['--context', [:context]]) if [:context] kubectl_cmd.concat(['--container', [:container]]) if [:container] kubectl_cmd.concat([[:pod], '--', '/bin/sh', '-c', cmd]) so = Mixlib::ShellOut.new(kubectl_cmd, logger: logger) so.run_command if so.error? # Trim the "command terminated with exit code N" line from the end # of the stderr content. so.stderr.gsub!(/command terminated with exit code #{so.exitstatus}\n\Z/, '') end CommandResult.new(so.stdout, so.stderr, so.exitstatus) end |
#uri ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/kitchen/verifier/train_kubernetes_hack.rb', line 81 def uri if [:container] "kubernetes://#{[:pod]}/#{[:container]}" else "kubernetes://#{[:pod]}" end end |