Skip to content

Commit 4bc861d

Browse files
authored
Merge pull request #7923 from Uladzislau97/nap-resilience
Improve resilience of diskTypes requests.
2 parents 7c28f52 + 93e21d0 commit 4bc861d

File tree

5 files changed

+109
-189
lines changed

5 files changed

+109
-189
lines changed

cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ type AutoscalingGceClient interface {
130130
FetchMigsWithName(zone string, filter *regexp.Regexp) ([]string, error)
131131
FetchZones(region string) ([]string, error)
132132
FetchAvailableCpuPlatforms() (map[string][]string, error)
133-
FetchAvailableDiskTypes() (map[string][]string, error)
133+
FetchAvailableDiskTypes(zone string) ([]string, error)
134134
FetchReservations() ([]*gce.Reservation, error)
135135
FetchReservationsInProject(projectId string) ([]*gce.Reservation, error)
136136
FetchListManagedInstancesResults(migRef GceRef) (string, error)
@@ -753,21 +753,13 @@ func (client *autoscalingGceClientV1) FetchAvailableCpuPlatforms() (map[string][
753753
return availableCpuPlatforms, nil
754754
}
755755

756-
func (client *autoscalingGceClientV1) FetchAvailableDiskTypes() (map[string][]string, error) {
757-
availableDiskTypes := make(map[string][]string)
756+
func (client *autoscalingGceClientV1) FetchAvailableDiskTypes(zone string) ([]string, error) {
757+
availableDiskTypes := []string{}
758758

759-
req := client.gceService.DiskTypes.AggregatedList(client.projectId)
760-
if err := req.Pages(context.TODO(), func(page *gce.DiskTypeAggregatedList) error {
761-
for _, diskTypesScopedList := range page.Items {
762-
for _, diskType := range diskTypesScopedList.DiskTypes {
763-
// skip data for regions
764-
if diskType.Zone == "" {
765-
continue
766-
}
767-
// convert URL of the zone, into the short name, e.g. us-central1-a
768-
zone := path.Base(diskType.Zone)
769-
availableDiskTypes[zone] = append(availableDiskTypes[zone], diskType.Name)
770-
}
759+
req := client.gceService.DiskTypes.List(client.projectId, zone)
760+
if err := req.Pages(context.TODO(), func(page *gce.DiskTypeList) error {
761+
for _, diskType := range page.Items {
762+
availableDiskTypes = append(availableDiskTypes, diskType.Name)
771763
}
772764
return nil
773765
}); err != nil {

cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -653,18 +653,13 @@ func TestFetchAvailableDiskTypes(t *testing.T) {
653653
defer server.Close()
654654
g := newTestAutoscalingGceClient(t, "project-id", server.URL, "")
655655

656-
// ref: https://cloud.google.com/compute/docs/reference/rest/v1/diskTypes/aggregatedList
657-
getDiskTypesAggregatedListOKResponse, _ := os.ReadFile("fixtures/diskTypes_aggregatedList.json")
658-
server.On("handle", "/projects/project-id/aggregated/diskTypes").Return(string(getDiskTypesAggregatedListOKResponse)).Times(1)
656+
// ref: https://cloud.google.com/compute/docs/reference/rest/v1/diskTypes/list
657+
getDiskTypesListOKResponse, _ := os.ReadFile("fixtures/diskTypes_list.json")
658+
server.On("handle", "/projects/project-id/zones/us-central1-b/diskTypes").Return(string(getDiskTypesListOKResponse)).Times(1)
659659

660660
t.Run("correctly parse a response", func(t *testing.T) {
661-
want := map[string][]string{
662-
// "us-central1" region should be skipped
663-
"us-central1-a": {"local-ssd", "pd-balanced", "pd-ssd", "pd-standard"},
664-
"us-central1-b": {"hyperdisk-balanced", "hyperdisk-extreme", "hyperdisk-throughput", "local-ssd", "pd-balanced", "pd-extreme", "pd-ssd", "pd-standard"},
665-
}
666-
667-
got, err := g.FetchAvailableDiskTypes()
661+
want := []string{"hyperdisk-balanced", "hyperdisk-extreme", "hyperdisk-throughput", "local-ssd", "pd-balanced", "pd-extreme", "pd-ssd", "pd-standard"}
662+
got, err := g.FetchAvailableDiskTypes("us-central1-b")
668663

669664
assert.NoError(t, err)
670665
if diff := cmp.Diff(want, got, cmpopts.EquateErrors()); diff != "" {
@@ -860,7 +855,7 @@ func TestAutoscalingClientTimeouts(t *testing.T) {
860855
},
861856
"FetchAvailableDiskTypes_HttpClientTimeout": {
862857
clientFunc: func(client *autoscalingGceClientV1) error {
863-
_, err := client.FetchAvailableDiskTypes()
858+
_, err := client.FetchAvailableDiskTypes("")
864859
return err
865860
},
866861
httpTimeout: instantTimeout,

cluster-autoscaler/cloudprovider/gce/fixtures/diskTypes_aggregatedList.json

Lines changed: 0 additions & 162 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"kind": "compute#diskTypeList",
3+
"id": "projects/project-id/aggregated/diskTypes",
4+
"items": [
5+
{
6+
"kind": "compute#diskType",
7+
"id": "30014",
8+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
9+
"name": "hyperdisk-balanced",
10+
"description": "Hyperdisk Balanced Persistent Disk",
11+
"validDiskSize": "4GB-65536GB",
12+
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
13+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-balanced",
14+
"defaultDiskSizeGb": "100"
15+
},
16+
{
17+
"kind": "compute#diskType",
18+
"id": "30012",
19+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
20+
"name": "hyperdisk-extreme",
21+
"description": "Hyperdisk Extreme Persistent Disk",
22+
"validDiskSize": "64GB-65536GB",
23+
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
24+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-extreme",
25+
"defaultDiskSizeGb": "1000"
26+
},
27+
{
28+
"kind": "compute#diskType",
29+
"id": "30013",
30+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
31+
"name": "hyperdisk-throughput",
32+
"description": "Hyperdisk Throughput Persistent Disk",
33+
"validDiskSize": "2048GB-32768GB",
34+
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
35+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-throughput",
36+
"defaultDiskSizeGb": "2048"
37+
},
38+
{
39+
"kind": "compute#diskType",
40+
"id": "30003",
41+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
42+
"name": "local-ssd",
43+
"description": "Local SSD",
44+
"validDiskSize": "375GB-375GB",
45+
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
46+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/local-ssd",
47+
"defaultDiskSizeGb": "375"
48+
},
49+
{
50+
"kind": "compute#diskType",
51+
"id": "30007",
52+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
53+
"name": "pd-balanced",
54+
"description": "Balanced Persistent Disk",
55+
"validDiskSize": "10GB-65536GB",
56+
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
57+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-balanced",
58+
"defaultDiskSizeGb": "100"
59+
},
60+
{
61+
"kind": "compute#diskType",
62+
"id": "30008",
63+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
64+
"name": "pd-extreme",
65+
"description": "Extreme Persistent Disk",
66+
"validDiskSize": "500GB-65536GB",
67+
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
68+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-extreme",
69+
"defaultDiskSizeGb": "1000"
70+
},
71+
{
72+
"kind": "compute#diskType",
73+
"id": "30002",
74+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
75+
"name": "pd-ssd",
76+
"description": "SSD Persistent Disk",
77+
"validDiskSize": "10GB-65536GB",
78+
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
79+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-ssd",
80+
"defaultDiskSizeGb": "100"
81+
},
82+
{
83+
"kind": "compute#diskType",
84+
"id": "30001",
85+
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
86+
"name": "pd-standard",
87+
"description": "Standard Persistent Disk",
88+
"validDiskSize": "10GB-65536GB",
89+
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
90+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-standard",
91+
"defaultDiskSizeGb": "500"
92+
}
93+
],
94+
"selfLink": "https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-b/diskTypes"
95+
}

cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (client *mockAutoscalingGceClient) FetchAvailableCpuPlatforms() (map[string
172172
return nil, nil
173173
}
174174

175-
func (client *mockAutoscalingGceClient) FetchAvailableDiskTypes() (map[string][]string, error) {
175+
func (client *mockAutoscalingGceClient) FetchAvailableDiskTypes(_ string) ([]string, error) {
176176
return nil, nil
177177
}
178178

0 commit comments

Comments
 (0)