diff --git a/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go b/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go index 87a953d125a7..f4e4e7f54f21 100644 --- a/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go +++ b/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go @@ -77,6 +77,7 @@ type AutoscalingGceClient interface { FetchMigsWithName(zone string, filter *regexp.Regexp) ([]string, error) FetchZones(region string) ([]string, error) FetchAvailableCpuPlatforms() (map[string][]string, error) + FetchReservations() ([]*gce.Reservation, error) // modifying resources ResizeMig(GceRef, int64) error @@ -508,3 +509,15 @@ func (client *autoscalingGceClientV1) FetchMigsWithName(zone string, name *regex } return links, nil } + +func (client *autoscalingGceClientV1) FetchReservations() ([]*gce.Reservation, error) { + reservations := make([]*gce.Reservation, 0) + call := client.gceService.Reservations.AggregatedList(client.projectId) + err := call.Pages(context.TODO(), func(ls *gce.ReservationAggregatedList) error { + for _, items := range ls.Items { + reservations = append(reservations, items.Reservations...) + } + return nil + }) + return reservations, err +} diff --git a/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go b/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go index f7c4c0b26762..0f304f48dc5f 100644 --- a/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go +++ b/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go @@ -100,6 +100,10 @@ func (client *mockAutoscalingGceClient) FetchAvailableCpuPlatforms() (map[string return nil, nil } +func (client *mockAutoscalingGceClient) FetchReservations() ([]*gce.Reservation, error) { + return nil, nil +} + func (client *mockAutoscalingGceClient) ResizeMig(_ GceRef, _ int64) error { return nil }