From 3975ba1db59fb5e7e9d7e087f87dfdad4aa148bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20=C5=BByli=C5=84ski?= Date: Fri, 17 May 2024 10:58:34 +0200 Subject: [PATCH] Add FetchAvailableDiskTypes to GCE Client --- .../gce/autoscaling_gce_client.go | 19 +++++++++++++++++++ .../gce/mig_info_provider_test.go | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go b/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go index c081c388085a..f0185220a316 100644 --- a/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go +++ b/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go @@ -107,6 +107,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) FetchReservations() ([]*gce.Reservation, error) FetchReservationsInProject(projectId string) ([]*gce.Reservation, error) FetchListManagedInstancesResults(migRef GceRef) (string, error) @@ -585,6 +586,24 @@ func (client *autoscalingGceClientV1) FetchAvailableCpuPlatforms() (map[string][ return availableCpuPlatforms, nil } +func (client *autoscalingGceClientV1) FetchAvailableDiskTypes() (map[string][]string, error) { + availableDiskTypes := make(map[string][]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 { + availableDiskTypes[diskType.Zone] = append(availableDiskTypes[diskType.Zone], diskType.Name) + } + } + return nil + }); err != nil { + return nil, err + } + + return availableDiskTypes, nil +} + func (client *autoscalingGceClientV1) FetchMigTemplateName(migRef GceRef) (InstanceTemplateName, error) { registerRequest("instance_group_managers", "get") igm, err := client.gceService.InstanceGroupManagers.Get(migRef.Project, migRef.Zone, migRef.Name).Do() diff --git a/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go b/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go index 5e5f519fae01..1f4e1199a5c5 100644 --- a/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go +++ b/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go @@ -107,6 +107,10 @@ func (client *mockAutoscalingGceClient) FetchAvailableCpuPlatforms() (map[string return nil, nil } +func (client *mockAutoscalingGceClient) FetchAvailableDiskTypes() (map[string][]string, error) { + return nil, nil +} + func (client *mockAutoscalingGceClient) FetchReservations() ([]*gce.Reservation, error) { return nil, nil }