Skip to content

Commit 79da4b5

Browse files
committed
never remove bindings when spec changed
Signed-off-by: roc <[email protected]>
1 parent fd4901e commit 79da4b5

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

internal/controller/clbbinding.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ func (r *CLBBindingReconciler[T]) ensurePortAllocated(ctx context.Context, bd cl
675675
Pool: binding.Pool,
676676
}
677677
bindings[key] = binding
678+
newBindings = append(newBindings, *binding)
678679
}
679680

680681
var allocatedPorts portpool.PortAllocations
@@ -709,17 +710,11 @@ LOOP_PORT:
709710
})
710711
}
711712
}
712-
alreadyAllocated := false
713713
for _, key := range keys {
714-
if binding, exists := bindings[key]; exists { // 已分配端口,跳过
715-
delete(bindings, key)
716-
alreadyAllocated = true
717-
newBindings = append(newBindings, *binding)
714+
if _, exists := bindings[key]; exists { // 已分配端口,跳过
715+
continue LOOP_PORT
718716
}
719717
}
720-
if alreadyAllocated {
721-
continue LOOP_PORT
722-
}
723718
// 未分配端口,先检查证书配置
724719
var certId *string
725720
if secretName := port.CertSecretName; secretName != nil && *secretName != "" {
@@ -785,20 +780,6 @@ LOOP_PORT:
785780
// 更新状态失败,释放已分配端口
786781
releasePorts()
787782
return errors.WithStack(err)
788-
} else {
789-
// 因 spec 变更导致已分配的端口被删除,应该释放端口,并且通知端口池以便更新 allocated 数量状态
790-
for _, binding := range bindings {
791-
poolsShouldReconcile[binding.Pool] = struct{}{}
792-
if portpool.Allocator.ReleaseBinding(binding) {
793-
log.FromContext(ctx).Info("release allocated port due to spec changed", "port", binding.LoadbalancerPort, "protocol", binding.Protocol, "pool", binding.Pool, "lb", binding.LoadbalancerId)
794-
} else {
795-
log.FromContext(ctx).Info("try release allocated port due to spec changed but released already", "port", binding.LoadbalancerPort, "protocol", binding.Protocol, "pool", binding.Pool, "lb", binding.LoadbalancerId)
796-
}
797-
}
798-
// 通知所有需要更新 allocated 状态的端口池重新对账
799-
for poolName := range poolsShouldReconcile {
800-
notifyPortPoolReconcile(poolName)
801-
}
802783
}
803784
}
804785
return nil

0 commit comments

Comments
 (0)