beaker-gke 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 4867a7f5a9b76a9a07fad205175c626ad5ffc25a186fdade9d08ebf82eeb87de
4
- data.tar.gz: 6d51919cb4ae4984fa182d734520af144d50232d302a45bc988ca0aa43a8fcaa
2
+ SHA1:
3
+ metadata.gz: 009e87947781520d425d4ba4e3578cd563a86839
4
+ data.tar.gz: 2754f9512a7dba47bb2330b12d4a3b215fdadd91
5
5
  SHA512:
6
- metadata.gz: 71b29c3e55c85fb5bb3910dcf0ce6d8051225ea50044063075e625b2883a252e57baf5414ec0f8dbb1ba307169b96d49781af677394be6f3004f0400a1bee1a6
7
- data.tar.gz: ab01abfd573b934508440a8d9e01a77b6946ccc75f05bbfff3436346cff24dc419ac857ddd15da2da12bbcbe8b5577ebc85ec1a3510969ab7ddca3b71d2ef772
6
+ metadata.gz: b8088bc44df805f9cf03895b178d761869f7dbe7d79e7f216d8f66dfd2fe9041687405a6698cb273d49a421d09b0292f4288af703dae8192608a8fb4e6dd4380
7
+ data.tar.gz: ff708f8ef2966f8254c054fe4449f7fc1461d6ab487e41cbcd2eef5bf345b580a413447ef39abe1c973e5cd2a0f8528b291d1438586e2d0bf5cc436af894a008
@@ -0,0 +1,14 @@
1
+ ---
2
+ require:
3
+ - rubocop-rspec
4
+ - rubocop-performance
5
+ AllCops:
6
+ TargetRubyVersion: 2.4
7
+ Documentation:
8
+ Enabled: false
9
+ Metrics/MethodLength:
10
+ Enabled: 20
11
+ Style/Documentation:
12
+ Enabled: false
13
+ Metrics/LineLength:
14
+ Max: 120
@@ -1,43 +1,25 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
4
+
3
5
  require 'beaker-gke/version'
4
6
 
5
7
  Gem::Specification.new do |s|
6
- s.name = "beaker-gke"
8
+ s.name = 'beaker-gke'
7
9
  s.version = BeakerGke::VERSION
8
10
  s.authors = ["Night's Watch"]
9
- s.email = ["team-nw@puppet.com"]
10
- s.homepage = "https://github.com/puppetlabs/beaker-gke"
11
- s.summary = %q{Beaker hypervisor for GKE!}
12
- s.description = %q{For use for the Beaker acceptance testing tool}
13
- s.license = 'Apache2'
11
+ s.email = ['team-nw@puppet.com']
12
+ s.homepage = 'https://github.com/puppetlabs/beaker-gke'
13
+ s.summary = 'Beaker hypervisor for GKE!'
14
+ s.description = 'Add GKE support to Beaker acceptance testing tool'
15
+ s.license = 'Apache-2.0'
14
16
 
15
17
  s.files = `git ls-files`.split("\n")
16
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
19
-
20
- # Testing dependencies
21
- s.add_development_dependency 'rspec', '~> 3.0'
22
- s.add_development_dependency 'rspec-its'
23
- # pin fakefs for Ruby < 2.3
24
- if RUBY_VERSION < "2.3"
25
- s.add_development_dependency 'fakefs', '~> 0.6', '< 0.14'
26
- else
27
- s.add_development_dependency 'fakefs', '~> 0.6'
28
- end
29
- s.add_development_dependency 'rake', '~> 10.1'
30
- s.add_development_dependency 'simplecov'
31
- s.add_development_dependency 'pry', '~> 0.10'
32
-
33
- # Documentation dependencies
34
- s.add_development_dependency 'yard'
35
- s.add_development_dependency 'markdown'
36
- s.add_development_dependency 'thin'
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |file| File.basename(file) }
20
+ s.require_paths = ['lib']
37
21
 
38
22
  # Run time dependencies
23
+ s.add_runtime_dependency 'googleauth', '~> 0.9'
39
24
  s.add_runtime_dependency 'kubeclient', '~> 4.4.0'
