From 3b8ae5f98ef86f89237991570591dd93f2dce2d3 Mon Sep 17 00:00:00 2001 From: Edwinhr716 Date: Thu, 7 Mar 2024 20:09:00 +0000 Subject: [PATCH] added unit test with regional MIG --- .../cloudprovider/gce/gce_url.go | 1 + .../gce/mig_info_provider_test.go | 28 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/gce/gce_url.go b/cluster-autoscaler/cloudprovider/gce/gce_url.go index 72fc3e774550..80ef91207ff0 100644 --- a/cluster-autoscaler/cloudprovider/gce/gce_url.go +++ b/cluster-autoscaler/cloudprovider/gce/gce_url.go @@ -78,6 +78,7 @@ func GenerateMigUrl(domainUrl string, ref GceRef) string { return fmt.Sprintf(migUrlTemplate, ref.Project, ref.Zone, ref.Name) } +// IsInstanceTemplateRegional determines whether or not an instance template is regional based on the url func IsInstanceTemplateRegional(templateUrl string) (bool, error) { return regexp.MatchString("(/projects/.*[A-Za-z0-9]+.*/regions/)", templateUrl) } diff --git a/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go b/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go index f01d928c8dbf..0c89f227eb3b 100644 --- a/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go +++ b/cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go @@ -852,7 +852,13 @@ func TestGetMigInstanceTemplateName(t *testing.T) { instanceGroupManager := &gce.InstanceGroupManager{ Zone: mig.GceRef().Zone, Name: mig.GceRef().Name, - InstanceTemplate: templateName, + InstanceTemplate: "https://www.googleapis.com/compute/v1/projects/test-project/global/instanceTemplates/template-name", + } + + instanceGroupManagerRegional := &gce.InstanceGroupManager{ + Zone: mig.GceRef().Zone, + Name: mig.GceRef().Name, + InstanceTemplate: "https://www.googleapis.com/compute/v1/projects/test-project/regions/us-central1/instanceTemplates/template-name", } testCases := []struct { @@ -861,6 +867,7 @@ func TestGetMigInstanceTemplateName(t *testing.T) { fetchMigs func(string) ([]*gce.InstanceGroupManager, error) fetchMigTemplateName func(GceRef) (InstanceTemplateName, error) expectedTemplateName string + expectedRegion bool expectedErr error }{ { @@ -877,6 +884,12 @@ func TestGetMigInstanceTemplateName(t *testing.T) { fetchMigs: fetchMigsConst([]*gce.InstanceGroupManager{instanceGroupManager}), expectedTemplateName: templateName, }, + { + name: "target size from cache fill, regional", + cache: emptyCache(), + fetchMigs: fetchMigsConst([]*gce.InstanceGroupManager{instanceGroupManagerRegional}), + expectedTemplateName: templateName, + }, { name: "cache fill without mig, fallback success", cache: emptyCache(), @@ -1371,26 +1384,15 @@ func (f *fakeTime) Now() time.Time { func emptyCache() *GceCache { return &GceCache{ -<<<<<<< HEAD migs: map[GceRef]Mig{mig.GceRef(): mig}, instances: make(map[GceRef][]GceInstance), instancesUpdateTime: make(map[GceRef]time.Time), migTargetSizeCache: make(map[GceRef]int64), migBaseNameCache: make(map[GceRef]string), listManagedInstancesResultsCache: make(map[GceRef]string), - instanceTemplateNameCache: make(map[GceRef]InstanceTemplateNameType), + instanceTemplateNameCache: make(map[GceRef]InstanceTemplateName), instanceTemplatesCache: make(map[GceRef]*gce.InstanceTemplate), instancesFromUnknownMig: make(map[GceRef]bool), -======= - migs: map[GceRef]Mig{mig.GceRef(): mig}, - instances: make(map[GceRef][]GceInstance), - instancesUpdateTime: make(map[GceRef]time.Time), - migTargetSizeCache: make(map[GceRef]int64), - migBaseNameCache: make(map[GceRef]string), - instanceTemplateNameCache: make(map[GceRef]InstanceTemplateName), - instanceTemplatesCache: make(map[GceRef]*gce.InstanceTemplate), - instancesFromUnknownMig: make(map[GceRef]bool), ->>>>>>> 2aeec4097 (changed InstanceTemplateNameType to InstanceTemplateName) } }