Skip to content

Commit e2ee378

Browse files
committed
some fix
* ensure requeue if port pool not found * ignore lb not found error when cleaup clb binding Signed-off-by: roc <[email protected]>
1 parent d429cd6 commit e2ee378

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

internal/controller/clbbinding.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,6 @@ func (r *CLBBindingReconciler[T]) sync(ctx context.Context, bd T) (result ctrl.R
6464
// 确保所有端口都已分配且绑定 obj
6565
if err := r.ensureCLBBinding(ctx, bd); err != nil {
6666
errCause := errors.Cause(err)
67-
if e, ok := errCause.(*portpool.ErrPoolNotFound); ok { // 分配端口时发现端口池不在分配器缓存中
68-
// 看是否有这个端口池对象
69-
poolName := e.Pool
70-
pp := &networkingv1alpha1.CLBPortPool{}
71-
if err := r.Client.Get(ctx, client.ObjectKey{Name: poolName}, pp); err != nil {
72-
if apierrors.IsNotFound(err) { // 端口池确实不存在,更新状态和 event
73-
r.Recorder.Event(bd.GetObject(), corev1.EventTypeWarning, "PoolNotFound", "port pool not found, please check the port pool name")
74-
if err := r.ensureState(ctx, bd, networkingv1alpha1.CLBBindingStatePortPoolNotFound); err != nil {
75-
return result, errors.WithStack(err)
76-
}
77-
return result, nil
78-
}
79-
return result, errors.WithStack(err)
80-
} else { // 端口池存在,但还没更新到分配器缓存,忽略,等待端口池就绪后会自动触发重新对账
81-
return result, nil
82-
}
83-
}
8467
// 1. 扩容了 lb、或者正在扩容,忽略,因为会自动触发对账。
8568
// 2. 端口不足无法分配、端口池不存在,忽略,因为如果端口池不改正或扩容 lb,无法重试成功。
8669
// 3. lb 被删除或监听器被删除,自动移除了 status 中的记录,需重新入队对账。
@@ -98,6 +81,24 @@ func (r *CLBBindingReconciler[T]) sync(ctx context.Context, bd T) (result ctrl.R
9881
}
9982
return result, nil
10083
}
84+
// 分配端口时发现端口池不在分配器缓存中
85+
if e, ok := errCause.(*portpool.ErrPoolNotFound); ok {
86+
// 看是否有这个端口池对象
87+
poolName := e.Pool
88+
pp := &networkingv1alpha1.CLBPortPool{}
89+
if err := r.Client.Get(ctx, client.ObjectKey{Name: poolName}, pp); err != nil {
90+
if apierrors.IsNotFound(err) { // 端口池确实不存在,更新状态和 event
91+
r.Recorder.Eventf(bd.GetObject(), corev1.EventTypeWarning, "PoolNotFound", "port pool %q not found, please check the port pool name", poolName)
92+
if err := r.ensureState(ctx, bd, networkingv1alpha1.CLBBindingStatePortPoolNotFound); err != nil {
93+
return result, errors.WithStack(err)
94+
}
95+
}
96+
return result, errors.WithStack(err)
97+
} else { // 端口池存在,但还没更新到分配器缓存,忽略,等待端口池就绪后会自动触发重新对账
98+
result.RequeueAfter = 20 * time.Microsecond
99+
return result, nil
100+
}
101+
}
101102
// 如果是被云 API 限流(默认每秒 20 qps 限制),1s 后重新入队
102103
if clb.IsRequestLimitExceededError(errCause) {
103104
result.RequeueAfter = time.Second
@@ -739,6 +740,9 @@ func (r *CLBBindingReconciler[T]) cleanup(ctx context.Context, bd T) (result ctr
739740
func (r *CLBBindingReconciler[T]) cleanupPortBinding(ctx context.Context, binding *networkingv1alpha1.PortBindingStatus) error {
740741
lis, err := clb.GetListenerByIdOrPort(ctx, binding.Region, binding.LoadbalancerId, binding.ListenerId, int64(binding.LoadbalancerPort), binding.Protocol)
741742
if err != nil {
743+
if clb.IsLoadBalancerNotExistsError(err) { // 忽略 lbid 不存在的错误,就当清理成功
744+
return nil
745+
}
742746
return errors.WithStack(err)
743747
}
744748
releasePort := func() {

pkg/clb/batch-target.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,8 @@ func startDescribeTargetsProccessor(concurrent int) {
113113
targetsMap[*backend.ListenerId] = targets
114114
}
115115
for _, task := range tasks {
116-
targets := targetsMap[task.ListenerId]
117-
if targets == nil {
118-
task.Result <- &DescribeTargetsResult{
119-
Err: fmt.Errorf("no targets result for %s/%s", task.LbId, task.ListenerId),
120-
}
121-
} else {
122-
task.Result <- &DescribeTargetsResult{
123-
Targets: targetsMap[task.ListenerId],
124-
}
116+
task.Result <- &DescribeTargetsResult{
117+
Targets: targetsMap[task.ListenerId],
125118
}
126119
}
127120
})

0 commit comments

Comments
 (0)