Skip to content

Commit

Permalink
Merge pull request #7004 from damikag/refactor-mig-fetch-2
Browse files Browse the repository at this point in the history
Use project name instead of project number in createIgmRef()
  • Loading branch information
k8s-ci-robot committed Jul 9, 2024
2 parents 01e8918 + aff0072 commit 286e61d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ func externalToInternalInstance(gceInstance *gce.Instance, loggingQuota *klogx.Q
},
},
NumericId: gceInstance.Id,
Igm: createIgmRef(gceInstance, loggingQuota),
Igm: createIgmRef(gceInstance, ref.Project, loggingQuota),
}, nil
}

func createIgmRef(gceInstance *gce.Instance, loggingQuota *klogx.Quota) GceRef {
func createIgmRef(gceInstance *gce.Instance, project string, loggingQuota *klogx.Quota) GceRef {
createdBy := ""
for _, item := range gceInstance.Metadata.Items {
if item.Key == "created-by" && item.Value != nil {
Expand All @@ -425,6 +425,9 @@ func createIgmRef(gceInstance *gce.Instance, loggingQuota *klogx.Quota) GceRef {
klogx.V(5).UpTo(loggingQuota).Infof("Unable to parse IGM for %v because of %v", gceInstance.SelfLink, err)
return GceRef{}
}
// project is overwritten to make it compatible with CA mig refs which uses project
// name instead of project number. igm url has project number not project name.
igmRef.Project = project
return igmRef
}

Expand Down
20 changes: 10 additions & 10 deletions cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ func TestFetchAllInstances(t *testing.T) {
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating},
},
NumericId: 11,
Igm: GceRef{"893226960234", "zones", "test-igm1-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm1-grp"},
},
},
},
Expand Down Expand Up @@ -987,15 +987,15 @@ func TestFetchAllInstances(t *testing.T) {
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 10,
Igm: GceRef{"893226960234", "zones", "test-igm1-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm1-grp"},
},
{
Instance: cloudprovider.Instance{
Id: "gce://myprojid/myzone/test-instance-2",
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 11,
Igm: GceRef{"893226960234", "zones", "test-igm1-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm1-grp"},
},
},
},
Expand Down Expand Up @@ -1084,47 +1084,47 @@ func TestFetchAllInstances(t *testing.T) {
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 10,
Igm: GceRef{"893226960234", "zones", "test-igm1-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm1-grp"},
},
{
Instance: cloudprovider.Instance{
Id: "gce://myprojid/myzone/test-instance-2",
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 11,
Igm: GceRef{"893226960234", "zones", "test-igm2-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm2-grp"},
},
{
Instance: cloudprovider.Instance{
Id: "gce://myprojid/myzone/test-instance-3",
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 12,
Igm: GceRef{"893226960234", "zones", "test-igm1-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm1-grp"},
},
{
Instance: cloudprovider.Instance{
Id: "gce://myprojid/myzone/test-instance-4",
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 13,
Igm: GceRef{"893226960234", "zones", "test-igm1-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm1-grp"},
},
{
Instance: cloudprovider.Instance{
Id: "gce://myprojid/myzone/test-instance-5",
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 14,
Igm: GceRef{"893226960234", "zones", "test-igm2-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm2-grp"},
},
{
Instance: cloudprovider.Instance{
Id: "gce://myprojid/myzone/test-instance-6",
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 15,
Igm: GceRef{"893226960234", "zones", "test-igm1-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm1-grp"},
},
},
},
Expand Down Expand Up @@ -1228,7 +1228,7 @@ func TestExternalToInternalInstance(t *testing.T) {
Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning},
},
NumericId: 10,
Igm: GceRef{"893226960234", "zones", "test-igm1-grp"},
Igm: GceRef{"myprojid", "zones", "test-igm1-grp"},
},
},
}
Expand Down

0 comments on commit 286e61d

Please sign in to comment.