Skip to content

Commit 00bb73f

Browse files
committed
reduce probability of maps conncurrent iteration and write (#5585)
Signed-off-by: Mengxin Liu <[email protected]> (cherry picked from commit ab4ebc3)
1 parent 4f1bdd7 commit 00bb73f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pkg/controller/service.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package controller
33
import (
44
"context"
55
"fmt"
6+
"maps"
67
"net"
78
"reflect"
89
"slices"
@@ -281,19 +282,20 @@ func (c *Controller) handleUpdateService(svcObject *updateSvcObject) error {
281282
klog.Errorf("failed to get LB %s: %v", lbName, err)
282283
return err
283284
}
284-
klog.V(3).Infof("existing vips of LB %s: %v", lbName, lb.Vips)
285+
lbVIPs := maps.Clone(lb.Vips)
286+
klog.V(3).Infof("existing vips of LB %s: %v", lbName, lbVIPs)
285287
for _, vip := range svcVips {
286288
if err := c.OVNNbClient.LoadBalancerDeleteVip(oLbName, vip, ignoreHealthCheck); err != nil {
287289
klog.Errorf("failed to delete vip %s from LB %s: %v", vip, oLbName, err)
288290
return err
289291
}
290292

291-
if _, ok := lb.Vips[vip]; !ok {
293+
if _, ok := lbVIPs[vip]; !ok {
292294
klog.Infof("add vip %s to LB %s", vip, lbName)
293295
needUpdateEndpointQueue = true
294296
}
295297
}
296-
for vip := range lb.Vips {
298+
for vip := range lbVIPs {
297299
if ip := parseVipAddr(vip); (slices.Contains(ips, ip) && !slices.Contains(svcVips, vip)) || slices.Contains(ipsToDel, ip) {
298300
klog.Infof("remove stale vip %s from LB %s", vip, lbName)
299301
if err := c.OVNNbClient.LoadBalancerDeleteVip(lbName, vip, ignoreHealthCheck); err != nil {
@@ -312,8 +314,9 @@ func (c *Controller) handleUpdateService(svcObject *updateSvcObject) error {
312314
klog.Errorf("failed to get LB %s: %v", oLbName, err)
313315
return err
314316
}
315-
klog.V(3).Infof("existing vips of LB %s: %v", oLbName, lb.Vips)
316-
for vip := range oLb.Vips {
317+
oLbVIPs := maps.Clone(oLb.Vips)
318+
klog.V(3).Infof("existing vips of LB %s: %v", oLbName, oLbVIPs)
319+
for vip := range oLbVIPs {
317320
if ip := parseVipAddr(vip); slices.Contains(ips, ip) || slices.Contains(ipsToDel, ip) {
318321
klog.Infof("remove stale vip %s from LB %s", vip, oLbName)
319322
if err = c.OVNNbClient.LoadBalancerDeleteVip(oLbName, vip, ignoreHealthCheck); err != nil {

0 commit comments

Comments
 (0)