diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go index dc1d3ae5bc9..99a9e323682 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go @@ -873,17 +873,20 @@ func getZonesForRegion(svc *compute.Service, projectID, region string) ([]string // (tested in https://cloud.google.com/compute/docs/reference/latest/zones/list) // listCall = listCall.Filter("region eq " + region) - res, err := listCall.Do() + var zones []string + var accumulator = func(response *compute.ZoneList) error { + for _, zone := range response.Items { + regionName := lastComponent(zone.Region) + if regionName == region { + zones = append(zones, zone.Name) + } + } + return nil + } + err := listCall.Pages(context.TODO(), accumulator) if err != nil { return nil, fmt.Errorf("unexpected response listing zones: %v", err) } - zones := []string{} - for _, zone := range res.Items { - regionName := lastComponent(zone.Region) - if regionName == region { - zones = append(zones, zone.Name) - } - } return zones, nil } diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go index 7e639067c92..32c1ea9a1ed 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go @@ -126,22 +126,32 @@ func (g *Cloud) ListTPUs(ctx context.Context, zone string) ([]*tpuapi.Node, erro mc := newTPUMetricContext("list", zone) parent := getTPUParentName(g.projectID, zone) - response, err := g.tpuService.projects.Locations.Nodes.List(parent).Do() + var nodes []*tpuapi.Node + var accumulator = func(response *tpuapi.ListNodesResponse) error { + nodes = append(nodes, response.Nodes...) + return nil + } + err := g.tpuService.projects.Locations.Nodes.List(parent).Pages(ctx, accumulator) if err != nil { return nil, mc.Observe(err) } - return response.Nodes, mc.Observe(nil) + return nodes, mc.Observe(nil) } // ListLocations returns the zones where Cloud TPUs are available. func (g *Cloud) ListLocations(ctx context.Context) ([]*tpuapi.Location, error) { mc := newTPUMetricContext("list_locations", "") parent := getTPUProjectURL(g.projectID) - response, err := g.tpuService.projects.Locations.List(parent).Do() + var locations []*tpuapi.Location + var accumulator = func(response *tpuapi.ListLocationsResponse) error { + locations = append(locations, response.Locations...) + return nil + } + err := g.tpuService.projects.Locations.List(parent).Pages(ctx, accumulator) if err != nil { return nil, mc.Observe(err) } - return response.Locations, mc.Observe(nil) + return locations, mc.Observe(nil) } // waitForTPUOp checks whether the op is done every 30 seconds before the ctx