40
- s.add_runtime_dependency 'jsonpath'
41
- s.add_runtime_dependency 'googleauth'
42
-
43
- end
25
+ end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rubygems' unless defined?(Gem)
4
5
  require 'beaker-gke'
@@ -1,23 +1,38 @@
1
- apiVersion: v1
2
- kind: Pod
3
- metadata:
4
- name: "%{pod_name}"
5
- namespace: gke-puppetagent-ci
6
- labels:
7
- app: "%{pod_name}"
8
- spec:
9
- hostname: "%{pod_name}"
10
- containers:
11
- - image: gcr.io/puppetagent-ci/centos-7:v5
12
- name: "centos-7"
13
- dnsPolicy: "None"
14
- dnsConfig:
1
+ ---
2
+ :apiVersion: v1
3
+ :kind: Pod
4
+ :metadata:
5
+ :name: "%{pod_name}"
6
+ :namespace: gke-puppetagent-ci
7
+ :labels:
8
+ :app: "%{pod_name}"
9
+ :project: puppet-agent-ci
10
+ :spec:
11
+ :hostname: "%{pod_name}"
12
+ :containers:
13
+ - :image: <%= ENV.fetch("CONTAINER_IMAGE") { "gcr.io/puppetagent-ci/centos-7-master:v4" } %>
14
+ :name: "centos-7-master"
15
+ :securityContext:
16
+ :capabilities:
17
+ :add:
18
+ - NET_ADMIN
19
+ :dnsPolicy: "None"
20
+ :dnsConfig:
15
21
  nameservers:
16
22
  - 10.240.0.10
17
23
  - 10.240.1.10
18
- searches:
24
+ :searches:
19
25
  - gke-puppetagent-ci.puppet.net
20
- hostAliases:
21
- - ip: "169.254.169.254"
22
- hostnames:
23
- - "metadata.google.internal"
26
+ :hostAliases:
27
+ - :ip: "169.254.169.254"
28
+ :hostnames:
29
+ - "metadata.google.internal"
30
+ :affinity:
31
+ :podAntiAffinity:
32
+ :preferredDuringSchedulingIgnoredDuringExecution:
33
+ - :weight: 100
34
+ :podAffinityTerm:
35
+ :labelSelector:
36
+ :matchLabels:
37
+ :project: puppet-agent-ci
38
+ :topologyKey: kubernetes.io/hostname
@@ -1,11 +1,12 @@
1
- apiVersion: v1
2
- kind: Service
3
- metadata:
4
- name: "%{pod_name}"
5
- namespace: gke-puppetagent-ci
6
- labels:
7
- app: "%{pod_name}"
8
- spec:
9
- selector:
10
- app: "%{pod_name}"
11
- clusterIP: "None"
1
+ ---
2
+ :apiVersion: v1
3
+ :kind: Service
4
+ :metadata:
5
+ :name: "%{pod_name}"
6
+ :namespace: gke-puppetagent-ci
7
+ :labels:
8
+ :app: "%{pod_name}"
9
+ :spec:
10
+ :selector:
11
+ :app: "%{pod_name}"
12
+ :clusterIP: "None"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
5
  ROOT_DIR = Pathname.new(File.expand_path('..', __dir__)) unless defined?(ROOT_DIR)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BeakerGke
2
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
3
5
  end
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'kubeclient'
2
- require 'jsonpath'
3
- require 'beaker'
4
4
  require 'beaker-gke'
5
5
  require 'googleauth'
6
+ require 'erb'
6
7
 
7
8
  module Beaker
8
9
  class Gke < Beaker::Hypervisor
9
- SERVICE_NAMESPACE = 'gke-puppetagent-ci'.freeze
10
- PROXY_IP = '10.236.0.3'.freeze
10
+ SERVICE_NAMESPACE = 'gke-puppetagent-ci'
11
+ PROXY_IP = '10.236.0.3'
11
12
  PROXY_PORT = 8899
12
13
  MAX_RETRIES = 5
