Skip to content

Commit

Permalink
feat: rs同步支持单批次同步超过100监听器 (#1210)
Browse files Browse the repository at this point in the history
--story=120038038
  • Loading branch information
chenjr15 authored Dec 11, 2024
1 parent bcb7fb6 commit 65df776
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,23 @@ func (cli *client) listTargetsFromCloud(kt *kit.Kit, param *SyncBaseParams,
listOpt := &typeslb.TCloudListTargetsOption{
Region: param.Region,
LoadBalancerId: opt.CloudLBID,
ListenerIds: param.CloudIDs,
}
return cli.cloudCli.ListTargets(kt, listOpt)
if len(param.CloudIDs) == 0 {
return cli.cloudCli.ListTargets(kt, listOpt)
}
allTargets := make([]typeslb.TCloudListenerTarget, 0)
// 指定id的情况
for i, lblIDBatch := range slice.Split(param.CloudIDs, constant.TCLBDescribeMax) {
listOpt.ListenerIds = lblIDBatch
targets, err := cli.cloudCli.ListTargets(kt, listOpt)
if err != nil {
logs.Errorf("fail to list targets from cloud, err: %v, idx: %d, cloud_id: %v, rid: %s",
err, i, lblIDBatch, kt.Rid)
return nil, err
}
allTargets = append(allTargets, targets...)
}
return allTargets, nil
}

// 获取云上监听器列表
Expand Down
2 changes: 1 addition & 1 deletion pkg/adaptor/tcloud/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

// ListTargets 获取监听器后端绑定的机器列表信息.
// reference: https://cloud.tencent.com/document/api/214/30686
// reference: https://cloud.tencent.com/document/api/214/30684
func (t *TCloudImpl) ListTargets(kt *kit.Kit, opt *typelb.TCloudListTargetsOption) (
[]typelb.TCloudListenerTarget, error) {

Expand Down
8 changes: 2 additions & 6 deletions pkg/adaptor/types/load-balancer/tcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,14 @@ func (clb TCloudListener) String() string {
type TCloudListTargetsOption struct {
Region string `json:"region" validate:"required"`
LoadBalancerId string `json:"load_balancer_id" validate:"required"`
ListenerIds []string `json:"cloud_ids" validate:"omitempty"`
ListenerIds []string `json:"cloud_ids" validate:"max=20,dive,required"`
Protocol enumor.ProtocolType `json:"protocol" validate:"omitempty"`
Port int64 `json:"port" validate:"omitempty"`
}

// Validate tcloud targets list option.
func (opt TCloudListTargetsOption) Validate() error {
if err := validator.Validate.Struct(opt); err != nil {
return nil
}

return nil
return validator.Validate.Struct(opt)
}

// TCloudListenerTarget for listener target Instance
Expand Down

0 comments on commit 65df776

Please sign in to comment.