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

add singleflight for DescribeInstanceTypes #659

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pkg/aliyun/client/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"time"

"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"golang.org/x/sync/singleflight"
"k8s.io/apimachinery/pkg/util/cache"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -108,6 +109,8 @@
type ECSLimitProvider struct {
cache cache.LRUExpireCache
ttl time.Duration

g singleflight.Group
}

func NewECSLimitProvider() *ECSLimitProvider {
Expand All @@ -126,15 +129,25 @@
if ok {
return v.(*Limits), nil
}

var req []string
if instanceType != "" {
req = append(req, instanceType)
}
ins, err := a.DescribeInstanceTypes(context.Background(), req)

v, err, _ := d.g.Do(instanceType, func() (interface{}, error) {
ins, err := a.DescribeInstanceTypes(context.Background(), req)
if err != nil {
return nil, err

Check warning on line 141 in pkg/aliyun/client/limit.go

View check run for this annotation

Codecov / codecov/patch

pkg/aliyun/client/limit.go#L138-L141

Added lines #L138 - L141 were not covered by tests
}
return ins, nil

Check warning on line 143 in pkg/aliyun/client/limit.go

View check run for this annotation

Codecov / codecov/patch

pkg/aliyun/client/limit.go#L143

Added line #L143 was not covered by tests
})
if err != nil {
return nil, err
}

ins := v.([]ecs.InstanceType)

Check warning on line 149 in pkg/aliyun/client/limit.go

View check run for this annotation

Codecov / codecov/patch

pkg/aliyun/client/limit.go#L149

Added line #L149 was not covered by tests

for _, instanceTypeInfo := range ins {
instanceTypeID := instanceTypeInfo.InstanceTypeId

Expand Down
Loading