mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #19081 from ioito/automated-cherry-pick-of-#19080-upstream-release-3.11
Automated cherry pick of #19080: fix(region): avoid for-loop sync volcengine disks
This commit is contained in:
@@ -88,7 +88,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111524-ab10dde9c9b0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231222082651-d3dd8fb49c5a
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
|
||||
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
|
||||
|
||||
@@ -1201,8 +1201,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111524-ab10dde9c9b0 h1:2Sj/zBlEgWaQGNxQXh1ZYLlNzZh0DAsTe3J/+eYBXZE=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111524-ab10dde9c9b0/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231222082651-d3dd8fb49c5a h1:szZDIyMRd9rqoMV41mbnlfqUVZP8JySED7M8pmLc3Jo=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231222082651-d3dd8fb49c5a/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
Vendored
+1
-1
@@ -1465,7 +1465,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111524-ab10dde9c9b0
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231222082651-d3dd8fb49c5a
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+26
-18
@@ -192,13 +192,11 @@ func (disk *SDisk) CreateISnapshot(ctx context.Context, name, desc string) (clou
|
||||
}
|
||||
|
||||
// region
|
||||
func (region *SRegion) GetDisks(instanceId string, zoneId string, category string, diskIds []string, pageNumber int, pageSize int) ([]SDisk, int, error) {
|
||||
if pageSize > 100 || pageSize <= 0 {
|
||||
pageSize = 100
|
||||
}
|
||||
func (region *SRegion) GetDisks(instanceId string, zoneId string, category string, diskIds []string) ([]SDisk, error) {
|
||||
params := make(map[string]string)
|
||||
params["PageSize"] = fmt.Sprintf("%d", pageSize)
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNumber)
|
||||
params["PageSize"] = "100"
|
||||
pageNum := 1
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNum)
|
||||
|
||||
if len(instanceId) > 0 {
|
||||
params["InstanceId"] = instanceId
|
||||
@@ -214,18 +212,28 @@ func (region *SRegion) GetDisks(instanceId string, zoneId string, category strin
|
||||
params[key] = id
|
||||
}
|
||||
|
||||
body, err := region.storageRequest("DescribeVolumes", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "GetDisks fail")
|
||||
ret := []SDisk{}
|
||||
for {
|
||||
resp, err := region.storageRequest("DescribeVolumes", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetDisks fail")
|
||||
}
|
||||
part := struct {
|
||||
Volumes []SDisk
|
||||
TotalCount int
|
||||
}{}
|
||||
err = resp.Unmarshal(&part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, part.Volumes...)
|
||||
if len(ret) >= part.TotalCount || len(part.Volumes) == 0 {
|
||||
break
|
||||
}
|
||||
pageNum++
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNum)
|
||||
}
|
||||
|
||||
disks := make([]SDisk, 0)
|
||||
err = body.Unmarshal(&disks, "Volumes")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "Unmarshal disk details fail")
|
||||
}
|
||||
total, _ := body.Int("TotalCount")
|
||||
return disks, int(total), nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateDisk(zoneId string, category string, name string, sizeGb int, desc string, projectId string) (string, error) {
|
||||
@@ -250,7 +258,7 @@ func (region *SRegion) CreateDisk(zoneId string, category string, name string, s
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDisk(diskId string) (*SDisk, error) {
|
||||
disks, _, err := region.GetDisks("", "", "", []string{diskId}, 1, 50)
|
||||
disks, err := region.GetDisks("", "", "", []string{diskId})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, fmt.Sprintf("%s not found", diskId))
|
||||
}
|
||||
|
||||
+3
-12
@@ -182,18 +182,9 @@ func (instance *SInstance) GetIHostId() string {
|
||||
}
|
||||
|
||||
func (instance *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
pageNumber := 1
|
||||
disks := make([]SDisk, 0)
|
||||
for {
|
||||
parts, total, err := instance.host.zone.region.GetDisks(instance.InstanceId, "", "", nil, pageNumber, 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
disks = append(disks, parts...)
|
||||
if len(disks) >= total {
|
||||
break
|
||||
}
|
||||
pageNumber += 1
|
||||
disks, err := instance.host.zone.region.GetDisks(instance.InstanceId, "", "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
idisks := make([]cloudprovider.ICloudDisk, len(disks))
|
||||
|
||||
+6
-16
@@ -54,26 +54,16 @@ func (storage *SStorage) GetIZone() cloudprovider.ICloudZone {
|
||||
}
|
||||
|
||||
func (storage *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
disks := make([]SDisk, 0)
|
||||
pageNumber := 1
|
||||
storageType := storage.storageType
|
||||
for {
|
||||
parts, total, err := storage.zone.region.GetDisks("", storage.zone.GetId(), storageType, nil, pageNumber, 50)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDisks")
|
||||
}
|
||||
disks = append(disks, parts...)
|
||||
if len(parts) >= total {
|
||||
break
|
||||
}
|
||||
pageNumber += 1
|
||||
disks, err := storage.zone.region.GetDisks("", storage.zone.GetId(), storage.storageType, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDisks")
|
||||
}
|
||||
idisks := make([]cloudprovider.ICloudDisk, len(disks))
|
||||
ret := []cloudprovider.ICloudDisk{}
|
||||
for i := 0; i < len(disks); i += 1 {
|
||||
disks[i].storage = storage
|
||||
idisks[i] = &disks[i]
|
||||
ret = append(ret, &disks[i])
|
||||
}
|
||||
return idisks, nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (storage *SStorage) GetStorageType() string {
|
||||
|
||||
Reference in New Issue
Block a user