@@ -3,10 +3,11 @@ package clb
33import (
44 "context"
55 "encoding/json"
6- "errors"
76 "fmt"
87 "time"
98
9+ "github.com/pkg/errors"
10+
1011 "github.com/imroc/tke-extend-network-controller/pkg/clusterinfo"
1112 "github.com/imroc/tke-extend-network-controller/pkg/util"
1213 vpcpkg "github.com/imroc/tke-extend-network-controller/pkg/vpc"
@@ -171,22 +172,21 @@ type CLBInfo struct {
171172}
172173
173174func BatchGetClbInfo (ctx context.Context , lbIds []string , region string ) (info map [string ]* CLBInfo , err error ) {
174- log .FromContext (ctx ).V (10 ).Info ("BatchGetClbInfo" , "lbIds" , lbIds )
175- client := GetClient (region )
176- req := clb .NewDescribeLoadBalancersRequest ()
177- req .LoadBalancerIds = common .StringPtrs (lbIds )
178- before := time .Now ()
179- resp , err := client .DescribeLoadBalancersWithContext (ctx , req )
180- LogAPI (ctx , "DescribeLoadBalancers" , req , resp , time .Since (before ), err )
181- if err != nil {
175+ res , err := ApiCall (context .Background (), "DescribeLoadBalancers" , region , func (ctx context.Context , client * clb.Client ) (req * clb.DescribeLoadBalancersRequest , res * clb.DescribeLoadBalancersResponse , err error ) {
176+ req = clb .NewDescribeLoadBalancersRequest ()
177+ req .LoadBalancerIds = common .StringPtrs (lbIds )
178+ res , err = client .DescribeLoadBalancersWithContext (ctx , req )
182179 return
180+ })
181+ if err != nil {
182+ return nil , errors .WithStack (err )
183183 }
184- if * resp .Response .TotalCount == 0 || len (resp .Response .LoadBalancerSet ) == 0 {
184+ if * res .Response .TotalCount == 0 || len (res .Response .LoadBalancerSet ) == 0 {
185185 return
186186 }
187187 info = make (map [string ]* CLBInfo )
188188 insIds := []* string {}
189- for _ , ins := range resp .Response .LoadBalancerSet {
189+ for _ , ins := range res .Response .LoadBalancerSet {
190190 lbInfo := & CLBInfo {
191191 LoadbalancerID : * ins .LoadBalancerId ,
192192 LoadbalancerName : * ins .LoadBalancerName ,
@@ -203,23 +203,25 @@ func BatchGetClbInfo(ctx context.Context, lbIds []string, region string) (info m
203203 insIds = append (insIds , ins .LoadBalancerId )
204204 }
205205 vpcClient := vpcpkg .GetClient (region )
206- addrReq := vpc . NewDescribeAddressesRequest ()
207- addrReq . Filters = [] * vpc.Filter {
208- {
209- Name : common . StringPtr ( "instance-id" ),
210- Values : insIds ,
211- } ,
212- }
213- addrResp , err := vpcClient . DescribeAddressesWithContext ( ctx , addrReq )
214- if err != nil {
206+ addrResp , err := ApiCall ( context . Background (), "DescribeAddresses" , region , func ( ctx context. Context , client * clb. Client ) ( req * vpc. DescribeAddressesRequest , res * vpc. DescribeAddressesResponse , err error ) {
207+ req = vpc .NewDescribeAddressesRequest ()
208+ req . Filters = [] * vpc. Filter {
209+ {
210+ Name : common . StringPtr ( "instance-id" ) ,
211+ Values : insIds ,
212+ },
213+ }
214+ res , err = vpcClient . DescribeAddressesWithContext ( ctx , req )
215215 return
216+ })
217+ if err != nil {
218+ return nil , errors .WithStack (err )
216219 }
217- vpcpkg .LogAPI (ctx , "DescribeAddresses" , addrReq , addrResp , err )
218220 for _ , addr := range addrResp .Response .AddressSet {
219- log .FromContext (ctx ).Info ("got clb eip addr" , "instanceId" , addr .InstanceId )
221+ log .FromContext (ctx ).V ( 3 ). Info ("got clb eip addr" , "instanceId" , addr .InstanceId )
220222 if addr .InstanceId != nil {
221223 if lbInfo , ok := info [* addr .InstanceId ]; ok {
222- log .FromContext (ctx ).Info ("set clb eip addr" , "instanceId" , addr .InstanceId , "eip" , * addr .AddressIp )
224+ log .FromContext (ctx ).V ( 3 ). Info ("set clb eip addr" , "instanceId" , addr .InstanceId , "eip" , * addr .AddressIp )
223225 lbInfo .Ips = []string {* addr .AddressIp }
224226 }
225227 }
0 commit comments