Class: Kitchen::Transport::Kubernetes::Connection

Inherits:
Base::Connection
  • Object
show all
Includes:
KitchenKubernetes::Helper, ShellOut
Defined in:
lib/kitchen/transport/kubernetes.rb

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Methods included from KitchenKubernetes::Helper

#kube_options, #kubectl_command

Instance Method Details

#execute(command) ⇒ Object

Since:

  • 1.0.0



57
58
59
60
61
# File 'lib/kitchen/transport/kubernetes.rb', line 57

def execute(command)
  return if command.nil?
  # Run via kubectl exec.
  run_command(kubectl_command('exec', '--tty', '--container=default', options[:pod_id], '--', *Shellwords.split(command)))
end

#login_commandObject

Since:

  • 1.0.0



71
72
73
74
75
76
77
78
79
80
# File 'lib/kitchen/transport/kubernetes.rb', line 71

def 
  # Find a valid login shell and exec it. This is so weridly complex
  # because it has to work with a /bin/sh that might be bash, dash, or
  # busybox. Also CentOS images doesn't have `which` for some reason.
  # Dash's `type` is super weird so use `which` first in case of dash but
  # fall back to `type` for basically just CentOS.
   = "IFS=$'\n'; for f in `which bash zsh sh 2>/dev/null || type -P bash zsh sh`; do exec \"$f\" -l; done"
  cmd = kubectl_command('exec', '--stdin', '--tty', '--container=default', options[:pod_id], '--', '/bin/sh', '-c', )
  LoginCommand.new(cmd[0], cmd.drop(1))
end

#upload(locals, remote) ⇒ Object

Since:

  • 1.0.0



64
65
66
67
68
# File 'lib/kitchen/transport/kubernetes.rb', line 64

def upload(locals, remote)
  return if locals.empty?
  # Use rsync over kubectl exec to send files.
  run_command([options[:rsync_command], '--archive', '--progress', '--blocking-io', '--rsh', options[:rsync_rsh]] + (options[:log_level] == :debug ? %w{--verbose --verbose --verbose} : []) + locals + ["#{options[:pod_id]}:#{remote}"])
end