@@ -247,13 +247,6 @@ func (e *EMLB) DeleteLoadBalancer(ctx context.Context, clusterScope *scope.Clust
247
247
return nil
248
248
}
249
249
250
- // See if the EMLB has a Port ID in its packetCluster annotations.
251
- lbPortNumber , exists := packetCluster .Annotations [loadBalancerPortNumberAnnotation ]
252
- if ! exists || (lbPortNumber == "" ) {
253
- log .Info ("no Equinix Metal Load Balancer Port Number found in cluster's annotations, skipping EMLB delete" )
254
- return nil
255
- }
256
-
257
250
log .Info ("Deleting EMLB" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Load Balancer ID" , lbID )
258
251
259
252
// Fetch the Load Balancer object.
@@ -264,28 +257,7 @@ func (e *EMLB) DeleteLoadBalancer(ctx context.Context, clusterScope *scope.Clust
264
257
return err
265
258
}
266
259
267
- // Get an int version of the listener port number.
268
- portNumber , err := strconv .ParseInt (lbPortNumber , 10 , 32 )
269
- if err != nil {
270
- log .Error (err , "failed to convert the loadbalancer port number to an int, cannot proceed with deletion" )
271
- return err
272
- }
273
-
274
- // Get the entire listener port object.
275
- // Skip if 404, otherwise error
276
- lbPort , err := e .getLoadBalancerPort (ctx , lbID , int32 (portNumber ))
277
- if err != nil {
278
- log .Error (err , "failed to load the loadbalancer port object, cannot proceed with deletion" )
279
- return err
280
- }
281
-
282
- resp , err := e .deleteListenerPort (ctx , lbPort .GetId ())
283
- if err != nil {
284
- log .Error (err , "LB Port Delete Failed" , "EMLB ID" , lb .GetId (), "Port ID" , lbPort .GetId (), "Response Body" , resp .Body )
285
- return err
286
- }
287
-
288
- resp , err = e .deleteLoadBalancer (ctx , lb .GetId ())
260
+ resp , err := e .deleteLoadBalancer (ctx , lb .GetId ())
289
261
if err != nil {
290
262
log .Error (err , "LB Delete Failed" , "EMLB ID" , lb .GetId (), "Response Body" , resp .Body )
291
263
return err
@@ -296,6 +268,7 @@ func (e *EMLB) DeleteLoadBalancer(ctx context.Context, clusterScope *scope.Clust
296
268
297
269
// DeleteLoadBalancerOrigin deletes the Equinix Metal Load Balancer associated with a given ClusterScope.
298
270
func (e * EMLB ) DeleteLoadBalancerOrigin (ctx context.Context , machineScope * scope.MachineScope ) error {
271
+ // Initially, we're creating a single pool per origin, logic below needs to be updated if we move to a shared load balancer pool model.
299
272
log := ctrl .LoggerFrom (ctx )
300
273
301
274
clusterName := machineScope .Cluster .Name
@@ -306,13 +279,7 @@ func (e *EMLB) DeleteLoadBalancerOrigin(ctx context.Context, machineScope *scope
306
279
return fmt .Errorf ("no Equinix Metal Load Balancer Pool found in machine's annotations" )
307
280
}
308
281
309
- // Make sure the machine has an EMLB Origin ID in its packetMachine annotations, otherwise abort.
310
- lbOriginID , exists := machineScope .PacketMachine .Annotations [loadBalancerOriginIDAnnotation ]
311
- if ! exists || (lbOriginID == "" ) {
312
- return fmt .Errorf ("no Equinix Metal Load Balancer Origin found in machine's annotations" )
313
- }
314
-
315
- log .Info ("Deleting EMLB Origin from Pool" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Pool ID" , lbPoolID , "Origin ID" , lbOriginID )
282
+ log .Info ("Deleting EMLB Origin from Pool" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Pool ID" , lbPoolID )
316
283
317
284
// Fetch the Load Balancer Pool object.
318
285
lbPool , err := e .getLoadBalancerPool (ctx , lbPoolID )
@@ -321,17 +288,9 @@ func (e *EMLB) DeleteLoadBalancerOrigin(ctx context.Context, machineScope *scope
321
288
return err
322
289
}
323
290
324
- resp , err := e .deleteOrigin (ctx , lbOriginID )
325
- if err != nil {
326
- log .Error (err , "LB Origin Delete Failed" , "Pool ID" , lbPool .GetId (), "Origin ID" , lbOriginID , "Response Body" , resp .Body )
327
- return err
328
- }
329
-
330
- // TODO: Validate pool is empty
331
-
332
291
log .Info ("Deleting EMLB Pool" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Pool ID" , lbPoolID )
333
292
334
- resp , err = e .deletePool (ctx , lbPool .GetId ())
293
+ resp , err : = e .deletePool (ctx , lbPool .GetId ())
335
294
if err != nil {
336
295
log .Error (err , "LB Pool Delete Failed" , "Pool ID" , lbPool .GetId (), "Response Body" , resp .Body )
337
296
return err
@@ -521,21 +480,11 @@ func (e *EMLB) deleteLoadBalancer(ctx context.Context, lbID string) (*http.Respo
521
480
return e .client .LoadBalancersApi .DeleteLoadBalancer (ctx , lbID ).Execute ()
522
481
}
523
482
524
- func (e * EMLB ) deleteListenerPort (ctx context.Context , portID string ) (* http.Response , error ) {
525
- ctx = context .WithValue (ctx , lbaas .ContextOAuth2 , e .tokenExchanger )
526
- return e .client .PortsApi .DeleteLoadBalancerPort (ctx , portID ).Execute ()
527
- }
528
-
529
483
func (e * EMLB ) deletePool (ctx context.Context , poolID string ) (* http.Response , error ) {
530
484
ctx = context .WithValue (ctx , lbaas .ContextOAuth2 , e .tokenExchanger )
531
485
return e .client .PoolsApi .DeleteLoadBalancerPool (ctx , poolID ).Execute ()
532
486
}
533
487
534
- func (e * EMLB ) deleteOrigin (ctx context.Context , originID string ) (* http.Response , error ) {
535
- ctx = context .WithValue (ctx , lbaas .ContextOAuth2 , e .tokenExchanger )
536
- return e .client .OriginsApi .DeleteLoadBalancerOrigin (ctx , originID ).Execute ()
537
- }
538
-
539
488
func (e * EMLB ) updateListenerPort (ctx context.Context , poolID , lbPortID string ) (* lbaas.LoadBalancerPort , error ) {
540
489
ctx = context .WithValue (ctx , lbaas .ContextOAuth2 , e .tokenExchanger )
541
490
0 commit comments