Skip to content

Commit 642f9b9

Browse files
committed
reconcile lbList in order
Signed-off-by: roc <[email protected]>
1 parent 744f833 commit 642f9b9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

internal/portpool/portpool.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package portpool
33
import (
44
"context"
55
"iter"
6+
"reflect"
67
"slices"
78
"sync"
89

@@ -268,6 +269,11 @@ func (pp *PortPool) AllocatedPorts(lbKey LBKey) uint16 {
268269
func (pp *PortPool) EnsureLbIds(lbKeys []LBKey) {
269270
pp.mu.Lock()
270271
defer pp.mu.Unlock()
272+
273+
if reflect.DeepEqual(lbKeys, pp.lbList) {
274+
return
275+
}
276+
271277
lbToDelete := make(map[LBKey]struct{})
272278
for lbKey := range pp.cache {
273279
lbToDelete[lbKey] = struct{}{}
@@ -285,9 +291,11 @@ func (pp *PortPool) EnsureLbIds(lbKeys []LBKey) {
285291
pp.removeLBUnlock(lbKey)
286292
}
287293
// 添加缺失的lb
288-
for _, lbKey := range lbToAdd {
289-
ppLog.Info("add lb", "lb", lbKey, "pool", pp.Name)
290-
pp.cache[lbKey] = make(map[ProtocolPort]struct{})
291-
pp.lbList = append(pp.lbList, lbKey)
294+
if len(lbToAdd) > 0 {
295+
for _, lbKey := range lbToAdd {
296+
ppLog.Info("add lb", "lb", lbKey, "pool", pp.Name)
297+
pp.cache[lbKey] = make(map[ProtocolPort]struct{})
298+
}
299+
pp.lbList = lbKeys
292300
}
293301
}

0 commit comments

Comments
 (0)