Skip to content

Commit c56cfd8

Browse files
SkalaNetworkszhangzujian
authored andcommitted
fix(slr): deleting old entries from ipmapping to avoid clogging loadbalancer (#5380)
Signed-off-by: SkalaNetworks <[email protected]> Signed-off-by: zhangzujian <[email protected]>
1 parent 985e294 commit c56cfd8

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

pkg/ovs/ovn-nb-load_balancer.go

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -483,25 +483,40 @@ func (c *OVNNbClient) LoadBalancerDeleteIPPortMapping(lbName, vipEndpoint string
483483

484484
// LoadBalancerUpdateIPPortMapping update load balancer ip port mapping
485485
func (c *OVNNbClient) LoadBalancerUpdateIPPortMapping(lbName, vipEndpoint string, ipPortMappings map[string]string) error {
486-
if len(ipPortMappings) != 0 {
487-
ops, err := c.LoadBalancerOp(
488-
lbName,
489-
func(lb *ovnnb.LoadBalancer) []model.Mutation {
490-
return []model.Mutation{
491-
{
492-
Field: &lb.IPPortMappings,
493-
Value: ipPortMappings,
494-
Mutator: ovsdb.MutateOperationInsert,
495-
},
486+
ops, err := c.LoadBalancerOp(
487+
lbName,
488+
func(lb *ovnnb.LoadBalancer) []model.Mutation {
489+
// Delete from the IPPortMappings any outdated mapping
490+
mappingToDelete := make(map[string]string)
491+
for portIP, portMapVip := range lb.IPPortMappings {
492+
if _, ok := ipPortMappings[portIP]; !ok {
493+
mappingToDelete[portIP] = portMapVip
496494
}
497-
},
498-
)
499-
if err != nil {
500-
return fmt.Errorf("failed to generate operations when adding ip port mapping with vip %v to load balancers %s: %v", vipEndpoint, lbName, err)
501-
}
502-
if err = c.Transact("lb-add", ops); err != nil {
503-
return fmt.Errorf("failed to add ip port mapping with vip %v to load balancers %s: %v", vipEndpoint, lbName, err)
504-
}
495+
}
496+
497+
if len(mappingToDelete) > 0 {
498+
klog.Infof("deleting outdated entry from ipportmapping %v", mappingToDelete)
499+
}
500+
501+
return []model.Mutation{
502+
{
503+
Field: &lb.IPPortMappings,
504+
Value: mappingToDelete,
505+
Mutator: ovsdb.MutateOperationDelete,
506+
},
507+
{
508+
Field: &lb.IPPortMappings,
509+
Value: ipPortMappings,
510+
Mutator: ovsdb.MutateOperationInsert,
511+
},
512+
}
513+
},
514+
)
515+
if err != nil {
516+
return fmt.Errorf("failed to generate operations when adding ip port mapping with vip %v to load balancers %s: %w", vipEndpoint, lbName, err)
517+
}
518+
if err = c.Transact("lb-add", ops); err != nil {
519+
return fmt.Errorf("failed to add ip port mapping with vip %v to load balancers %s: %w", vipEndpoint, lbName, err)
505520
}
506521
return nil
507522
}

0 commit comments

Comments
 (0)