13
14
  # OS environment variable must be set to continue
@@ -18,12 +19,16 @@ module Beaker
18
19
  begin
19
20
  ENV.fetch('KUBECONFIG')
20
21
  ENV.fetch('GOOGLE_APPLICATION_CREDENTIALS')
21
- rescue
22
- raise ArgumentError, 'OS environment variable KUBECONFIG and GOOGLE_APPLICATION_CREDENTIALS must be set'
22
+ rescue KeyError
23
+ raise(
24
+ ArgumentError,
25
+ 'OS environment variable KUBECONFIG and GOOGLE_APPLICATION_CREDENTIALS must be set'
26
+ )
23
27
  end
24
- @hosts = hosts
25
- @options = options
26
- @client = client
28
+ @hosts = hosts
29
+ @options = options
30
+ @client = client
31
+ @logger = options[:logger]
27
32
  end
28
33
 
29
34
  def provision
@@ -32,39 +37,43 @@ module Beaker
32
37
  create_pod(hostname)
33
38
  create_srv(hostname)
34
39
  retries = 0
40
+
35
41
  begin
36
42
  pod = get_pod(hostname)
37
- raise StandardError if pod.status.podIP.nil?
43
+ raise StandardError unless pod.status.podIP
38
44
  rescue StandardError => e
39
- if retries <= MAX_RETRIES
40
- retries += 1
41
- puts 'Retrying , could not get podIP'
42
- sleep(2 ** retries)
45
+ raise "Timeout: #{e.message}" unless retries <= MAX_RETRIES
46
+
47
+ @logger.info("Retrying , could not get podIP for #{hostname}")
48
+
49
+ retries += 1
50
+ sleep(2**retries)
43
51
  retry
44
- else
45
- raise "Timeout: #{e.message}"
46
- end
47
52
  end
53
+
48
54
  host[:vmhostname] = "#{hostname}.gke-puppetagent-ci.puppet.net"
49
55
  host[:hostname] = hostname
50
56
  host[:ip] = pod.status.podIP
57
+ host[:gke_container] = true
51
58
  end
52
59
  nil
53
60
  end
54
61
 
55
62
  def cleanup
56
63
  @hosts.each do |host|
64
+ @logger.info("Deleting POD with ID: #{host[:hostname]}")
65
+
57
66
  delete_pod(host[:hostname])
58
67
  delete_service(host[:hostname])
59
68
  end
60
69
  end
61
70
 
62
- def connection_preference(host)
63
- [:ip, :vmhostname, :hostname]
71
+ def connection_preference(_host)
72
+ %i[ip vmhostname hostname]
64
73
  end
65
74
 
66
75
  def create_pod(name)
67
- pod_config=read_symbols('pod.yaml',{pod_name:name} )
76
+ pod_config = read_symbols('pod.yaml', pod_name: name)
68
77
  @client.create_pod(pod_config)
69
78
  end
70
79
 
@@ -73,24 +82,22 @@ module Beaker
73
82
  end
74
83
 
75
84
  def create_srv(name)
76
- service_config=read_symbols('service.yaml',{pod_name:name} )
85
+ service_config = read_symbols('service.yaml', pod_name: name)
77
86
  @client.create_service(service_config)
78
87
  end
79
88
 
80
89
  def delete_pod(pod_name)
81
- @client.delete_pod(pod_name, SERVICE_NAMESPACE, delete_options: { 'force': 1, 'grace-period': 0 } )
90
+ @client.delete_pod(
91
+ pod_name,
92
+ SERVICE_NAMESPACE,
93
+ delete_options: { 'force': 1, '--grace-period': 0 }
94
+ )
82
95
  end
83
96
 
84
97
  def delete_service(srv_name)
85
- begin
86
- if srv_name.instance_of?(String)
87
- client.delete_service(srv_name, SERVICE_NAMESPACE)
88
- else
89
- raise ArgumentError, 'Wrong argument type - #{srv_name.class}'
90
- end
91
- end
98
+ @client.delete_service(srv_name, SERVICE_NAMESPACE)
92
99
  rescue Kubeclient::ResourceNotFoundError => e
