@@ -64,23 +64,6 @@ func (r *CLBBindingReconciler[T]) sync(ctx context.Context, bd T) (result ctrl.R
64
64
// 确保所有端口都已分配且绑定 obj
65
65
if err := r .ensureCLBBinding (ctx , bd ); err != nil {
66
66
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
- }
84
67
// 1. 扩容了 lb、或者正在扩容,忽略,因为会自动触发对账。
85
68
// 2. 端口不足无法分配、端口池不存在,忽略,因为如果端口池不改正或扩容 lb,无法重试成功。
86
69
// 3. lb 被删除或监听器被删除,自动移除了 status 中的记录,需重新入队对账。
@@ -98,6 +81,24 @@ func (r *CLBBindingReconciler[T]) sync(ctx context.Context, bd T) (result ctrl.R
98
81
}
99
82
return result , nil
100
83
}
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
+ }
101
102
// 如果是被云 API 限流(默认每秒 20 qps 限制),1s 后重新入队
102
103
if clb .IsRequestLimitExceededError (errCause ) {
103
104
result .RequeueAfter = time .Second
@@ -739,6 +740,9 @@ func (r *CLBBindingReconciler[T]) cleanup(ctx context.Context, bd T) (result ctr
739
740
func (r * CLBBindingReconciler [T ]) cleanupPortBinding (ctx context.Context , binding * networkingv1alpha1.PortBindingStatus ) error {
740
741
lis , err := clb .GetListenerByIdOrPort (ctx , binding .Region , binding .LoadbalancerId , binding .ListenerId , int64 (binding .LoadbalancerPort ), binding .Protocol )
741
742
if err != nil {
743
+ if clb .IsLoadBalancerNotExistsError (err ) { // 忽略 lbid 不存在的错误,就当清理成功
744
+ return nil
745
+ }
742
746
return errors .WithStack (err )
743
747
}
744
748
releasePort := func () {
0 commit comments