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

disk: only count cloud disks #1005

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions pkg/disk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ func getSnapshotInfoByID(snapshotID string) (string, string, *timestamp.Timestam
return "", "", nil
}

func getAttachedDisks(ecsClient cloud.ECSInterface, m metadata.MetadataProvider) (diskIds []string, err error) {
func getAttachedCloudDisks(ecsClient cloud.ECSInterface, m metadata.MetadataProvider) (diskIds []string, err error) {
req := ecs.CreateDescribeDisksRequest()
req.InstanceId = metadata.MustGet(m, metadata.InstanceID)
req.RegionId = metadata.MustGet(m, metadata.RegionID)
Expand All @@ -1444,7 +1444,10 @@ func getAttachedDisks(ecsClient cloud.ECSInterface, m metadata.MetadataProvider)
req.NextToken = resp.NextToken

for _, disk := range resp.Disks.Disk {
diskIds = append(diskIds, disk.DiskId)
// local disks have their own quota in LocalStorageAmount, and are not counted for DiskQuantity
if strings.HasPrefix(disk.Category, "cloud") {
diskIds = append(diskIds, disk.DiskId)
}
}

if len(req.NextToken) == 0 {
Expand Down Expand Up @@ -1473,7 +1476,7 @@ func getAvailableDiskCount(ecsClient cloud.ECSInterface, m metadata.MetadataProv
}

func getVolumeCountFromOpenAPI(node *v1.Node, ecsClient cloud.ECSInterface, m metadata.MetadataProvider) (int, error) {
attachedDisks, err := getAttachedDisks(ecsClient, m)
attachedDisks, err := getAttachedCloudDisks(ecsClient, m)
if err != nil {
return 0, err
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/disk/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,30 @@ const DescribeDisksResponse = `{
}
]
},
"Category": "cloud_essd",
"DiskId": "d-2zeah0dj7hx3zk6unfbf"
},
{
"Tags": {
"Tag": []
},
"Category": "cloud",
"DiskId": "d-2zeh74nnxxrobxz49eug"
},
{
"Tags": {
"Tag": []
},
"Category": "cloud_essd",
"DiskId": "d-testingusedbystaticpv"
},
{
"Tags": {
"Tag": []
},
"Category": "local_hdd_pro",
"DiskId": "d-testinglocaldisk"
},
{
"Tags": {
"Tag": [
Expand All @@ -273,6 +283,7 @@ const DescribeDisksResponse = `{
}
]
},
"Category": "cloud_auto",
"DiskId": "d-2ze49fivxwkwxl36o1d3"
}
]
Expand Down