beaker-gke 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +8 -0
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/.rubocop.yml +36 -0
- data/.travis.yml +17 -0
- data/CODEOWNERS +2 -1
- data/Gemfile +28 -2
- data/Rakefile +31 -0
- data/beaker-gke.gemspec +21 -28
- data/bin/beaker-gke +1 -0
- data/config/pod.yaml +34 -19
- data/config/service.yaml +12 -11
- data/lib/beaker/hypervisor/gke.rb +44 -38
- data/lib/beaker-gke/version.rb +3 -1
- data/lib/beaker-gke.rb +2 -0
- data/spec/gke/hypervisor/gke_spec.rb +176 -0
- data/spec/spec_helper.rb +24 -0
- metadata +42 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7088a7e3170a2710eab2fdd6fd718e24da57daec4a59233bd8c9c2213dec2c79
|
4
|
+
data.tar.gz: 190e006996fd60900469009ea5a6d6b68efbdd2410b2c0731e684b4be4774052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73a0b108eb1bb49deffd6f7041a04d881366b2a5d2739202c761d1246f83d2bfa8d9530c0d173d68fa53f03036d3399e6021846225322fb87f152352789e680b
|
7
|
+
data.tar.gz: 2cbd244cd17946c6bf5047ec9db0db67b156b477b645cfd31b5e0907bb0a84a940f8aa93b3ec5b880d8e28662709352dc79f03f7b48cfa28dff1296fd5b7287c
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
require:
|
3
|
+
- rubocop-rspec
|
4
|
+
- rubocop-performance
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.5
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Style/Documentation:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 25
|
14
|
+
|
15
|
+
Layout/LineLength:
|
16
|
+
Max: 120
|
17
|
+
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Naming/FileName:
|
22
|
+
Exclude:
|
23
|
+
- 'lib/beaker-gke.rb'
|
24
|
+
|
25
|
+
Security/Eval:
|
26
|
+
Exclude:
|
27
|
+
- 'Gemfile'
|
28
|
+
|
29
|
+
Metrics/BlockLength:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Metrics/ModuleLength:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
RSpec/FilePath:
|
36
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
bundler_args: --jobs 4 --retry 2 --without packaging documentation
|
4
|
+
before_install:
|
5
|
+
- gem update --system && gem install bundler --no-document
|
6
|
+
script:
|
7
|
+
- "bundle exec rake $CHECK"
|
8
|
+
notifications:
|
9
|
+
email: false
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
include:
|
13
|
+
- rvm: 2.5
|
14
|
+
env: "CHECK=rubocop"
|
15
|
+
|
16
|
+
- rvm: 2.5
|
17
|
+
env: "CHECK=test:spec:run"
|
data/CODEOWNERS
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
*
|
1
|
+
* @puppetlabs/release-engineering
|
2
|
+
|
data/Gemfile
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem 'rubocop', require: false
|
9
|
+
gem 'rubocop-performance', require: false
|
10
|
+
gem 'rubocop-rspec', require: false
|
11
|
+
end
|
12
|
+
|
13
|
+
def location_for(place, fake_version = nil)
|
14
|
+
if place =~ /^git:([^#]*)#(.*)/
|
15
|
+
[fake_version, { git: Regexp.last_match(1), branch: Regexp.last_match(2), require: false }].compact
|
16
|
+
elsif place =~ %r{^file://(.*)}
|
17
|
+
['>= 0', { path: File.expand_path(Regexp.last_match(1)), require: false }]
|
18
|
+
else
|
19
|
+
[place, { require: false }]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# We don't put beaker in as a test dependency because we
|
24
|
+
# don't want to create a transitive dependency
|
25
|
+
group :acceptance_testing do
|
26
|
+
gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '~> 4.0')
|
27
|
+
end
|
28
|
+
|
29
|
+
eval(File.read("#{__FILE__}.local"), binding) if File.exist? "#{__FILE__}.local"
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
namespace :spec do
|
7
|
+
desc 'Run spec tests'
|
8
|
+
RSpec::Core::RakeTask.new(:run) do |t|
|
9
|
+
t.rspec_opts = ['--color']
|
10
|
+
t.pattern = 'spec/'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'run static analysis with rubocop'
|
16
|
+
task(:rubocop) do
|
17
|
+
require 'rubocop'
|
18
|
+
cli = RuboCop::CLI.new
|
19
|
+
exit_code = cli.run(%w[--display-cop-names --format simple])
|
20
|
+
raise 'RuboCop detected offenses' if exit_code != 0
|
21
|
+
end
|
22
|
+
|
23
|
+
# namespace-named default tasks.
|
24
|
+
# these are the default tasks invoked when only the namespace is referenced.
|
25
|
+
# they're needed because `task :default` in those blocks doesn't work as expected.
|
26
|
+
task 'test:spec' => 'test:spec:run'
|
27
|
+
task 'test:acceptance' => 'test:acceptance:quick'
|
28
|
+
|
29
|
+
# global defaults
|
30
|
+
task test: 'test:spec'
|
31
|
+
task default: :test
|
data/beaker-gke.gemspec
CHANGED
@@ -1,43 +1,36 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
4
|
+
|
3
5
|
require 'beaker-gke/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
8
|
+
s.name = 'beaker-gke'
|
7
9
|
s.version = BeakerGke::VERSION
|
8
10
|
s.authors = ["Night's Watch"]
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
13
|
-
s.license = '
|
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{ |
|
18
|
-
s.require_paths = [
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |file| File.basename(file) }
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
# Required ruby version
|
23
|
+
s.required_ruby_version = '~> 2.5'
|
19
24
|
|
20
25
|
# Testing dependencies
|
26
|
+
s.add_development_dependency 'climate_control'
|
27
|
+
s.add_development_dependency 'fakefs', '~> 1.2', '<= 1.2.3'
|
28
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
21
29
|
s.add_development_dependency 'rspec', '~> 3.0'
|
22
30
|
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
31
|
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'
|
37
32
|
|
38
33
|
# Run time dependencies
|
39
|
-
s.add_runtime_dependency '
|
40
|
-
s.add_runtime_dependency '
|
41
|
-
|
42
|
-
|
43
|
-
end
|
34
|
+
s.add_runtime_dependency 'googleauth', '~> 0.9'
|
35
|
+
s.add_runtime_dependency 'kubeclient', '>= 4.4', '< 4.10'
|
36
|
+
end
|
data/bin/beaker-gke
CHANGED
data/config/pod.yaml
CHANGED
@@ -1,23 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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-base:v3" } %>
|
14
|
+
:name: "centos-7-base"
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
data/config/service.yaml
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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,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'
|
10
|
-
PROXY_IP = '10.236.0.3'
|
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
|
22
|
+
rescue KeyError
|
23
|
+
raise(
|
24
|
+
ArgumentError,
|
25
|
+
'OS environment variable KUBECONFIG and GOOGLE_APPLICATION_CREDENTIALS must be set'
|
26
|
+
)
|
23
27
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
43
|
+
raise StandardError unless pod.status.podIP
|
38
44
|
rescue StandardError => e
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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(
|
63
|
-
[
|
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',
|
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',
|
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(
|
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
|
-
|
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
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
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
|
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
|
data/lib/beaker-gke/version.rb
CHANGED
data/lib/beaker-gke.rb
CHANGED
@@ -0,0 +1,176 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'beaker/hypervisor/gke'
|
4
|
+
|
5
|
+
describe Beaker::Gke do
|
6
|
+
let(:hosts) { make_hosts }
|
7
|
+
|
8
|
+
let(:options) { { logger: logger } }
|
9
|
+
|
10
|
+
let(:logger) do
|
11
|
+
logger = instance_double('logger')
|
12
|
+
allow(logger).to receive(:debug)
|
13
|
+
allow(logger).to receive(:info)
|
14
|
+
allow(logger).to receive(:warn)
|
15
|
+
allow(logger).to receive(:error)
|
16
|
+
allow(logger).to receive(:notify)
|
17
|
+
logger
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:config) { instance_double('config') }
|
21
|
+
|
22
|
+
let(:context) do
|
23
|
+
instance_double('context',
|
24
|
+
api_endpoint: 'v1',
|
25
|
+
ssl_options: {
|
26
|
+
verify_ssl: 1,
|
27
|
+
cert_store: true
|
28
|
+
},
|
29
|
+
auth_options: {
|
30
|
+
bearer_token: 'TOKEN_STRING'
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:gke) { ::Beaker::Gke.new(hosts, options) }
|
35
|
+
|
36
|
+
def pass_through_initialization
|
37
|
+
allow(ENV).to receive(:fetch).with('KUBECONFIG').and_return('default_value')
|
38
|
+
allow(ENV).to receive(:fetch).with('GOOGLE_APPLICATION_CREDENTIALS').and_return('default_value')
|
39
|
+
allow(config).to receive(:context).and_return(context)
|
40
|
+
allow(Kubeclient::Config).to receive(:read).with(ENV['KUBECONFIG']).and_return(config)
|
41
|
+
end
|
42
|
+
|
43
|
+
before do
|
44
|
+
FakeFS.deactivate!
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ' #initialize' do
|
48
|
+
let(:env_error_message) { 'OS environment variable KUBECONFIG and GOOGLE_APPLICATION_CREDENTIALS must be set' }
|
49
|
+
|
50
|
+
it 'raises error when KUBECONFIG and GOOGLE_APPLICATION_CREDENTIALS ENV variables are not set' do
|
51
|
+
expect { gke }.to raise_error(ArgumentError, env_error_message)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'raises error when only GOOGLE_APPLICATION_CREDENTIALS ENV variable is set' do
|
55
|
+
with_modified_env GOOGLE_APPLICATION_CREDENTIALS: 'default_value' do
|
56
|
+
expect { gke }.to raise_error(ArgumentError, env_error_message)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'raises error when only KUBECONFIG ENV variable is set' do
|
61
|
+
with_modified_env KUBECONFIG: 'default_value' do
|
62
|
+
expect { gke }.to raise_error(ArgumentError, env_error_message)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when both KUBECONFIG and GOOGLE_APPLICATION_CREDENTIALS ENV are set' do
|
67
|
+
before do
|
68
|
+
pass_through_initialization
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'sets the hosts data member accordingly' do
|
72
|
+
expect(gke.instance_variable_get(:@hosts)).to equal(hosts)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'sets the options data member accordingly' do
|
76
|
+
expect(gke.instance_variable_get(:@options)).to equal(options)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'sets the logger data member accordingly' do
|
80
|
+
expect(gke.instance_variable_get(:@logger)).to equal(logger)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'succeeds and does not raise any errors' do
|
84
|
+
expect { gke }.not_to raise_error
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe ' #provision' do
|
90
|
+
let(:pod) { instance_double('pod') }
|
91
|
+
|
92
|
+
let(:status) { instance_double('status', podIP: '10.236.246.250') }
|
93
|
+
let(:empty_ip_status) { instance_double('status', podIP: nil) }
|
94
|
+
|
95
|
+
def pass_through_pod_and_service_creation
|
96
|
+
allow(gke).to receive(:create_pod).and_return(nil)
|
97
|
+
allow(gke).to receive(:read_file).with('pod.yaml').and_return('pod.yaml content')
|
98
|
+
|
99
|
+
allow(gke).to receive(:create_srv).and_return(nil)
|
100
|
+
allow(gke).to receive(:read_file).with('service.yaml').and_return('service.yaml content')
|
101
|
+
end
|
102
|
+
|
103
|
+
before do
|
104
|
+
pass_through_initialization
|
105
|
+
pass_through_pod_and_service_creation
|
106
|
+
allow(gke).to receive(:sleep).and_return(true)
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when no hosts given' do
|
110
|
+
let(:no_hosts_gke) { ::Beaker::Gke.new([], options) }
|
111
|
+
|
112
|
+
it 'returns nil' do
|
113
|
+
expect(no_hosts_gke.provision).to eq(nil)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'logs no info' do
|
117
|
+
no_hosts_gke.provision
|
118
|
+
expect(logger).not_to have_received(:info)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'does not raise any error' do
|
122
|
+
expect { no_hosts_gke.provision }.not_to raise_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'raises StandardError and logs podIP retrieval attempts' do # rubocop:disable RSpec/MultipleExpectations
|
127
|
+
allow(gke).to receive(:get_pod).and_return(pod)
|
128
|
+
allow(pod).to receive(:status).and_return(empty_ip_status)
|
129
|
+
|
130
|
+
expect { gke.provision }.to raise_error(StandardError)
|
131
|
+
expect(logger).to have_received(:info).with(/Retrying, could not get podIP for/).at_least(:once)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'succeeds' do
|
135
|
+
allow(gke).to receive(:get_pod).and_return(pod)
|
136
|
+
allow(pod).to receive(:status).and_return(status)
|
137
|
+
|
138
|
+
expect(gke.provision).to eq(nil)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe ' #cleanup' do
|
143
|
+
before do
|
144
|
+
pass_through_initialization
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when no hosts given' do
|
148
|
+
let(:no_hosts_gke) { ::Beaker::Gke.new([], options) }
|
149
|
+
|
150
|
+
it 'does not raise any error' do
|
151
|
+
expect { no_hosts_gke.cleanup }.not_to raise_error
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'logs no info' do
|
155
|
+
no_hosts_gke.cleanup
|
156
|
+
expect(logger).not_to have_received(:info)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when succeeds' do
|
161
|
+
before do
|
162
|
+
allow(gke).to receive(:delete_pod).and_return(nil)
|
163
|
+
allow(gke).to receive(:delete_service).and_return(nil)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'does not raise any error' do
|
167
|
+
expect { gke.cleanup }.not_to raise_error
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'logs deleted pods' do
|
171
|
+
gke.cleanup
|
172
|
+
expect(logger).to have_received(:info).with(/Deleting POD with ID:/).exactly(hosts.size).times
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'beaker'
|
4
|
+
require 'simplecov'
|
5
|
+
require 'climate_control'
|
6
|
+
require 'fakefs/spec_helpers'
|
7
|
+
|
8
|
+
Dir.glob(Dir.pwd + '/lib/beaker/hypervisor/*.rb').sort { |file| require file }
|
9
|
+
|
10
|
+
# setup & require beaker's spec_helper.rb
|
11
|
+
beaker_gem_spec = Gem::Specification.find_by_name('beaker')
|
12
|
+
beaker_gem_dir = beaker_gem_spec.gem_dir
|
13
|
+
beaker_spec_path = File.join(beaker_gem_dir, 'spec')
|
14
|
+
$LOAD_PATH << beaker_spec_path
|
15
|
+
require File.join(beaker_spec_path, 'spec_helper.rb')
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.include TestFileHelpers
|
19
|
+
config.include HostHelpers
|
20
|
+
end
|
21
|
+
|
22
|
+
def with_modified_env(options, &block)
|
23
|
+
ClimateControl.modify(options, &block)
|
24
|
+
end
|
metadata
CHANGED
@@ -1,31 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaker-gke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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:
|
11
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
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
|
14
|
+
name: climate_control
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
@@ -44,72 +30,50 @@ dependencies:
|
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
33
|
+
version: '1.2'
|
34
|
+
- - "<="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.2.3
|
48
37
|
type: :development
|
49
38
|
prerelease: false
|
50
39
|
version_requirements: !ruby/object:Gem::Requirement
|
51
40
|
requirements:
|
52
41
|
- - "~>"
|
53
42
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
43
|
+
version: '1.2'
|
44
|
+
- - "<="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.2.3
|
55
47
|
- !ruby/object:Gem::Dependency
|
56
48
|
name: rake
|
57
49
|
requirement: !ruby/object:Gem::Requirement
|
58
50
|
requirements:
|
59
51
|
- - "~>"
|
60
52
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
53
|
+
version: '13.0'
|
62
54
|
type: :development
|
63
55
|
prerelease: false
|
64
56
|
version_requirements: !ruby/object:Gem::Requirement
|
65
57
|
requirements:
|
66
58
|
- - "~>"
|
67
59
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
60
|
+
version: '13.0'
|
69
61
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
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
|
62
|
+
name: rspec
|
85
63
|
requirement: !ruby/object:Gem::Requirement
|
86
64
|
requirements:
|
87
65
|
- - "~>"
|
88
66
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0
|
67
|
+
version: '3.0'
|
90
68
|
type: :development
|
91
69
|
prerelease: false
|
92
70
|
version_requirements: !ruby/object:Gem::Requirement
|
93
71
|
requirements:
|
94
72
|
- - "~>"
|
95
73
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0
|
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'
|
74
|
+
version: '3.0'
|
111
75
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
76
|
+
name: rspec-its
|
113
77
|
requirement: !ruby/object:Gem::Requirement
|
114
78
|
requirements:
|
115
79
|
- - ">="
|
@@ -123,7 +87,7 @@ dependencies:
|
|
123
87
|
- !ruby/object:Gem::Version
|
124
88
|
version: '0'
|
125
89
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
90
|
+
name: simplecov
|
127
91
|
requirement: !ruby/object:Gem::Requirement
|
128
92
|
requirements:
|
129
93
|
- - ">="
|
@@ -137,48 +101,40 @@ dependencies:
|
|
137
101
|
- !ruby/object:Gem::Version
|
138
102
|
version: '0'
|
139
103
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
104
|
+
name: googleauth
|
141
105
|
requirement: !ruby/object:Gem::Requirement
|
142
106
|
requirements:
|
143
107
|
- - "~>"
|
144
108
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
109
|
+
version: '0.9'
|
146
110
|
type: :runtime
|
147
111
|
prerelease: false
|
148
112
|
version_requirements: !ruby/object:Gem::Requirement
|
149
113
|
requirements:
|
150
114
|
- - "~>"
|
151
115
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
116
|
+
version: '0.9'
|
153
117
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
118
|
+
name: kubeclient
|
155
119
|
requirement: !ruby/object:Gem::Requirement
|
156
120
|
requirements:
|
157
121
|
- - ">="
|
158
122
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
160
|
-
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
123
|
+
version: '4.4'
|
124
|
+
- - "<"
|
165
125
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
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'
|
126
|
+
version: '4.10'
|
174
127
|
type: :runtime
|
175
128
|
prerelease: false
|
176
129
|
version_requirements: !ruby/object:Gem::Requirement
|
177
130
|
requirements:
|
178
131
|
- - ">="
|
179
132
|
- !ruby/object:Gem::Version
|
180
|
-
version: '
|
181
|
-
|
133
|
+
version: '4.4'
|
134
|
+
- - "<"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '4.10'
|
137
|
+
description: Add GKE support to Beaker acceptance testing tool
|
182
138
|
email:
|
183
139
|
- team-nw@puppet.com
|
184
140
|
executables:
|
@@ -186,10 +142,16 @@ executables:
|
|
186
142
|
extensions: []
|
187
143
|
extra_rdoc_files: []
|
188
144
|
files:
|
145
|
+
- ".github/dependabot.yml"
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".rubocop.yml"
|
149
|
+
- ".travis.yml"
|
189
150
|
- CODEOWNERS
|
190
151
|
- Gemfile
|
191
152
|
- LICENSE
|
192
153
|
- README.md
|
154
|
+
- Rakefile
|
193
155
|
- beaker-gke.gemspec
|
194
156
|
- bin/beaker-gke
|
195
157
|
- config/pod.yaml
|
@@ -198,9 +160,11 @@ files:
|
|
198
160
|
- lib/beaker-gke.rb
|
199
161
|
- lib/beaker-gke/version.rb
|
200
162
|
- lib/beaker/hypervisor/gke.rb
|
163
|
+
- spec/gke/hypervisor/gke_spec.rb
|
164
|
+
- spec/spec_helper.rb
|
201
165
|
homepage: https://github.com/puppetlabs/beaker-gke
|
202
166
|
licenses:
|
203
|
-
-
|
167
|
+
- Apache-2.0
|
204
168
|
metadata: {}
|
205
169
|
post_install_message:
|
206
170
|
rdoc_options: []
|
@@ -208,16 +172,16 @@ require_paths:
|
|
208
172
|
- lib
|
209
173
|
required_ruby_version: !ruby/object:Gem::Requirement
|
210
174
|
requirements:
|
211
|
-
- - "
|
175
|
+
- - "~>"
|
212
176
|
- !ruby/object:Gem::Version
|
213
|
-
version: '
|
177
|
+
version: '2.5'
|
214
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
179
|
requirements:
|
216
180
|
- - ">="
|
217
181
|
- !ruby/object:Gem::Version
|
218
182
|
version: '0'
|
219
183
|
requirements: []
|
220
|
-
rubygems_version: 3.0.
|
184
|
+
rubygems_version: 3.0.9
|
221
185
|
signing_key:
|
222
186
|
specification_version: 4
|
223
187
|
summary: Beaker hypervisor for GKE!
|