Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alibabacloud: use DescribeVSwitches to get vswitch tags #23635

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 3 additions & 40 deletions pkg/alibabacloud/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -125,45 +117,16 @@ 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
}
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
}

Expand Down