Skip to content

Commit

Permalink
added unit test with regional MIG
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwinhr716 committed Mar 13, 2024
1 parent f8b4727 commit 3b8ae5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions cluster-autoscaler/cloudprovider/gce/gce_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
28 changes: 15 additions & 13 deletions cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}{
{
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 3b8ae5f

Please sign in to comment.