Class: Kitchen::Driver::K8s

Inherits:
Base
  • Object
show all
Includes:
KitchenK8s::Helper, ShellOut
Defined in:
lib/kitchen/driver/k8s.rb

Overview

Driver for Kitchen

Author:

Instance Method Summary collapse

Methods included from KitchenK8s::Helper

#kube_options, #kubectl_command

Instance Method Details

#create(state) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/kitchen/driver/k8s.rb', line 61

def create(state)
  return if state[:pod_id]
  pod_id = config[:pod_name].downcase
  state[:pod_id] = pod_id
  state[:namespace] = config[:namespace]
  client = kubectl_client
  # Render pod
  pod = render_pod_info(pod_id)
  debug("Creating pod with YAML:\n#{pod}\n")
  client.create_pod(render_pod_info(pod_id))
  # Wait until pod is running
  status = nil
  start_time = Time.now
  while status != 'Running'
    if Time.now - start_time > 20
      info("Waiting for pod #{pod_id} to be running, currently #{status}")
    end
    sleep(1)
    status = client.get_pod(pod_id, config[:namespace]).status.phase
  end
  platform_dependencies.each do |cmd|
    run_command(kubectl_command('exec', '--tty', '--container=default', pod_id, '--', *Shellwords.split(cmd)))
  end
  if config[:provision_command]
    config[:provision_command].each do |cmd|
      run_command(kubectl_command('exec', '--tty', '--container=default', pod_id, '--', *Shellwords.split(cmd)))
    end
  end
  state[:pod_id] = pod_id
end

#default_platformObject



49
50
51
# File 'lib/kitchen/driver/k8s.rb', line 49

def default_platform
  instance.platform.name.split('-').first
end

#destroy(state) ⇒ Object



93
94
95
96
97
# File 'lib/kitchen/driver/k8s.rb', line 93

def destroy(state)
  return unless state[:pod_id]
  client = kubectl_client
  client.delete_pod(state[:pod_id], config[:namespace])
end

#finalize_config!(instance) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
57
58
# File 'lib/kitchen/driver/k8s.rb', line 54

def finalize_config!(instance)
  super.tap do
    instance.transport = Kitchen::Transport::K8s.new(config)
  end
end