vmpooler-provider-gce 0.1.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vmpooler/cloud_dns.rb +63 -0
- data/lib/vmpooler/providers/gce.rb +17 -28
- data/lib/vmpooler-provider-gce/version.rb +1 -1
- metadata +48 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d84f2dc8dd84470083c1f6d7b87b8c4d213d9d1ed1dca1558fbdf02ef8553bf8
|
4
|
+
data.tar.gz: dac3ab9c8105b1dda22c61f787d5a2e0f7bf1cdee25998a130c1e286dfdca19c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 857d5925f6a618b75f90fde55265366804455cbc126bf6395e2d0d5f7e17a10c40f1901ddb3e900ba93024b684b185e34ded7d13cb11b46b3e81ada5657be244
|
7
|
+
data.tar.gz: 6c8681ed0c3b8cf9df4b5726fee60756cba2d0c9919421f0fc2eaf898f4e45fb8ecab23d5bfcd82b69e455bfaf7e3a3a8cb3fbab3e6bb1eb31e5826d0ad9e7db
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'googleauth'
|
4
|
+
require 'google/cloud/dns'
|
5
|
+
|
6
|
+
module Vmpooler
|
7
|
+
class PoolManager
|
8
|
+
# This class interacts with GCP Cloud DNS to create or delete records.
|
9
|
+
class CloudDns
|
10
|
+
def initialize(project, dns_zone_resource_name)
|
11
|
+
@dns = Google::Cloud::Dns.new(project_id: project)
|
12
|
+
@dns_zone_resource_name = dns_zone_resource_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def dns_create_or_replace(created_instance)
|
16
|
+
dns_zone = @dns.zone(@dns_zone_resource_name) if @dns_zone_resource_name
|
17
|
+
return unless dns_zone && created_instance && created_instance['name'] && created_instance['ip']
|
18
|
+
|
19
|
+
retries = 0
|
20
|
+
name = created_instance['name']
|
21
|
+
begin
|
22
|
+
change = dns_zone.add(name, 'A', 60, [created_instance['ip']])
|
23
|
+
debug_logger("#{change.id} - #{change.started_at} - #{change.status} DNS address added") if change
|
24
|
+
rescue Google::Cloud::AlreadyExistsError => _e
|
25
|
+
# DNS setup is done only for new instances, so in the rare case where a DNS record already exists (it is stale) and we replace it.
|
26
|
+
# the error is Google::Cloud::AlreadyExistsError: alreadyExists: The resource 'entity.change.additions[0]' named 'instance-8.test.vmpooler.net. (A)' already exists
|
27
|
+
change = dns_zone.replace(name, 'A', 60, [created_instance['ip']])
|
28
|
+
debug_logger("#{change.id} - #{change.started_at} - #{change.status} DNS address previously existed and was replaced") if change
|
29
|
+
rescue Google::Cloud::FailedPreconditionError => e
|
30
|
+
# this error was experienced intermittently, will retry to see if it can complete successfully
|
31
|
+
# the error is Google::Cloud::FailedPreconditionError: conditionNotMet: Precondition not met for 'entity.change.deletions[0]'
|
32
|
+
debug_logger("DNS create failed, retrying error: #{e}")
|
33
|
+
sleep 5
|
34
|
+
retry if (retries += 1) < 30
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def dns_teardown(created_instance)
|
39
|
+
dns_zone = @dns.zone(@dns_zone_resource_name) if @dns_zone_resource_name
|
40
|
+
return unless dns_zone && created_instance
|
41
|
+
|
42
|
+
retries = 0
|
43
|
+
name = created_instance['name']
|
44
|
+
change = dns_zone.remove(name, 'A')
|
45
|
+
debug_logger("#{change.id} - #{change.started_at} - #{change.status} DNS address removed") if change
|
46
|
+
rescue Google::Cloud::FailedPreconditionError => e
|
47
|
+
# this error was experienced intermittently, will retry to see if it can complete successfully
|
48
|
+
# the error is Google::Cloud::FailedPreconditionError: conditionNotMet: Precondition not met for 'entity.change.deletions[1]'
|
49
|
+
debug_logger("DNS teardown failed, retrying error: #{e}")
|
50
|
+
sleep 5
|
51
|
+
retry if (retries += 1) < 30
|
52
|
+
end
|
53
|
+
|
54
|
+
# used in local dev environment, set DEBUG_FLAG=true
|
55
|
+
# this way the upstream vmpooler manager does not get polluted with logs
|
56
|
+
def debug_logger(message, send_to_upstream: false)
|
57
|
+
# the default logger is simple and does not enforce debug levels (the first argument)
|
58
|
+
puts message if ENV['DEBUG_FLAG']
|
59
|
+
logger.log('[g]', message) if send_to_upstream
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'googleauth'
|
4
4
|
require 'google/apis/compute_v1'
|
5
|
-
require '
|
5
|
+
require 'vmpooler/cloud_dns'
|
6
6
|
require 'bigdecimal'
|
7
7
|
require 'bigdecimal/util'
|
8
8
|
require 'vmpooler/providers/base'
|
@@ -58,11 +58,6 @@ module Vmpooler
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
def dns
|
62
|
-
@dns ||= Google::Cloud::Dns.new(project_id: project)
|
63
|
-
@dns
|
64
|
-
end
|
65
|
-
|
66
61
|
# main configuration options
|
67
62
|
def project
|
68
63
|
provider_config['project']
|
@@ -181,19 +176,28 @@ module Vmpooler
|
|
181
176
|
network: network_name
|
182
177
|
)
|
183
178
|
network_interfaces.subnetwork = subnetwork_name(pool_name) if subnetwork_name(pool_name)
|
184
|
-
init_params =
|
179
|
+
init_params = Google::Apis::ComputeV1::AttachedDiskInitializeParams.new(
|
185
180
|
source_image: pool['template'], # The source image to create this disk.
|
186
181
|
labels: { 'vm' => new_vmname, 'pool' => pool_name },
|
187
182
|
disk_name: "#{new_vmname}-disk0"
|
188
|
-
|
183
|
+
)
|
184
|
+
# rubocop:disable Style/IfUnlessModifier
|
185
|
+
if pool['disk_type'] && !pool['disk_type'].empty?
|
186
|
+
init_params.disk_type = "https://www.googleapis.com/compute/v1/projects/#{project}/zones/#{zone(pool_name)}/diskTypes/#{pool['disk_type']}"
|
187
|
+
end
|
188
|
+
# rubocop:enable Style/IfUnlessModifier
|
189
189
|
disk = Google::Apis::ComputeV1::AttachedDisk.new(
|
190
190
|
auto_delete: true,
|
191
191
|
boot: true,
|
192
|
-
initialize_params:
|
192
|
+
initialize_params: init_params
|
193
193
|
)
|
194
|
+
append_domain = domain || global_config[:config]['domain']
|
195
|
+
fqdn = "#{new_vmname}.#{append_domain}" if append_domain
|
196
|
+
|
194
197
|
# Assume all pool config is valid i.e. not missing
|
195
198
|
client = ::Google::Apis::ComputeV1::Instance.new(
|
196
199
|
name: new_vmname,
|
200
|
+
hostname: fqdn,
|
197
201
|
machine_type: pool['machine_type'],
|
198
202
|
disks: [disk],
|
199
203
|
network_interfaces: [network_interfaces],
|
@@ -557,28 +561,13 @@ module Vmpooler
|
|
557
561
|
# END BASE METHODS
|
558
562
|
|
559
563
|
def dns_setup(created_instance)
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
name = created_instance['name']
|
564
|
-
begin
|
565
|
-
change = dns_zone.add(name, 'A', 60, [created_instance['ip']])
|
566
|
-
debug_logger("#{change.id} - #{change.started_at} - #{change.status} DNS address added") if change
|
567
|
-
rescue Google::Cloud::AlreadyExistsError => _e
|
568
|
-
# DNS setup is done only for new instances, so in the rare case where a DNS record already exists (it is stale) and we replace it.
|
569
|
-
# the error is Google::Cloud::AlreadyExistsError: alreadyExists: The resource 'entity.change.additions[0]' named 'instance-8.test.vmpooler.net. (A)' already exists
|
570
|
-
change = dns_zone.replace(name, 'A', 60, [created_instance['ip']])
|
571
|
-
debug_logger("#{change.id} - #{change.started_at} - #{change.status} DNS address previously existed and was replaced") if change
|
572
|
-
end
|
564
|
+
dns = Vmpooler::PoolManager::CloudDns.new(project, dns_zone_resource_name)
|
565
|
+
dns.dns_create_or_replace(created_instance)
|
573
566
|
end
|
574
567
|
|
575
568
|
def dns_teardown(created_instance)
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
name = created_instance['name']
|
580
|
-
change = dns_zone.remove(name, 'A')
|
581
|
-
debug_logger("#{change.id} - #{change.started_at} - #{change.status} DNS address removed") if change
|
569
|
+
dns = Vmpooler::PoolManager::CloudDns.new(project, dns_zone_resource_name)
|
570
|
+
dns.dns_teardown(created_instance)
|
582
571
|
end
|
583
572
|
|
584
573
|
def should_be_ignored(item, allowlist)
|
metadata
CHANGED
@@ -1,177 +1,182 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmpooler-provider-gce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: google-apis-compute_v1
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '0.14'
|
20
|
-
|
19
|
+
name: google-apis-compute_v1
|
21
20
|
prerelease: false
|
21
|
+
type: :runtime
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.14'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: googleauth
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
|
-
- - "
|
30
|
+
- - ">="
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: 0.16.2
|
34
|
-
|
33
|
+
- - "<"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.3.0
|
36
|
+
name: googleauth
|
35
37
|
prerelease: false
|
38
|
+
type: :runtime
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: 0.16.2
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.3.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: google-cloud-dns
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
44
49
|
requirements:
|
45
50
|
- - "~>"
|
46
51
|
- !ruby/object:Gem::Version
|
47
52
|
version: 0.35.1
|
48
|
-
|
53
|
+
name: google-cloud-dns
|
49
54
|
prerelease: false
|
55
|
+
type: :runtime
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: 0.35.1
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: vmpooler
|
57
62
|
requirement: !ruby/object:Gem::Requirement
|
58
63
|
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.3'
|
62
64
|
- - ">="
|
63
65
|
- !ruby/object:Gem::Version
|
64
66
|
version: 1.3.0
|
65
|
-
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.3'
|
70
|
+
name: vmpooler
|
66
71
|
prerelease: false
|
72
|
+
type: :development
|
67
73
|
version_requirements: !ruby/object:Gem::Requirement
|
68
74
|
requirements:
|
69
|
-
- - "~>"
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '1.3'
|
72
75
|
- - ">="
|
73
76
|
- !ruby/object:Gem::Version
|
74
77
|
version: 1.3.0
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '2.3'
|
75
81
|
- !ruby/object:Gem::Dependency
|
76
|
-
name: climate_control
|
77
82
|
requirement: !ruby/object:Gem::Requirement
|
78
83
|
requirements:
|
79
84
|
- - ">="
|
80
85
|
- !ruby/object:Gem::Version
|
81
86
|
version: 0.2.0
|
82
|
-
|
87
|
+
name: climate_control
|
83
88
|
prerelease: false
|
89
|
+
type: :development
|
84
90
|
version_requirements: !ruby/object:Gem::Requirement
|
85
91
|
requirements:
|
86
92
|
- - ">="
|
87
93
|
- !ruby/object:Gem::Version
|
88
94
|
version: 0.2.0
|
89
95
|
- !ruby/object:Gem::Dependency
|
90
|
-
name: mock_redis
|
91
96
|
requirement: !ruby/object:Gem::Requirement
|
92
97
|
requirements:
|
93
98
|
- - ">="
|
94
99
|
- !ruby/object:Gem::Version
|
95
100
|
version: 0.17.0
|
96
|
-
|
101
|
+
name: mock_redis
|
97
102
|
prerelease: false
|
103
|
+
type: :development
|
98
104
|
version_requirements: !ruby/object:Gem::Requirement
|
99
105
|
requirements:
|
100
106
|
- - ">="
|
101
107
|
- !ruby/object:Gem::Version
|
102
108
|
version: 0.17.0
|
103
109
|
- !ruby/object:Gem::Dependency
|
104
|
-
name: pry
|
105
110
|
requirement: !ruby/object:Gem::Requirement
|
106
111
|
requirements:
|
107
112
|
- - ">="
|
108
113
|
- !ruby/object:Gem::Version
|
109
114
|
version: '0'
|
110
|
-
|
115
|
+
name: pry
|
111
116
|
prerelease: false
|
117
|
+
type: :development
|
112
118
|
version_requirements: !ruby/object:Gem::Requirement
|
113
119
|
requirements:
|
114
120
|
- - ">="
|
115
121
|
- !ruby/object:Gem::Version
|
116
122
|
version: '0'
|
117
123
|
- !ruby/object:Gem::Dependency
|
118
|
-
name: rack-test
|
119
124
|
requirement: !ruby/object:Gem::Requirement
|
120
125
|
requirements:
|
121
126
|
- - ">="
|
122
127
|
- !ruby/object:Gem::Version
|
123
128
|
version: '0.6'
|
124
|
-
|
129
|
+
name: rack-test
|
125
130
|
prerelease: false
|
131
|
+
type: :development
|
126
132
|
version_requirements: !ruby/object:Gem::Requirement
|
127
133
|
requirements:
|
128
134
|
- - ">="
|
129
135
|
- !ruby/object:Gem::Version
|
130
136
|
version: '0.6'
|
131
137
|
- !ruby/object:Gem::Dependency
|
132
|
-
name: rspec
|
133
138
|
requirement: !ruby/object:Gem::Requirement
|
134
139
|
requirements:
|
135
140
|
- - ">="
|
136
141
|
- !ruby/object:Gem::Version
|
137
142
|
version: '3.2'
|
138
|
-
|
143
|
+
name: rspec
|
139
144
|
prerelease: false
|
145
|
+
type: :development
|
140
146
|
version_requirements: !ruby/object:Gem::Requirement
|
141
147
|
requirements:
|
142
148
|
- - ">="
|
143
149
|
- !ruby/object:Gem::Version
|
144
150
|
version: '3.2'
|
145
151
|
- !ruby/object:Gem::Dependency
|
146
|
-
name: rubocop
|
147
152
|
requirement: !ruby/object:Gem::Requirement
|
148
153
|
requirements:
|
149
154
|
- - "~>"
|
150
155
|
- !ruby/object:Gem::Version
|
151
156
|
version: 1.1.0
|
152
|
-
|
157
|
+
name: rubocop
|
153
158
|
prerelease: false
|
159
|
+
type: :development
|
154
160
|
version_requirements: !ruby/object:Gem::Requirement
|
155
161
|
requirements:
|
156
162
|
- - "~>"
|
157
163
|
- !ruby/object:Gem::Version
|
158
164
|
version: 1.1.0
|
159
165
|
- !ruby/object:Gem::Dependency
|
160
|
-
name: simplecov
|
161
166
|
requirement: !ruby/object:Gem::Requirement
|
162
167
|
requirements:
|
163
168
|
- - ">="
|
164
169
|
- !ruby/object:Gem::Version
|
165
170
|
version: 0.11.2
|
166
|
-
|
171
|
+
name: simplecov
|
167
172
|
prerelease: false
|
173
|
+
type: :development
|
168
174
|
version_requirements: !ruby/object:Gem::Requirement
|
169
175
|
requirements:
|
170
176
|
- - ">="
|
171
177
|
- !ruby/object:Gem::Version
|
172
178
|
version: 0.11.2
|
173
179
|
- !ruby/object:Gem::Dependency
|
174
|
-
name: thor
|
175
180
|
requirement: !ruby/object:Gem::Requirement
|
176
181
|
requirements:
|
177
182
|
- - "~>"
|
@@ -180,8 +185,9 @@ dependencies:
|
|
180
185
|
- - ">="
|
181
186
|
- !ruby/object:Gem::Version
|
182
187
|
version: 1.0.1
|
183
|
-
|
188
|
+
name: thor
|
184
189
|
prerelease: false
|
190
|
+
type: :development
|
185
191
|
version_requirements: !ruby/object:Gem::Requirement
|
186
192
|
requirements:
|
187
193
|
- - "~>"
|
@@ -191,20 +197,20 @@ dependencies:
|
|
191
197
|
- !ruby/object:Gem::Version
|
192
198
|
version: 1.0.1
|
193
199
|
- !ruby/object:Gem::Dependency
|
194
|
-
name: yarjuf
|
195
200
|
requirement: !ruby/object:Gem::Requirement
|
196
201
|
requirements:
|
197
202
|
- - ">="
|
198
203
|
- !ruby/object:Gem::Version
|
199
204
|
version: '2.0'
|
200
|
-
|
205
|
+
name: yarjuf
|
201
206
|
prerelease: false
|
207
|
+
type: :development
|
202
208
|
version_requirements: !ruby/object:Gem::Requirement
|
203
209
|
requirements:
|
204
210
|
- - ">="
|
205
211
|
- !ruby/object:Gem::Version
|
206
212
|
version: '2.0'
|
207
|
-
description:
|
213
|
+
description:
|
208
214
|
email:
|
209
215
|
- support@puppet.com
|
210
216
|
executables: []
|
@@ -212,12 +218,13 @@ extensions: []
|
|
212
218
|
extra_rdoc_files: []
|
213
219
|
files:
|
214
220
|
- lib/vmpooler-provider-gce/version.rb
|
221
|
+
- lib/vmpooler/cloud_dns.rb
|
215
222
|
- lib/vmpooler/providers/gce.rb
|
216
223
|
homepage: https://github.com/puppetlabs/vmpooler-provider-gce
|
217
224
|
licenses:
|
218
225
|
- Apache-2.0
|
219
226
|
metadata: {}
|
220
|
-
post_install_message:
|
227
|
+
post_install_message:
|
221
228
|
rdoc_options: []
|
222
229
|
require_paths:
|
223
230
|
- lib
|
@@ -232,9 +239,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
232
239
|
- !ruby/object:Gem::Version
|
233
240
|
version: '0'
|
234
241
|
requirements: []
|
235
|
-
|
236
|
-
|
237
|
-
signing_key:
|
242
|
+
rubygems_version: 3.2.29
|
243
|
+
signing_key:
|
238
244
|
specification_version: 4
|
239
245
|
summary: GCE provider for VMPooler
|
240
246
|
test_files: []
|