Skip to content

Commit

Permalink
alibabacloud: use NextToken and MaxResults to list instance types
Browse files Browse the repository at this point in the history
Currently, there is no paging query used to retrieve instance types.
When there are many instance types, some instances can not obtain ENI
and IPPerENI limits. The cilium operator log is as follows.
```
level=warning msg="Unable to maintain ip pool of node" error="Unable
to determine limits" instanceID=<ID> name=<NAME> subsys=ipam
```
This patch fixes this problem by using NextToken and MaxResults for
paging query.

Signed-off-by: Hao Zhang <hao.zhang.am.i@gmail.com>
  • Loading branch information
haozhangami authored and ti-mo committed Jun 20, 2023
1 parent 29b75ee commit 95b264d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions pkg/alibabacloud/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,30 @@ func (c *Client) GetVPCs(ctx context.Context) (ipamTypes.VirtualNetworkMap, erro

// GetInstanceTypes returns all the known ECS instance types in the configured region
func (c *Client) GetInstanceTypes(ctx context.Context) ([]ecs.InstanceType, error) {
var result []ecs.InstanceType
req := ecs.CreateDescribeInstanceTypesRequest()
resp, err := c.ecsClient.DescribeInstanceTypes(req)
if err != nil {
return nil, err
// When there are many instance types, some instance limits can not be queried,
// so use NextToken and MaxResults for paging query.
// MaxResults is the number of entries on each page, the maximum value of this parameter is 100.
// Ref: https://www.alibabacloud.com/help/en/elastic-compute-service/latest/describeinstancetypes
req.MaxResults = requests.NewInteger(100)
for {
resp, err := c.ecsClient.DescribeInstanceTypes(req)
if err != nil {
return nil, err
}

for _, v := range resp.InstanceTypes.InstanceType {
result = append(result, v)
}

if resp.NextToken == "" {
break
}
req.NextToken = resp.NextToken
}

return resp.InstanceTypes.InstanceType, nil
return result, nil
}

// GetSecurityGroups return all sg
Expand Down

0 comments on commit 95b264d

Please sign in to comment.