@@ -156,7 +156,7 @@ func (e *EMLB) ReconcileVIPOrigin(ctx context.Context, machineScope *scope.Machi
156156 }
157157
158158 // Fetch the Load Balancer object.
159- lb , err := e .getLoadBalancer (ctx , lbID )
159+ lb , _ , err := e .getLoadBalancer (ctx , lbID )
160160 if err != nil {
161161 return err
162162 }
@@ -247,18 +247,18 @@ func (e *EMLB) DeleteLoadBalancer(ctx context.Context, clusterScope *scope.Clust
247247 return nil
248248 }
249249
250- log .Info ("Deleting EMLB" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Load Balancer ID" , lbID )
251-
252250 // Fetch the Load Balancer object.
253251 // 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" )
257255 return err
258256 }
259257
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 ) {
262262 log .Error (err , "LB Delete Failed" , "EMLB ID" , lb .GetId (), "Response Body" , resp .Body )
263263 return err
264264 }
@@ -279,19 +279,17 @@ func (e *EMLB) DeleteLoadBalancerOrigin(ctx context.Context, machineScope *scope
279279 return fmt .Errorf ("no Equinix Metal Load Balancer Pool found in machine's annotations" )
280280 }
281281
282- log .Info ("Deleting EMLB Origin from Pool" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Pool ID" , lbPoolID )
283-
284282 // 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" )
288286 return err
289287 }
290288
291289 log .Info ("Deleting EMLB Pool" , "Cluster Metro" , e .metro , "Cluster Name" , clusterName , "Project ID" , e .projectID , "Pool ID" , lbPoolID )
292290
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 ) {
295293 log .Error (err , "LB Pool Delete Failed" , "Pool ID" , lbPool .GetId (), "Response Body" , resp .Body )
296294 return err
297295 }
@@ -300,11 +298,11 @@ func (e *EMLB) DeleteLoadBalancerOrigin(ctx context.Context, machineScope *scope
300298}
301299
302300// 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 ) {
304302 ctx = context .WithValue (ctx , lbaas .ContextOAuth2 , e .tokenExchanger )
305303
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
308306}
309307
310308// 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
316314}
317315
318316// 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 ) {
320318 ctx = context .WithValue (ctx , lbaas .ContextOAuth2 , e .tokenExchanger )
321319
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
324322}
325323
326324// 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
424422 }
425423
426424 // 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 )
428426 if err != nil {
429427 return nil , nil , err
430428 }
0 commit comments