-
Notifications
You must be signed in to change notification settings - Fork 143
feat(tke): [116471075]optimize cluster instance queries #2560
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
datasource/tencentcloud_kubernetes_cluster_instances: optimize cluster instance queries | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2716,20 +2716,38 @@ func (me *TkeService) DescribeKubernetesClusterInstancesByFilter(ctx context.Con | |
} | ||
} | ||
|
||
ratelimit.Check(request.GetAction()) | ||
var offset int64 = 0 | ||
var limit int64 = 20 | ||
var total int64 = -1 | ||
|
||
response, err := me.client.UseTkeClient().DescribeClusterInstances(request) | ||
if err != nil { | ||
errRet = err | ||
return | ||
} | ||
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) | ||
for { | ||
if total >= 0 && offset >= total { | ||
break | ||
} | ||
request.Offset = &offset | ||
request.Limit = &limit | ||
ratelimit.Check(request.GetAction()) | ||
|
||
if len(response.Response.InstanceSet) < 1 { | ||
return | ||
} | ||
response, err := me.client.UseTkeClient().DescribeClusterInstances(request) | ||
if err != nil { | ||
errRet = err | ||
return | ||
} | ||
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) | ||
|
||
if total < 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里为啥需要判断 total < 0 呢 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 获取所有数据数量存入total There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 去掉 if total < 0 { 这段会有问题吗 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果去掉,每次都会给total赋值,加上判断只会在第一次查询后赋值,当然去掉也没问题 |
||
total = int64(*response.Response.TotalCount) | ||
} | ||
|
||
clusterInstances = response.Response.InstanceSet | ||
if len(response.Response.InstanceSet) == 0 { | ||
// get empty set, we're done | ||
break | ||
} | ||
|
||
offset += limit | ||
|
||
clusterInstances = append(clusterInstances, response.Response.InstanceSet...) | ||
} | ||
return | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为啥需要判断 total >=0 呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
total >=0说明存在数据,然后判断offset >= total以结束循环