Merge pull request #7923 from Uladzislau97/nap-resilience

Improve resilience of diskTypes requests.
This commit is contained in:
Kubernetes Prow Robot 2025-04-08 04:22:40 -07:00 committed by GitHub
commit 4bc861d097
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 109 additions and 189 deletions

View File

@ -130,7 +130,7 @@ type AutoscalingGceClient interface {
FetchMigsWithName(zone string, filter *regexp.Regexp) ([]string, error)
FetchZones(region string) ([]string, error)
FetchAvailableCpuPlatforms() (map[string][]string, error)
FetchAvailableDiskTypes() (map[string][]string, error)
FetchAvailableDiskTypes(zone string) ([]string, error)
FetchReservations() ([]*gce.Reservation, error)
FetchReservationsInProject(projectId string) ([]*gce.Reservation, error)
FetchListManagedInstancesResults(migRef GceRef) (string, error)
@ -753,21 +753,13 @@ func (client *autoscalingGceClientV1) FetchAvailableCpuPlatforms() (map[string][
return availableCpuPlatforms, nil
}
func (client *autoscalingGceClientV1) FetchAvailableDiskTypes() (map[string][]string, error) {
availableDiskTypes := make(map[string][]string)
func (client *autoscalingGceClientV1) FetchAvailableDiskTypes(zone string) ([]string, error) {
availableDiskTypes := []string{}
req := client.gceService.DiskTypes.AggregatedList(client.projectId)
if err := req.Pages(context.TODO(), func(page *gce.DiskTypeAggregatedList) error {
for _, diskTypesScopedList := range page.Items {
for _, diskType := range diskTypesScopedList.DiskTypes {
// skip data for regions
if diskType.Zone == "" {
continue
}
// convert URL of the zone, into the short name, e.g. us-central1-a
zone := path.Base(diskType.Zone)
availableDiskTypes[zone] = append(availableDiskTypes[zone], diskType.Name)
}
req := client.gceService.DiskTypes.List(client.projectId, zone)
if err := req.Pages(context.TODO(), func(page *gce.DiskTypeList) error {
for _, diskType := range page.Items {
availableDiskTypes = append(availableDiskTypes, diskType.Name)
}
return nil
}); err != nil {

View File

@ -653,18 +653,13 @@ func TestFetchAvailableDiskTypes(t *testing.T) {
defer server.Close()
g := newTestAutoscalingGceClient(t, "project-id", server.URL, "")
// ref: https://cloud.google.com/compute/docs/reference/rest/v1/diskTypes/aggregatedList
getDiskTypesAggregatedListOKResponse, _ := os.ReadFile("fixtures/diskTypes_aggregatedList.json")
server.On("handle", "/projects/project-id/aggregated/diskTypes").Return(string(getDiskTypesAggregatedListOKResponse)).Times(1)
// ref: https://cloud.google.com/compute/docs/reference/rest/v1/diskTypes/list
getDiskTypesListOKResponse, _ := os.ReadFile("fixtures/diskTypes_list.json")
server.On("handle", "/projects/project-id/zones/us-central1-b/diskTypes").Return(string(getDiskTypesListOKResponse)).Times(1)
t.Run("correctly parse a response", func(t *testing.T) {
want := map[string][]string{
// "us-central1" region should be skipped
"us-central1-a": {"local-ssd", "pd-balanced", "pd-ssd", "pd-standard"},
"us-central1-b": {"hyperdisk-balanced", "hyperdisk-extreme", "hyperdisk-throughput", "local-ssd", "pd-balanced", "pd-extreme", "pd-ssd", "pd-standard"},
}
got, err := g.FetchAvailableDiskTypes()
want := []string{"hyperdisk-balanced", "hyperdisk-extreme", "hyperdisk-throughput", "local-ssd", "pd-balanced", "pd-extreme", "pd-ssd", "pd-standard"}
got, err := g.FetchAvailableDiskTypes("us-central1-b")
assert.NoError(t, err)
if diff := cmp.Diff(want, got, cmpopts.EquateErrors()); diff != "" {
@ -860,7 +855,7 @@ func TestAutoscalingClientTimeouts(t *testing.T) {
},
"FetchAvailableDiskTypes_HttpClientTimeout": {
clientFunc: func(client *autoscalingGceClientV1) error {
_, err := client.FetchAvailableDiskTypes()
_, err := client.FetchAvailableDiskTypes("")
return err
},
httpTimeout: instantTimeout,

View File

@ -1,162 +0,0 @@
{
"kind": "compute#diskTypeAggregatedList",
"id": "projects/project-id/aggregated/diskTypes",
"items": {
"regions/us-central1": {
"diskTypes": [
{
"kind": "compute#diskType",
"id": "30007",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-balanced",
"description": "Balanced Persistent Disk",
"validDiskSize": "10GB-65536GB",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/regions/us-central1/diskTypes/pd-balanced",
"defaultDiskSizeGb": "100",
"region": "https://www.googleapis.com/compute/v1/projects/project-id/regions/us-central1"
}
]
},
"zones/us-central1-a": {
"diskTypes": [
{
"kind": "compute#diskType",
"id": "30003",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "local-ssd",
"description": "Local SSD",
"validDiskSize": "375GB-375GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-a",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-a/diskTypes/local-ssd",
"defaultDiskSizeGb": "375"
},
{
"kind": "compute#diskType",
"id": "30007",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-balanced",
"description": "Balanced Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-a",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-a/diskTypes/pd-balanced",
"defaultDiskSizeGb": "100"
},
{
"kind": "compute#diskType",
"id": "30002",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-ssd",
"description": "SSD Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-a",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-a/diskTypes/pd-ssd",
"defaultDiskSizeGb": "100"
},
{
"kind": "compute#diskType",
"id": "30001",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-standard",
"description": "Standard Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-a",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-a/diskTypes/pd-standard",
"defaultDiskSizeGb": "500"
}
]
},
"zones/us-central1-b": {
"diskTypes": [
{
"kind": "compute#diskType",
"id": "30014",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "hyperdisk-balanced",
"description": "Hyperdisk Balanced Persistent Disk",
"validDiskSize": "4GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-balanced",
"defaultDiskSizeGb": "100"
},
{
"kind": "compute#diskType",
"id": "30012",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "hyperdisk-extreme",
"description": "Hyperdisk Extreme Persistent Disk",
"validDiskSize": "64GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-extreme",
"defaultDiskSizeGb": "1000"
},
{
"kind": "compute#diskType",
"id": "30013",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "hyperdisk-throughput",
"description": "Hyperdisk Throughput Persistent Disk",
"validDiskSize": "2048GB-32768GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-throughput",
"defaultDiskSizeGb": "2048"
},
{
"kind": "compute#diskType",
"id": "30003",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "local-ssd",
"description": "Local SSD",
"validDiskSize": "375GB-375GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/local-ssd",
"defaultDiskSizeGb": "375"
},
{
"kind": "compute#diskType",
"id": "30007",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-balanced",
"description": "Balanced Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-balanced",
"defaultDiskSizeGb": "100"
},
{
"kind": "compute#diskType",
"id": "30008",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-extreme",
"description": "Extreme Persistent Disk",
"validDiskSize": "500GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-extreme",
"defaultDiskSizeGb": "1000"
},
{
"kind": "compute#diskType",
"id": "30002",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-ssd",
"description": "SSD Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-ssd",
"defaultDiskSizeGb": "100"
},
{
"kind": "compute#diskType",
"id": "30001",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-standard",
"description": "Standard Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-standard",
"defaultDiskSizeGb": "500"
}
]
}
},
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/aggregated/diskTypes"
}

View File

@ -0,0 +1,95 @@
{
"kind": "compute#diskTypeList",
"id": "projects/project-id/aggregated/diskTypes",
"items": [
{
"kind": "compute#diskType",
"id": "30014",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "hyperdisk-balanced",
"description": "Hyperdisk Balanced Persistent Disk",
"validDiskSize": "4GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-balanced",
"defaultDiskSizeGb": "100"
},
{
"kind": "compute#diskType",
"id": "30012",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "hyperdisk-extreme",
"description": "Hyperdisk Extreme Persistent Disk",
"validDiskSize": "64GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-extreme",
"defaultDiskSizeGb": "1000"
},
{
"kind": "compute#diskType",
"id": "30013",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "hyperdisk-throughput",
"description": "Hyperdisk Throughput Persistent Disk",
"validDiskSize": "2048GB-32768GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/hyperdisk-throughput",
"defaultDiskSizeGb": "2048"
},
{
"kind": "compute#diskType",
"id": "30003",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "local-ssd",
"description": "Local SSD",
"validDiskSize": "375GB-375GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/local-ssd",
"defaultDiskSizeGb": "375"
},
{
"kind": "compute#diskType",
"id": "30007",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-balanced",
"description": "Balanced Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-balanced",
"defaultDiskSizeGb": "100"
},
{
"kind": "compute#diskType",
"id": "30008",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-extreme",
"description": "Extreme Persistent Disk",
"validDiskSize": "500GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-extreme",
"defaultDiskSizeGb": "1000"
},
{
"kind": "compute#diskType",
"id": "30002",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-ssd",
"description": "SSD Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-ssd",
"defaultDiskSizeGb": "100"
},
{
"kind": "compute#diskType",
"id": "30001",
"creationTimestamp": "1969-12-31T16:00:00.000-08:00",
"name": "pd-standard",
"description": "Standard Persistent Disk",
"validDiskSize": "10GB-65536GB",
"zone": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-b/diskTypes/pd-standard",
"defaultDiskSizeGb": "500"
}
],
"selfLink": "https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-b/diskTypes"
}

View File

@ -172,7 +172,7 @@ func (client *mockAutoscalingGceClient) FetchAvailableCpuPlatforms() (map[string
return nil, nil
}
func (client *mockAutoscalingGceClient) FetchAvailableDiskTypes() (map[string][]string, error) {
func (client *mockAutoscalingGceClient) FetchAvailableDiskTypes(_ string) ([]string, error) {
return nil, nil
}