Skip to content

Commit f02dec7

Browse files
committed
ensureQuota
Signed-off-by: roc <[email protected]>
1 parent 4122d07 commit f02dec7

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

internal/controller/clbportpool_controller.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -285,39 +285,44 @@ func (r *CLBPortPoolReconciler) ensureLb(ctx context.Context, pool *networkingv1
285285
return nil
286286
}
287287

288+
func (r *CLBPortPoolReconciler) ensureQuota(ctx context.Context, pool *networkingv1alpha1.CLBPortPool) error {
289+
quota := util.GetValue(pool.Spec.ListenerQuota)
290+
if quota == 0 {
291+
q, err := clb.Quota.GetQuota(ctx, pool.GetRegion(), clb.TOTAL_LISTENER_QUOTA)
292+
if err != nil {
293+
return errors.WithStack(err)
294+
}
295+
quota = uint16(q)
296+
}
297+
if pool.Status.Quota != quota {
298+
pool.Status.Quota = quota
299+
if err := r.Status().Update(ctx, pool); err != nil {
300+
return errors.WithStack(err)
301+
}
302+
portpool.Allocator.EnsureLbIds(name string, lbKeys []portpool.LBKey)
303+
}
304+
return nil
305+
}
306+
288307
// 同步端口池
289308
func (r *CLBPortPoolReconciler) sync(ctx context.Context, pool *networkingv1alpha1.CLBPortPool) (result ctrl.Result, err error) {
290309
// 确保分配器缓存中存在该 port pool,放在最开头,避免同时创建 CLBPortPool 和 CLBBinding 导致分配端口时找不到 pool
291310
portpool.Allocator.AddPoolIfNotExists(pool.Name)
292311

293312
needUpdateStatus := false
294313

295-
// 确定 quota
296-
if pool.Status.Quota == 0 {
297-
quota := util.GetValue(pool.Spec.ListenerQuota)
298-
if quota == 0 {
299-
q, err := clb.Quota.GetQuota(ctx, pool.GetRegion(), clb.TOTAL_LISTENER_QUOTA)
300-
if err != nil {
301-
return result, errors.WithStack(err)
302-
}
303-
quota = uint16(q)
304-
}
305-
pool.Status.Quota = quota
306-
needUpdateStatus = true
307-
}
308-
309314
// 初始化状态
310315
if pool.Status.State == "" {
311-
pool.Status.State = networkingv1alpha1.CLBPortPoolStatePending
312-
needUpdateStatus = true
313-
}
314-
315-
if needUpdateStatus {
316-
if err := r.Status().Update(ctx, pool); err != nil {
316+
if err := r.ensureState(ctx, pool, networkingv1alpha1.CLBPortPoolStatePending); err != nil {
317317
return result, errors.WithStack(err)
318318
}
319319
}
320320

321+
// 同步 quota
322+
if err := r.ensureQuota(ctx, pool); err != nil {
323+
return result, errors.WithStack(err)
324+
}
325+
321326
// 确保 lb 列表可用
322327
if err := r.ensureLb(ctx, pool); err != nil {
323328
return result, errors.WithStack(err)

0 commit comments

Comments
 (0)