Skip to content

Commit

Permalink
rebased and resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwinhr716 committed Mar 13, 2024
1 parent d348ae8 commit 145d286
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,14 @@ func (client *autoscalingGceClientV1) FetchMigTemplateName(migRef GceRef) (Insta
return InstanceTemplateNameType{}, err
}
templateUrl, err := url.Parse(igm.InstanceTemplate)
regional, _ := regexp.MatchString("(/projects/.*[A-Za-z0-9]+.*/regions/)", templateUrl.String())
if err != nil {
return InstanceTemplateNameType{}, err
}
regional, err := regexp.MatchString("(/projects/.*[A-Za-z0-9]+.*/regions/)", templateUrl.String())
if err != nil {
return InstanceTemplateNameType{}, err
}

_, templateName := path.Split(templateUrl.EscapedPath())
return InstanceTemplateNameType{templateName, regional}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/gce/mig_info_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ func (c *cachingMigInfoProvider) GetMigInstanceTemplate(migRef GceRef) (*gce.Ins
}

func (c *cachingMigInfoProvider) GetMigKubeEnv(migRef GceRef) (KubeEnv, error) {
templateName, err := c.GetMigInstanceTemplateName(migRef)
instanceTemplateNameType, err := c.GetMigInstanceTemplateName(migRef)
if err != nil {
return KubeEnv{}, err
}

kubeEnv, kubeEnvFound := c.cache.GetMigKubeEnv(migRef)
if kubeEnvFound && kubeEnv.templateName == templateName {
if kubeEnvFound && kubeEnv.templateName == instanceTemplateNameType.Name {
return kubeEnv, nil
}

Expand Down
18 changes: 9 additions & 9 deletions cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,8 @@ func TestGetMigInstanceKubeEnv(t *testing.T) {
name string
cache *GceCache
fetchMigs func(string) ([]*gce.InstanceGroupManager, error)
fetchMigTemplateName func(GceRef) (string, error)
fetchMigTemplate func(GceRef, string) (*gce.InstanceTemplate, error)
fetchMigTemplateName func(GceRef) (InstanceTemplateNameType, error)
fetchMigTemplate func(GceRef, string, bool) (*gce.InstanceTemplate, error)
expectedKubeEnv KubeEnv
expectedCachedKubeEnv KubeEnv
expectedErr error
Expand All @@ -1085,7 +1085,7 @@ func TestGetMigInstanceKubeEnv(t *testing.T) {
name: "kube-env in cache",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): {templateName, false}},
kubeEnvCache: map[GceRef]KubeEnv{mig.GceRef(): kubeEnv},
},
expectedKubeEnv: kubeEnv,
Expand All @@ -1095,7 +1095,7 @@ func TestGetMigInstanceKubeEnv(t *testing.T) {
name: "cache without kube-env, template in cache",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): {templateName, false}},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{mig.GceRef(): template},
kubeEnvCache: make(map[GceRef]KubeEnv),
},
Expand All @@ -1106,7 +1106,7 @@ func TestGetMigInstanceKubeEnv(t *testing.T) {
name: "cache without kube-env, fetch success",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): {templateName, false}},
instanceTemplatesCache: make(map[GceRef]*gce.InstanceTemplate),
kubeEnvCache: make(map[GceRef]KubeEnv),
},
Expand All @@ -1118,7 +1118,7 @@ func TestGetMigInstanceKubeEnv(t *testing.T) {
name: "cache with old kube-env, new template cached",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): {templateName, false}},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{mig.GceRef(): template},
kubeEnvCache: map[GceRef]KubeEnv{mig.GceRef(): oldKubeEnv},
},
Expand All @@ -1129,7 +1129,7 @@ func TestGetMigInstanceKubeEnv(t *testing.T) {
name: "cache with old kube-env, fetch success",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): {templateName, false}},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{mig.GceRef(): oldTemplate},
kubeEnvCache: map[GceRef]KubeEnv{mig.GceRef(): oldKubeEnv},
},
Expand All @@ -1141,7 +1141,7 @@ func TestGetMigInstanceKubeEnv(t *testing.T) {
name: "cache without kube-env, fetch failure",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): {templateName, false}},
instanceTemplatesCache: make(map[GceRef]*gce.InstanceTemplate),
kubeEnvCache: make(map[GceRef]KubeEnv),
},
Expand All @@ -1152,7 +1152,7 @@ func TestGetMigInstanceKubeEnv(t *testing.T) {
name: "cache with old kube-env, fetch failure",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): {templateName, false}},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{mig.GceRef(): oldTemplate},
kubeEnvCache: map[GceRef]KubeEnv{mig.GceRef(): oldKubeEnv},
},
Expand Down

0 comments on commit 145d286

Please sign in to comment.