From 7fcca14ca2d7133550ed9e44fefceb6ae0450396 Mon Sep 17 00:00:00 2001 From: ioito Date: Fri, 22 Dec 2023 16:28:29 +0800 Subject: [PATCH] fix(region): avoid for-lool sync volcengine disks --- go.mod | 2 +- go.sum | 4 +- vendor/modules.txt | 2 +- .../pkg/multicloud/volcengine/disk.go | 44 +++++++++++-------- .../pkg/multicloud/volcengine/instance.go | 15 ++----- .../pkg/multicloud/volcengine/storage.go | 22 +++------- 6 files changed, 39 insertions(+), 50 deletions(-) diff --git a/go.mod b/go.mod index e3284768f90..f5f39e531e5 100644 --- a/go.mod +++ b/go.mod @@ -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.20231220111515-f4d6c15e4077 + yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231222082642-2717001c0240 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 diff --git a/go.sum b/go.sum index c9358f4db00..f71214b3c7d 100644 --- a/go.sum +++ b/go.sum @@ -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.20231220111515-f4d6c15e4077 h1:uzfyl/PcxvNAYHwf+uOXnNRxucRIoLC3xLbdLhp68o0= -yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231220111515-f4d6c15e4077/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231222082642-2717001c0240 h1:gxeXGwyuXRWOETJ3KChKXb5BD0I+OTvgUenJNoJowFI= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231222082642-2717001c0240/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= diff --git a/vendor/modules.txt b/vendor/modules.txt index 53b88299820..eac7b534e15 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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.20231220111515-f4d6c15e4077 +# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231222082642-2717001c0240 ## explicit; go 1.18 yunion.io/x/cloudmux/pkg/apis yunion.io/x/cloudmux/pkg/apis/billing diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/disk.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/disk.go index 7d0d7363592..f0ea085eb51 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/disk.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/disk.go @@ -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") - } - - disks := make([]SDisk, 0) - err = body.Unmarshal(&disks, "Volumes") - if err != nil { - return nil, 0, errors.Wrapf(err, "Unmarshal disk details 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) } - 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)) } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/instance.go index 02d32933244..69e4d7c2e85 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/instance.go @@ -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)) diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/storage.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/storage.go index fe88b49ab7c..1f947b3c3ea 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/storage.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/volcengine/storage.go @@ -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 {