From 6c7f2cd7908d3930ad97e7b6f37de63fe4fd4b08 Mon Sep 17 00:00:00 2001 From: pavel <36902936+pavel-github@users.noreply.github.com> Date: Thu, 27 Jun 2024 22:46:21 +0200 Subject: [PATCH] fix: clean up previously defined forwarding rules when updating --- internal/xelon/load_balancers.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/xelon/load_balancers.go b/internal/xelon/load_balancers.go index 21f609e..2e0061d 100644 --- a/internal/xelon/load_balancers.go +++ b/internal/xelon/load_balancers.go @@ -408,12 +408,25 @@ func (l *loadBalancers) fetchXelonLoadBalancerForwardingRules(ctx context.Contex } func (l *loadBalancers) updateLoadBalancer(ctx context.Context, xlb *xelonLoadBalancer, service *v1.Service) error { - logger := configureLogger(ctx, "retrieveXelonLoadBalancer").WithValues( + logger := configureLogger(ctx, "updateLoadBalancer").WithValues( "service", getServiceNameWithNamespace(service), ) patcher := newServicePatcher(l.client.k8s, service) defer func() { _ = patcher.Patch(ctx) }() + // clean up old rules + if forwardingRuleIDs, ok := service.Annotations[serviceAnnotationLoadBalancerClusterForwardingRuleIDs]; ok && forwardingRuleIDs != "" { + logger.Info("Deleting previously specified forwarding rules", "forwarding_rules_ids", forwardingRuleIDs) + definedForwardingRuleIDs := strings.Split(forwardingRuleIDs, ",") + + for _, definedForwardingRuleID := range definedForwardingRuleIDs { + _, err := l.client.xelon.LoadBalancerClusters.DeleteForwardingRule(ctx, xlb.clusterID, xlb.virtualIPID, definedForwardingRuleID) + if err != nil { + return err + } + } + } + // build forwarding rules logger.Info("Building forwarding rules request") var forwardingRules []xelon.LoadBalancerClusterForwardingRule