Skip to content

Commit

Permalink
fix: clean up previously defined forwarding rules when updating
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-github committed Jun 27, 2024
1 parent 7a530d4 commit 6c7f2cd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/xelon/load_balancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c7f2cd

Please sign in to comment.