Class: Beaker::Gke
- Inherits:
-
Hypervisor
- Object
- Hypervisor
- Beaker::Gke
- Defined in:
- lib/beaker/hypervisor/gke.rb
Constant Summary collapse
- SERVICE_NAMESPACE =
'gke-puppetagent-ci'- PROXY_IP =
'10.236.0.3'- PROXY_PORT =
8899- MAX_RETRIES =
5
Instance Method Summary collapse
- #cleanup ⇒ Object
- #connection_preference(_host) ⇒ Object
- #create_pod(name) ⇒ Object
- #create_srv(name) ⇒ Object
- #delete_pod(pod_name) ⇒ Object
- #delete_service(srv_name) ⇒ Object
- #get_pod(name) ⇒ Object
- #initialize(hosts, options) ⇒ Gke constructor
- #provision ⇒ Object
Constructor Details
#initialize(hosts, options) ⇒ Gke
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/beaker/hypervisor/gke.rb', line 18 def initialize(hosts, ) begin ENV.fetch('KUBECONFIG') ENV.fetch('GOOGLE_APPLICATION_CREDENTIALS') rescue KeyError raise( ArgumentError, 'OS environment variable KUBECONFIG and GOOGLE_APPLICATION_CREDENTIALS must be set' ) end @hosts = hosts = @client = client @logger = [:logger] end |
Instance Method Details
#cleanup ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/beaker/hypervisor/gke.rb', line 62 def cleanup @hosts.each do |host| @logger.info("Deleting POD with ID: #{host[:hostname]}") delete_pod(host[:hostname]) delete_service(host[:hostname]) end end |
#connection_preference(_host) ⇒ Object
71 72 73 |
# File 'lib/beaker/hypervisor/gke.rb', line 71 def connection_preference(_host) i[ip vmhostname hostname] end |
#create_pod(name) ⇒ Object
75 76 77 78 |
# File 'lib/beaker/hypervisor/gke.rb', line 75 def create_pod(name) pod_config = read_symbols('pod.yaml', pod_name: name) @client.create_pod(pod_config) end |
#create_srv(name) ⇒ Object
84 85 86 87 |
# File 'lib/beaker/hypervisor/gke.rb', line 84 def create_srv(name) service_config = read_symbols('service.yaml', pod_name: name) @client.create_service(service_config) end |
#delete_pod(pod_name) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/beaker/hypervisor/gke.rb', line 89 def delete_pod(pod_name) @client.delete_pod( pod_name, SERVICE_NAMESPACE, delete_options: { 'force': 1, '--grace-period': 0 } ) end |
#delete_service(srv_name) ⇒ Object
97 98 99 100 101 |
# File 'lib/beaker/hypervisor/gke.rb', line 97 def delete_service(srv_name) @client.delete_service(srv_name, SERVICE_NAMESPACE) rescue Kubeclient::ResourceNotFoundError => e @logger.info("Service #{srv_name} could not be deleted #{e}") end |
#get_pod(name) ⇒ Object
80 81 82 |
# File 'lib/beaker/hypervisor/gke.rb', line 80 def get_pod(name) @client.get_pod(name, SERVICE_NAMESPACE) end |
#provision ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/beaker/hypervisor/gke.rb', line 34 def provision @hosts.each do |host| hostname = generate_host_name create_pod(hostname) create_srv(hostname) retries = 0 begin pod = get_pod(hostname) raise StandardError unless pod.status.podIP rescue StandardError => e raise "Timeout: #{e.message}" unless retries <= MAX_RETRIES @logger.info("Retrying, could not get podIP for #{hostname}") retries += 1 sleep(2**retries) retry end host[:vmhostname] = "#{hostname}.gke-puppetagent-ci.puppet.net" host[:hostname] = hostname host[:ip] = pod.status.podIP host[:gke_container] = true end nil end |