@@ -40,12 +40,17 @@ var recordTypeRegionalHostnameSupported = map[string]bool{
40
40
"CNAME" : true ,
41
41
}
42
42
43
- // RegionalHostnamesMap is a map of regional hostnames keyed by hostname.
44
- type RegionalHostnamesMap map [string ]cloudflare.RegionalHostname
43
+ type regionalHostname struct {
44
+ hostname string
45
+ regionKey string
46
+ }
47
+
48
+ // regionalHostnamesMap is a map of regional hostnames keyed by hostname.
49
+ type regionalHostnamesMap map [string ]regionalHostname
45
50
46
51
type regionalHostnameChange struct {
47
52
action changeAction
48
- cloudflare. RegionalHostname
53
+ regionalHostname
49
54
}
50
55
51
56
func (z zoneService ) ListDataLocalizationRegionalHostnames (ctx context.Context , rc * cloudflare.ResourceContainer , rp cloudflare.ListDataLocalizationRegionalHostnamesParams ) ([]cloudflare.RegionalHostname , error ) {
@@ -69,16 +74,16 @@ func (z zoneService) DeleteDataLocalizationRegionalHostname(ctx context.Context,
69
74
// createDataLocalizationRegionalHostnameParams is a function that returns the appropriate RegionalHostname Param based on the cloudFlareChange passed in
70
75
func createDataLocalizationRegionalHostnameParams (rhc regionalHostnameChange ) cloudflare.CreateDataLocalizationRegionalHostnameParams {
71
76
return cloudflare.CreateDataLocalizationRegionalHostnameParams {
72
- Hostname : rhc .Hostname ,
73
- RegionKey : rhc .RegionKey ,
77
+ Hostname : rhc .hostname ,
78
+ RegionKey : rhc .regionKey ,
74
79
}
75
80
}
76
81
77
82
// updateDataLocalizationRegionalHostnameParams is a function that returns the appropriate RegionalHostname Param based on the cloudFlareChange passed in
78
83
func updateDataLocalizationRegionalHostnameParams (rhc regionalHostnameChange ) cloudflare.UpdateDataLocalizationRegionalHostnameParams {
79
84
return cloudflare.UpdateDataLocalizationRegionalHostnameParams {
80
- Hostname : rhc .Hostname ,
81
- RegionKey : rhc .RegionKey ,
85
+ Hostname : rhc .hostname ,
86
+ RegionKey : rhc .regionKey ,
82
87
}
83
88
}
84
89
@@ -98,8 +103,8 @@ func (p *CloudFlareProvider) submitRegionalHostnameChanges(ctx context.Context,
98
103
// submitRegionalHostnameChange applies a single regional hostname change, returns false if it fails
99
104
func (p * CloudFlareProvider ) submitRegionalHostnameChange (ctx context.Context , rhChange regionalHostnameChange , resourceContainer * cloudflare.ResourceContainer ) bool {
100
105
changeLog := log .WithFields (log.Fields {
101
- "hostname" : rhChange .Hostname ,
102
- "region_key" : rhChange .RegionKey ,
106
+ "hostname" : rhChange .hostname ,
107
+ "region_key" : rhChange .regionKey ,
103
108
"action" : rhChange .action .String (),
104
109
"zone" : resourceContainer .Identifier ,
105
110
})
@@ -124,42 +129,45 @@ func (p *CloudFlareProvider) submitRegionalHostnameChange(ctx context.Context, r
124
129
}
125
130
case cloudFlareDelete :
126
131
changeLog .Debug ("Deleting regional hostname" )
127
- if err := p .Client .DeleteDataLocalizationRegionalHostname (ctx , resourceContainer , rhChange .Hostname ); err != nil {
132
+ if err := p .Client .DeleteDataLocalizationRegionalHostname (ctx , resourceContainer , rhChange .hostname ); err != nil {
128
133
changeLog .Errorf ("failed to delete regional hostname: %v" , err )
129
134
return false
130
135
}
131
136
}
132
137
return true
133
138
}
134
139
135
- func (p * CloudFlareProvider ) listDataLocalisationRegionalHostnames (ctx context.Context , resourceContainer * cloudflare.ResourceContainer ) (RegionalHostnamesMap , error ) {
140
+ func (p * CloudFlareProvider ) listDataLocalisationRegionalHostnames (ctx context.Context , resourceContainer * cloudflare.ResourceContainer ) (regionalHostnamesMap , error ) {
136
141
rhs , err := p .Client .ListDataLocalizationRegionalHostnames (ctx , resourceContainer , cloudflare.ListDataLocalizationRegionalHostnamesParams {})
137
142
if err != nil {
138
143
return nil , convertCloudflareError (err )
139
144
}
140
- rhsMap := make (RegionalHostnamesMap )
141
- for _ , r := range rhs {
142
- rhsMap [r .Hostname ] = r
145
+ rhsMap := make (regionalHostnamesMap )
146
+ for _ , rh := range rhs {
147
+ rhsMap [rh .Hostname ] = regionalHostname {
148
+ hostname : rh .Hostname ,
149
+ regionKey : rh .RegionKey ,
150
+ }
143
151
}
144
152
return rhsMap , nil
145
153
}
146
154
147
- // regionalHostname returns a RegionalHostname for the given endpoint.
155
+ // regionalHostname returns a regionalHostname for the given endpoint.
148
156
//
149
157
// If the regional services feature is not enabled or the record type does not support regional hostnames,
150
- // it returns an empty RegionalHostname .
158
+ // it returns an empty regionalHostname .
151
159
// If the endpoint has a specific region key set, it uses that; otherwise, it defaults to the region key configured in the provider.
152
- func (p * CloudFlareProvider ) regionalHostname (ep * endpoint.Endpoint ) cloudflare. RegionalHostname {
160
+ func (p * CloudFlareProvider ) regionalHostname (ep * endpoint.Endpoint ) regionalHostname {
153
161
if ! p .RegionalServicesConfig .Enabled || ! recordTypeRegionalHostnameSupported [ep .RecordType ] {
154
- return cloudflare. RegionalHostname {}
162
+ return regionalHostname {}
155
163
}
156
164
regionKey := p .RegionalServicesConfig .RegionKey
157
165
if epRegionKey , exists := ep .GetProviderSpecificProperty (annotations .CloudflareRegionKey ); exists {
158
166
regionKey = epRegionKey
159
167
}
160
- return cloudflare. RegionalHostname {
161
- Hostname : ep .DNSName ,
162
- RegionKey : regionKey ,
168
+ return regionalHostname {
169
+ hostname : ep .DNSName ,
170
+ regionKey : regionKey ,
163
171
}
164
172
}
165
173
@@ -192,7 +200,7 @@ func (p *CloudFlareProvider) addEnpointsProviderSpecificRegionKeyProperty(ctx co
192
200
193
201
for _ , ep := range supportedEndpoints {
194
202
if rh , found := regionalHostnames [ep .DNSName ]; found {
195
- ep .SetProviderSpecificProperty (annotations .CloudflareRegionKey , rh .RegionKey )
203
+ ep .SetProviderSpecificProperty (annotations .CloudflareRegionKey , rh .regionKey )
196
204
}
197
205
}
198
206
return nil
@@ -203,67 +211,67 @@ func (p *CloudFlareProvider) addEnpointsProviderSpecificRegionKeyProperty(ctx co
203
211
// If there is a delete and a create or update action for the same hostname,
204
212
// The create or update takes precedence.
205
213
// Returns an error for conflicting region keys.
206
- func desiredRegionalHostnames (changes []* cloudFlareChange ) ([]cloudflare. RegionalHostname , error ) {
207
- rhs := make (map [string ]cloudflare. RegionalHostname )
214
+ func desiredRegionalHostnames (changes []* cloudFlareChange ) ([]regionalHostname , error ) {
215
+ rhs := make (map [string ]regionalHostname )
208
216
for _ , change := range changes {
209
- if change .RegionalHostname .Hostname == "" {
217
+ if change .RegionalHostname .hostname == "" {
210
218
continue
211
219
}
212
- rh , found := rhs [change .RegionalHostname .Hostname ]
220
+ rh , found := rhs [change .RegionalHostname .hostname ]
213
221
if ! found {
214
222
if change .Action == cloudFlareDelete {
215
- rhs [change .RegionalHostname .Hostname ] = cloudflare. RegionalHostname {
216
- Hostname : change .RegionalHostname .Hostname ,
217
- RegionKey : "" , // Indicate that this regional hostname should not exists
223
+ rhs [change .RegionalHostname .hostname ] = regionalHostname {
224
+ hostname : change .RegionalHostname .hostname ,
225
+ regionKey : "" , // Indicate that this regional hostname should not exists
218
226
}
219
227
continue
220
228
}
221
- rhs [change .RegionalHostname .Hostname ] = change .RegionalHostname
229
+ rhs [change .RegionalHostname .hostname ] = change .RegionalHostname
222
230
continue
223
231
}
224
232
if change .Action == cloudFlareDelete {
225
233
// A previous regional hostname exists so we can skip this delete action
226
234
continue
227
235
}
228
- if rh .RegionKey == "" {
236
+ if rh .regionKey == "" {
229
237
// If the existing regional hostname has no region key, we can overwrite it
230
- rhs [change .RegionalHostname .Hostname ] = change .RegionalHostname
238
+ rhs [change .RegionalHostname .hostname ] = change .RegionalHostname
231
239
continue
232
240
}
233
- if rh .RegionKey != change .RegionalHostname .RegionKey {
234
- return nil , fmt .Errorf ("conflicting region keys for regional hostname %q: %q and %q" , change .RegionalHostname .Hostname , rh .RegionKey , change .RegionalHostname .RegionKey )
241
+ if rh .regionKey != change .RegionalHostname .regionKey {
242
+ return nil , fmt .Errorf ("conflicting region keys for regional hostname %q: %q and %q" , change .RegionalHostname .hostname , rh .regionKey , change .RegionalHostname .regionKey )
235
243
}
236
244
}
237
245
return slices .Collect (maps .Values (rhs )), nil
238
246
}
239
247
240
248
// regionalHostnamesChanges build a list of changes needed to synchronize the current regional hostnames state with the desired state.
241
- func regionalHostnamesChanges (desired []cloudflare. RegionalHostname , regionalHostnames RegionalHostnamesMap ) []regionalHostnameChange {
249
+ func regionalHostnamesChanges (desired []regionalHostname , regionalHostnames regionalHostnamesMap ) []regionalHostnameChange {
242
250
changes := make ([]regionalHostnameChange , 0 )
243
251
for _ , rh := range desired {
244
- current , found := regionalHostnames [rh .Hostname ]
245
- if rh .RegionKey == "" {
252
+ current , found := regionalHostnames [rh .hostname ]
253
+ if rh .regionKey == "" {
246
254
// If the region key is empty, we don't want a regional hostname
247
255
if ! found {
248
256
continue
249
257
}
250
258
changes = append (changes , regionalHostnameChange {
251
259
action : cloudFlareDelete ,
252
- RegionalHostname : rh ,
260
+ regionalHostname : rh ,
253
261
})
254
262
continue
255
263
}
256
264
if ! found {
257
265
changes = append (changes , regionalHostnameChange {
258
266
action : cloudFlareCreate ,
259
- RegionalHostname : rh ,
267
+ regionalHostname : rh ,
260
268
})
261
269
continue
262
270
}
263
- if rh .RegionKey != current .RegionKey {
271
+ if rh .regionKey != current .regionKey {
264
272
changes = append (changes , regionalHostnameChange {
265
273
action : cloudFlareUpdate ,
266
- RegionalHostname : rh ,
274
+ regionalHostname : rh ,
267
275
})
268
276
}
269
277
}
0 commit comments