@@ -497,25 +497,40 @@ func (c *OVNNbClient) LoadBalancerDeleteIPPortMapping(lbName, vipEndpoint string
497497
498498// LoadBalancerUpdateIPPortMapping update load balancer ip port mapping
499499func (c * OVNNbClient ) LoadBalancerUpdateIPPortMapping (lbName , vipEndpoint string , ipPortMappings map [string ]string ) error {
500- if len (ipPortMappings ) != 0 {
501- ops , err := c .LoadBalancerOp (
502- lbName ,
503- func (lb * ovnnb.LoadBalancer ) []model.Mutation {
504- return []model.Mutation {
505- {
506- Field : & lb .IPPortMappings ,
507- Value : ipPortMappings ,
508- Mutator : ovsdb .MutateOperationInsert ,
509- },
500+ ops , err := c .LoadBalancerOp (
501+ lbName ,
502+ func (lb * ovnnb.LoadBalancer ) []model.Mutation {
503+ // Delete from the IPPortMappings any outdated mapping
504+ mappingToDelete := make (map [string ]string )
505+ for portIP , portMapVip := range lb .IPPortMappings {
506+ if _ , ok := ipPortMappings [portIP ]; ! ok {
507+ mappingToDelete [portIP ] = portMapVip
510508 }
511- },
512- )
513- if err != nil {
514- return fmt .Errorf ("failed to generate operations when adding ip port mapping with vip %v to load balancers %s: %w" , vipEndpoint , lbName , err )
515- }
516- if err = c .Transact ("lb-add" , ops ); err != nil {
517- return fmt .Errorf ("failed to add ip port mapping with vip %v to load balancers %s: %w" , vipEndpoint , lbName , err )
518- }
509+ }
510+
511+ if len (mappingToDelete ) > 0 {
512+ klog .Infof ("deleting outdated entry from ipportmapping %v" , mappingToDelete )
513+ }
514+
515+ return []model.Mutation {
516+ {
517+ Field : & lb .IPPortMappings ,
518+ Value : mappingToDelete ,
519+ Mutator : ovsdb .MutateOperationDelete ,
520+ },
521+ {
522+ Field : & lb .IPPortMappings ,
523+ Value : ipPortMappings ,
524+ Mutator : ovsdb .MutateOperationInsert ,
525+ },
526+ }
527+ },
528+ )
529+ if err != nil {
530+ return fmt .Errorf ("failed to generate operations when adding ip port mapping with vip %v to load balancers %s: %w" , vipEndpoint , lbName , err )
531+ }
532+ if err = c .Transact ("lb-add" , ops ); err != nil {
533+ return fmt .Errorf ("failed to add ip port mapping with vip %v to load balancers %s: %w" , vipEndpoint , lbName , err )
519534 }
520535 return nil
521536}
0 commit comments