@@ -20,6 +20,8 @@ import (
20
20
"reflect"
21
21
"strings"
22
22
23
+ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
24
+
23
25
"google.golang.org/api/option"
24
26
25
27
gcp "cloud.google.com/go/compute/apiv1"
@@ -111,7 +113,7 @@ func (m *targetTCPProxyModel) AdapterForObject(ctx context.Context, reader clien
111
113
if err != nil {
112
114
return nil , fmt .Errorf ("get ComputeTargetTCPProxyAdapter parent %s: %w" , computeTargetTCPProxyRef .External , err )
113
115
}
114
- location := parent .Region
116
+ location := parent .Location
115
117
116
118
// Handle API/TF default values
117
119
if obj .Spec .ProxyBind != nil && * obj .Spec .ProxyBind == false {
@@ -181,13 +183,13 @@ func (a *targetTCPProxyAdapter) Create(ctx context.Context, createOp *directbase
181
183
if err != nil {
182
184
return fmt .Errorf ("get ComputeTargetTCPProxy parent %s: %w" , a .id .External , err )
183
185
}
184
- region := parent .Region
186
+ location := parent .Location
185
187
186
188
tokens := strings .Split (a .id .External , "/" )
187
189
targetTCPProxy .Name = direct .LazyPtr (tokens [len (tokens )- 1 ])
188
190
189
191
op := & gcp.Operation {}
190
- if region == "global" {
192
+ if location == "global" {
191
193
req := & computepb.InsertTargetTcpProxyRequest {
192
194
Project : parent .ProjectID ,
193
195
TargetTcpProxyResource : targetTCPProxy ,
@@ -196,7 +198,7 @@ func (a *targetTCPProxyAdapter) Create(ctx context.Context, createOp *directbase
196
198
} else {
197
199
req := & computepb.InsertRegionTargetTcpProxyRequest {
198
200
Project : parent .ProjectID ,
199
- Region : region ,
201
+ Region : location ,
200
202
TargetTcpProxyResource : targetTCPProxy ,
201
203
}
202
204
op , err = a .regionalTargetTcpProxiesClient .Insert (ctx , req )
@@ -258,13 +260,18 @@ func (a *targetTCPProxyAdapter) Update(ctx context.Context, updateOp *directbase
258
260
if err != nil {
259
261
return fmt .Errorf ("get ComputeTargetTCPProxy parent %s: %w" , a .id .External , err )
260
262
}
261
- region := parent .Region
263
+ location := parent .Location
264
+
265
+ // Regional API does not support Update
266
+ if location != "global" {
267
+ return fmt .Errorf ("update operation not supported for resource %v %v" ,
268
+ a .desired .GroupVersionKind (), k8s .GetNamespacedName (a .desired ))
269
+ }
262
270
263
271
tokens := strings .Split (a .id .External , "/" )
264
272
targetTCPProxy .Name = direct .LazyPtr (tokens [len (tokens )- 1 ])
265
273
266
- // Regional API does not support Update
267
- if ! reflect .DeepEqual (targetTCPProxy .ProxyHeader , a .actual .ProxyHeader ) && region == "global" {
274
+ if ! reflect .DeepEqual (targetTCPProxy .ProxyHeader , a .actual .ProxyHeader ) {
268
275
setProxyHeaderReq := & computepb.SetProxyHeaderTargetTcpProxyRequest {
269
276
Project : parent .ProjectID ,
270
277
TargetTcpProxiesSetProxyHeaderRequestResource : & computepb.TargetTcpProxiesSetProxyHeaderRequest {ProxyHeader : targetTCPProxy .ProxyHeader },
@@ -283,7 +290,7 @@ func (a *targetTCPProxyAdapter) Update(ctx context.Context, updateOp *directbase
283
290
log .V (2 ).Info ("successfully updated ComputeTargetTCPProxy proxy header" , "name" , a .id .External )
284
291
}
285
292
286
- if ! reflect .DeepEqual (targetTCPProxy .Service , a .actual .Service ) && region == "global" {
293
+ if ! reflect .DeepEqual (targetTCPProxy .Service , a .actual .Service ) {
287
294
setBackendServiceReq := & computepb.SetBackendServiceTargetTcpProxyRequest {
288
295
Project : parent .ProjectID ,
289
296
TargetTcpProxiesSetBackendServiceRequestResource : & computepb.TargetTcpProxiesSetBackendServiceRequest {Service : targetTCPProxy .Service },
@@ -347,11 +354,11 @@ func (a *targetTCPProxyAdapter) Delete(ctx context.Context, deleteOp *directbase
347
354
if err != nil {
348
355
return false , fmt .Errorf ("get ComputeTargetTcpProxy parent %s: %w" , a .id .External , err )
349
356
}
350
- region := parent .Region
357
+ location := parent .Location
351
358
352
359
op := & gcp.Operation {}
353
360
tokens := strings .Split (a .id .External , "/" )
354
- if region == "global" {
361
+ if location == "global" {
355
362
delReq := & computepb.DeleteTargetTcpProxyRequest {
356
363
Project : parent .ProjectID ,
357
364
TargetTcpProxy : tokens [len (tokens )- 1 ],
@@ -360,7 +367,7 @@ func (a *targetTCPProxyAdapter) Delete(ctx context.Context, deleteOp *directbase
360
367
} else {
361
368
delReq := & computepb.DeleteRegionTargetTcpProxyRequest {
362
369
Project : parent .ProjectID ,
363
- Region : region ,
370
+ Region : location ,
364
371
TargetTcpProxy : tokens [len (tokens )- 1 ],
365
372
}
366
373
op , err = a .regionalTargetTcpProxiesClient .Delete (ctx , delReq )
@@ -384,10 +391,10 @@ func (a *targetTCPProxyAdapter) get(ctx context.Context) (*computepb.TargetTcpPr
384
391
if err != nil {
385
392
return nil , fmt .Errorf ("get ComputeTargetTcpProxy parent %s: %w" , a .id .External , err )
386
393
}
387
- region := parent .Region
394
+ location := parent .Location
388
395
389
396
tokens := strings .Split (a .id .External , "/" )
390
- if region == "global" {
397
+ if location == "global" {
391
398
getReq := & computepb.GetTargetTcpProxyRequest {
392
399
Project : parent .ProjectID ,
393
400
TargetTcpProxy : tokens [len (tokens )- 1 ],
@@ -396,7 +403,7 @@ func (a *targetTCPProxyAdapter) get(ctx context.Context) (*computepb.TargetTcpPr
396
403
} else {
397
404
getReq := & computepb.GetRegionTargetTcpProxyRequest {
398
405
Project : parent .ProjectID ,
399
- Region : region ,
406
+ Region : location ,
400
407
TargetTcpProxy : tokens [len (tokens )- 1 ],
401
408
}
402
409
return a .regionalTargetTcpProxiesClient .Get (ctx , getReq )
0 commit comments