93
- puts "Service #{srv_name} could not be deleted #{e.to_s}"
100
+ @logger.info("Service #{srv_name} could not be deleted #{e}")
94
101
  end
95
102
 
96
103
  private
@@ -100,21 +107,20 @@ module Beaker
100
107
  context = config.context
101
108
  proxy_uri = URI::HTTP.build(host: PROXY_IP, port: PROXY_PORT)
102
109
  Kubeclient::Client.new(
103
- context.api_endpoint, 'v1',
104
- http_proxy_uri: proxy_uri,
105
- ssl_options: context.ssl_options,
106
- auth_options: context.auth_options
110
+ context.api_endpoint, 'v1',
111
+ http_proxy_uri: proxy_uri,
112
+ ssl_options: context.ssl_options,
113
+ auth_options: context.auth_options
107
114
  )
108
115
  end
109
116
 
110
117
  def read_file(file_name)
111
- path = File.join(ROOT_DIR, 'config', file_name)
112
- File.read(path)
118
+ File.read(File.join(ROOT_DIR, 'config', file_name))
113
119
  end
114
120
 
115
121
  def read_symbols(file, substitution = {})
116
- data = read_file(file)
117
- Psych.load(data %substitution , symbolize_names: true)
122
+ data = ERB.new(read_file(file)).result
123
+ Psych.load(data % substitution, symbolize_names: true)
118
124
  end
119
125
  end
120
126
  end
metadata CHANGED
@@ -1,141 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-gke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Night's Watch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-26 00:00:00.000000000 Z
11
+ date: 2019-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec-its
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: fakefs
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.6'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.6'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '10.1'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '10.1'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry
14
+ name: googleauth
85
15
  requirement: !ruby/object:Gem::Requirement
86
16
  requirements:
87
17
  - - "~>"
88
18
  - !ruby/object:Gem::Version
89
- version: '0.10'
90
- type: :development
19
+ version: '0.9'
20
+ type: :runtime
91
21
  prerelease: false
92
22
  version_requirements: !ruby/object:Gem::Requirement
93
23
  requirements:
94
24
  - - "~>"
95
25
  - !ruby/object:Gem::Version
96
- version: '0.10'
97
- - !ruby/object:Gem::Dependency
98
- name: yard
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: markdown
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: thin
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
26
+ version: '0.9'
139
27
  - !ruby/object:Gem::Dependency
140
28
  name: kubeclient
141
29
  requirement: !ruby/object:Gem::Requirement
@@ -150,35 +38,7 @@ dependencies:
150
38
  - - "~>"
151
39
  - !ruby/object:Gem::Version
152
40
  version: 4.4.0
153
- - !ruby/object:Gem::Dependency
154
- name: jsonpath
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :runtime
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: googleauth
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :runtime
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- description: For use for the Beaker acceptance testing tool
41
+ description: Add GKE support to Beaker acceptance testing tool
182
42
  email:
183
43
  - team-nw@puppet.com
184
44
  executables:
@@ -186,6 +46,7 @@ executables:
186
46
  extensions: []
187
47
  extra_rdoc_files: []
188
48
  files:
49
+ - ".rubcop.yaml"
189
50
  - CODEOWNERS
190
51
  - Gemfile
191
52
  - LICENSE
@@ -200,7 +61,7 @@ files:
200
61
  - lib/beaker/hypervisor/gke.rb
201
62
  homepage: https://github.com/puppetlabs/beaker-gke
202
63
  licenses:
203
- - Apache2
64
+ - Apache-2.0
204
65
  metadata: {}
205
66
  post_install_message:
206
67
  rdoc_options: []
@@ -217,7 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
78
  - !ruby/object:Gem::Version
218
79
  version: '0'
219
80
  requirements: []
220
- rubygems_version: 3.0.4
81
+ rubyforge_project:
82
+ rubygems_version: 2.5.1
221
83
  signing_key:
222
84
  specification_version: 4
223
85
  summary: Beaker hypervisor for GKE!