Skip to content

Commit

Permalink
Add fetch reservations in specific project
Browse files Browse the repository at this point in the history
GCE supports shared reservations where the reservation is in a different
project than the project the cluster is in. Add GCE client method to get
said reservations so autoscaling can support shared reservations.
  • Loading branch information
jessicaochen committed Aug 18, 2023
1 parent bb7c8a1 commit 3c9aecb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type AutoscalingGceClient interface {
FetchZones(region string) ([]string, error)
FetchAvailableCpuPlatforms() (map[string][]string, error)
FetchReservations() ([]*gce.Reservation, error)
FetchReservationsInProject(projectId string) ([]*gce.Reservation, error)

// modifying resources
ResizeMig(GceRef, int64) error
Expand Down Expand Up @@ -550,8 +551,12 @@ func (client *autoscalingGceClientV1) FetchMigsWithName(zone string, name *regex
}

func (client *autoscalingGceClientV1) FetchReservations() ([]*gce.Reservation, error) {
return client.FetchReservationsInProject(client.projectId)
}

func (client *autoscalingGceClientV1) FetchReservationsInProject(projectId string) ([]*gce.Reservation, error) {
reservations := make([]*gce.Reservation, 0)
call := client.gceService.Reservations.AggregatedList(client.projectId)
call := client.gceService.Reservations.AggregatedList(projectId)
err := call.Pages(context.TODO(), func(ls *gce.ReservationAggregatedList) error {
for _, items := range ls.Items {
reservations = append(reservations, items.Reservations...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (client *mockAutoscalingGceClient) FetchReservations() ([]*gce.Reservation,
return nil, nil
}

func (client *mockAutoscalingGceClient) FetchReservationsInProject(_ string) ([]*gce.Reservation, error) {
return nil, nil
}

func (client *mockAutoscalingGceClient) ResizeMig(_ GceRef, _ int64) error {
return nil
}
Expand Down

0 comments on commit 3c9aecb

Please sign in to comment.