beaker-gke 0.0.3 → 0.1.0

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
- SHA1:
3
- metadata.gz: 354a9675ddc9882d82b854124c3f7d60f03f80ca
4
- data.tar.gz: df0e876ba3d48d7c1e4a7d842fe3051f66f3b5da
2
+ SHA256:
3
+ metadata.gz: 7088a7e3170a2710eab2fdd6fd718e24da57daec4a59233bd8c9c2213dec2c79
4
+ data.tar.gz: 190e006996fd60900469009ea5a6d6b68efbdd2410b2c0731e684b4be4774052
5
5
  SHA512:
6
- metadata.gz: e10f5291bf417d5cdf7d5f1985dcd8b88cc3f14ad84ebcf59aedfef960f50d55b67163b7038e10ba89f250f1c0899646682c3c6aff29c6796fb396cdce29c8c7
7
- data.tar.gz: 08c721c8d35df672c0795bd12b5861c72611a2db9f93edfcfb229a0ac0ec91a108aa85a70b1c323d412c0da507388631d108f10c4358c7cec92b8fc03d90cefb
6
+ metadata.gz: 73a0b108eb1bb49deffd6f7041a04d881366b2a5d2739202c761d1246f83d2bfa8d9530c0d173d68fa53f03036d3399e6021846225322fb87f152352789e680b
7
+ data.tar.gz: 2cbd244cd17946c6bf5047ec9db0db67b156b477b645cfd31b5e0907bb0a84a940f8aa93b3ec5b880d8e28662709352dc79f03f7b48cfa28dff1296fd5b7287c
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "13:00"
8
+ open-pull-requests-limit: 10
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ # bundler
2
+ .bundle
3
+ Gemfile.local
4
+ Gemfile.lock
5
+
6
+ # JetBrains IDEA
7
+ *.iml
8
+ .idea/
9
+
10
+ # rbenv file
11
+ .ruby-version
12
+ .ruby-gemset
13
+
14
+ /.yardoc
15
+ /_yardoc/
16
+ /coverage/
17
+ /doc/
18
+ /pkg/
19
+ /spec/reports/
20
+ /tmp/
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
- * @puppetlabs/night-s-watch
1
+ * @puppetlabs/release-engineering
2
+
data/Gemfile CHANGED
@@ -1,3 +1,29 @@
1
- source ENV['GEM_SOURCE'] || "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- gemspec
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,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
4
 
5
5
  require 'beaker-gke/version'
6
6
 
@@ -19,7 +19,18 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map { |file| File.basename(file) }
20
20
  s.require_paths = ['lib']
21
21
 
22
+ # Required ruby version
23
+ s.required_ruby_version = '~> 2.5'
24
+
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'
29
+ s.add_development_dependency 'rspec', '~> 3.0'
30
+ s.add_development_dependency 'rspec-its'
31
+ s.add_development_dependency 'simplecov'
32
+
22
33
  # Run time dependencies
23
34
  s.add_runtime_dependency 'googleauth', '~> 0.9'
24
- s.add_runtime_dependency 'kubeclient', '~> 4.4.0'
35
+ s.add_runtime_dependency 'kubeclient', '>= 4.4', '< 4.10'
25
36
  end
@@ -44,7 +44,7 @@ module Beaker
44
44
  rescue StandardError => e
45
45
  raise "Timeout: #{e.message}" unless retries <= MAX_RETRIES
46
46
 
47
- @logger.info("Retrying , could not get podIP for #{hostname}")
47
+ @logger.info("Retrying, could not get podIP for #{hostname}")
48
48
 
49
49
  retries += 1
50
50
  sleep(2**retries)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BeakerGke
4
- VERSION = '0.0.3'
4
+ VERSION = '0.1.0'
5
5
  end
@@ -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
@@ -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,15 +1,105 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-gke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
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: 2019-10-31 00:00:00.000000000 Z
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: climate_control
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fakefs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ - - "<="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.2.3
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.2'
44
+ - - "<="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.2.3
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '13.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec-its
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
13
103
  - !ruby/object:Gem::Dependency
14
104
  name: googleauth
15
105
  requirement: !ruby/object:Gem::Requirement
@@ -28,16 +118,22 @@ dependencies:
28
118
  name: kubeclient
29
119
  requirement: !ruby/object:Gem::Requirement
30
120
  requirements:
31
- - - "~>"
121
+ - - ">="
32
122
  - !ruby/object:Gem::Version
33
- version: 4.4.0
123
+ version: '4.4'
124
+ - - "<"
125
+ - !ruby/object:Gem::Version
126
+ version: '4.10'
34
127
  type: :runtime
35
128
  prerelease: false
36
129
  version_requirements: !ruby/object:Gem::Requirement
37
130
  requirements:
38
- - - "~>"
131
+ - - ">="
39
132
  - !ruby/object:Gem::Version
40
- version: 4.4.0
133
+ version: '4.4'
134
+ - - "<"
135
+ - !ruby/object:Gem::Version
136
+ version: '4.10'
41
137
  description: Add GKE support to Beaker acceptance testing tool
42
138
  email:
43
139
  - team-nw@puppet.com
@@ -46,11 +142,16 @@ executables:
46
142
  extensions: []
47
143
  extra_rdoc_files: []
48
144
  files:
49
- - ".rubcop.yaml"
145
+ - ".github/dependabot.yml"
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".travis.yml"
50
150
  - CODEOWNERS
51
151
  - Gemfile
52
152
  - LICENSE
53
153
  - README.md
154
+ - Rakefile
54
155
  - beaker-gke.gemspec
55
156
  - bin/beaker-gke
56
157
  - config/pod.yaml
@@ -59,6 +160,8 @@ files:
59
160
  - lib/beaker-gke.rb
60
161
  - lib/beaker-gke/version.rb
61
162
  - lib/beaker/hypervisor/gke.rb
163
+ - spec/gke/hypervisor/gke_spec.rb
164
+ - spec/spec_helper.rb
62
165
  homepage: https://github.com/puppetlabs/beaker-gke
63
166
  licenses:
64
167
  - Apache-2.0
@@ -69,17 +172,16 @@ require_paths:
69
172
  - lib
70
173
  required_ruby_version: !ruby/object:Gem::Requirement
71
174
  requirements:
72
- - - ">="
175
+ - - "~>"
73
176
  - !ruby/object:Gem::Version
74
- version: '0'
177
+ version: '2.5'
75
178
  required_rubygems_version: !ruby/object:Gem::Requirement
76
179
  requirements:
77
180
  - - ">="
78
181
  - !ruby/object:Gem::Version
79
182
  version: '0'
80
183
  requirements: []
81
- rubyforge_project:
82
- rubygems_version: 2.5.1
184
+ rubygems_version: 3.0.9
83
185
  signing_key:
84
186
  specification_version: 4
85
187
  summary: Beaker hypervisor for GKE!
data/.rubcop.yaml DELETED
@@ -1,14 +0,0 @@
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