@@ -156,7 +156,7 @@ func (e *EMLB) ReconcileVIPOrigin(ctx context.Context, machineScope *scope.Machi
156
156
}
157
157
158
158
// Fetch the Load Balancer object.
159
- lb , err := e .getLoadBalancer (ctx , lbID )
159
+ lb , _ , err := e .getLoadBalancer (ctx , lbID )
160
160
if err != nil {
161
161
return err
162
162
}
@@ -247,18 +247,18 @@ func (e *EMLB) DeleteLoadBalancer(ctx context.Context, clusterScope *scope.Clust
247
247
return nil
248
248
}
249
249
250
- log .Info ("Deleting EMLB" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Load Balancer ID" , lbID )
251
-
252
250
// Fetch the Load Balancer object.
253
251
// Skip if 404, otherwise error
254
- lb , err := e .getLoadBalancer (ctx , lbID )
255
- if err != nil {
256
- log .Error (err , "failed to load the loadbalancer object, cannot proceed with deletion" )
252
+ lb , resp , err := e .getLoadBalancer (ctx , lbID )
253
+ if err != nil && ( resp . StatusCode != http . StatusNotFound ) {
254
+ log .Error (err , "unexpected error while loading the loadbalancer object, cannot proceed with deletion" )
257
255
return err
258
256
}
259
257
260
- resp , err := e .deleteLoadBalancer (ctx , lb .GetId ())
261
- if err != nil {
258
+ log .Info ("Deleting EMLB" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Load Balancer ID" , lbID )
259
+
260
+ resp , err = e .deleteLoadBalancer (ctx , lb .GetId ())
261
+ if err != nil && (resp .StatusCode != http .StatusNotFound ) {
262
262
log .Error (err , "LB Delete Failed" , "EMLB ID" , lb .GetId (), "Response Body" , resp .Body )
263
263
return err
264
264
}
@@ -279,19 +279,17 @@ func (e *EMLB) DeleteLoadBalancerOrigin(ctx context.Context, machineScope *scope
279
279
return fmt .Errorf ("no Equinix Metal Load Balancer Pool found in machine's annotations" )
280
280
}
281
281
282
- log .Info ("Deleting EMLB Origin from Pool" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Pool ID" , lbPoolID )
283
-
284
282
// Fetch the Load Balancer Pool object.
285
- lbPool , err := e .getLoadBalancerPool (ctx , lbPoolID )
286
- if err != nil {
287
- log .Error (err , "failed to load the loadbalancer pool object, cannot proceed with deletion" )
283
+ lbPool , resp , err := e .getLoadBalancerPool (ctx , lbPoolID )
284
+ if err != nil && ( resp . StatusCode != http . StatusNotFound ) {
285
+ log .Error (err , "unexpected error while loading the loadbalancer pool object, cannot proceed with deletion" )
288
286
return err
289
287
}
290
288
291
289
log .Info ("Deleting EMLB Pool" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Pool ID" , lbPoolID )
292
290
293
- resp , err : = e .deletePool (ctx , lbPool .GetId ())
294
- if err != nil {
291
+ resp , err = e .deletePool (ctx , lbPool .GetId ())
292
+ if err != nil && ( resp . StatusCode != http . StatusNotFound ) {
295
293
log .Error (err , "LB Pool Delete Failed" , "Pool ID" , lbPool .GetId (), "Response Body" , resp .Body )
296
294
return err
297
295
}
@@ -300,11 +298,11 @@ func (e *EMLB) DeleteLoadBalancerOrigin(ctx context.Context, machineScope *scope
300
298
}
301
299
302
300
// getLoadBalancer Returns a Load Balancer object given an id.
303
- func (e * EMLB ) getLoadBalancer (ctx context.Context , id string ) (* lbaas.LoadBalancer , error ) {
301
+ func (e * EMLB ) getLoadBalancer (ctx context.Context , id string ) (* lbaas.LoadBalancer , * http. Response , error ) {
304
302
ctx = context .WithValue (ctx , lbaas .ContextOAuth2 , e .tokenExchanger )
305
303
306
- LoadBalancer , _ , err := e .client .LoadBalancersApi .GetLoadBalancer (ctx , id ).Execute ()
307
- return LoadBalancer , err
304
+ LoadBalancer , resp , err := e .client .LoadBalancersApi .GetLoadBalancer (ctx , id ).Execute ()
305
+ return LoadBalancer , resp , err
308
306
}
309
307
310
308
// getLoadBalancerPort Returns a Load Balancer Port object given an id.
@@ -316,11 +314,11 @@ func (e *EMLB) getLoadBalancerPort(ctx context.Context, id string, portNumber in
316
314
}
317
315
318
316
// getLoadBalancerPool Returns a Load Balancer Pool object given an id.
319
- func (e * EMLB ) getLoadBalancerPool (ctx context.Context , id string ) (* lbaas.LoadBalancerPool , error ) {
317
+ func (e * EMLB ) getLoadBalancerPool (ctx context.Context , id string ) (* lbaas.LoadBalancerPool , * http. Response , error ) {
320
318
ctx = context .WithValue (ctx , lbaas .ContextOAuth2 , e .tokenExchanger )
321
319
322
- LoadBalancerPool , _ , err := e .client .PoolsApi .GetLoadBalancerPool (ctx , id ).Execute ()
323
- return LoadBalancerPool , err
320
+ LoadBalancerPool , resp , err := e .client .PoolsApi .GetLoadBalancerPool (ctx , id ).Execute ()
321
+ return LoadBalancerPool , resp , err
324
322
}
325
323
326
324
// EnsureLoadBalancerOrigin takes the devices list of IP addresses in a Load Balancer Origin Pool and ensures an origin
@@ -424,7 +422,7 @@ func (e *EMLB) ensureLoadBalancer(ctx context.Context, lbID, lbname string, port
424
422
}
425
423
426
424
// Regardless of whether we just created it, fetch the loadbalancer object.
427
- lb , err := e .getLoadBalancer (ctx , lbID )
425
+ lb , _ , err := e .getLoadBalancer (ctx , lbID )
428
426
if err != nil {
429
427
return nil , nil , err
430
428
}
0 commit comments