From 4269350f5f550546e86d873de702a105b114168f Mon Sep 17 00:00:00 2001 From: Hao Zhang Date: Wed, 8 Feb 2023 08:54:34 -0500 Subject: [PATCH] alibabacloud: use DescribeVSwitches to get vswitch tags Obtaining the vswitch tags through ListTagResources is incomplete, which will cause the IP allocation to fail and require additional queries. Therefore, use DescribeVSwitches to get the vswitch tags. Signed-off-by: Hao Zhang --- pkg/alibabacloud/api/api.go | 43 +++---------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/pkg/alibabacloud/api/api.go b/pkg/alibabacloud/api/api.go index dd4bdbffdf379..40a2b80a83da6 100644 --- a/pkg/alibabacloud/api/api.go +++ b/pkg/alibabacloud/api/api.go @@ -21,18 +21,11 @@ import ( "github.com/cilium/cilium/pkg/api/helpers" "github.com/cilium/cilium/pkg/cidr" ipamTypes "github.com/cilium/cilium/pkg/ipam/types" - "github.com/cilium/cilium/pkg/math" "github.com/cilium/cilium/pkg/spanstat" ) const ( VPCID = "VPCID" - - MaxListByTagSize = 20 - - // MaxResults is the number of entities on each page, - // it ranges from 1 to 50, the default value is 30. - MaxResults = 30 ) var maxAttachRetries = wait.Backoff{ @@ -94,7 +87,6 @@ func (c *Client) GetInstances(ctx context.Context, vpcs ipamTypes.VirtualNetwork // GetVSwitches returns all ecs vSwitches as a subnetMap func (c *Client) GetVSwitches(ctx context.Context) (ipamTypes.SubnetMap, error) { var result ipamTypes.SubnetMap - vsws := []string{} for i := 1; ; { req := vpc.CreateDescribeVSwitchesRequest() req.PageNumber = requests.NewInteger(i) @@ -125,7 +117,9 @@ func (c *Client) GetVSwitches(ctx context.Context) (ipamTypes.SubnetMap, error) AvailableAddresses: int(v.AvailableIpAddressCount), Tags: map[string]string{}, } - vsws = append(vsws, v.VSwitchId) + for _, tag := range v.Tags.Tag { + result[v.VSwitchId].Tags[tag.Key] = tag.Value + } } if resp.TotalCount < resp.PageNumber*resp.PageSize { break @@ -133,37 +127,6 @@ func (c *Client) GetVSwitches(ctx context.Context) (ipamTypes.SubnetMap, error) i++ } - for i := 0; i <= (len(vsws)-1)/MaxListByTagSize; i++ { - var ids []string - - tail := math.IntMin((i+1)*MaxListByTagSize, len(vsws)) - ids = vsws[i*MaxListByTagSize : tail] - - req := vpc.CreateListTagResourcesRequest() - req.ResourceType = "VSWITCH" - req.ResourceId = &ids - req.MaxResults = requests.NewInteger(MaxResults) - c.limiter.Limit(ctx, "ListTagResources") - for { - resp, err := c.vpcClient.ListTagResources(req) - if err != nil { - return nil, err - } - for _, tagRes := range resp.TagResources.TagResource { - subnet, ok := result[tagRes.ResourceId] - if !ok { - continue - } - subnet.Tags[tagRes.TagKey] = tagRes.TagValue - } - if resp.NextToken == "" { - break - } else { - req.NextToken = resp.NextToken - } - } - } - return result, nil }