diff --git a/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go b/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go index 4dde60940700..2bb0db5b99a6 100644 --- a/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go +++ b/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go @@ -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 { @@ -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 } diff --git a/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client_test.go b/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client_test.go index b5e829ef2b7d..136494e83ce9 100644 --- a/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client_test.go +++ b/cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client_test.go @@ -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"}, }, }, }, @@ -987,7 +987,7 @@ 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{ @@ -995,7 +995,7 @@ func TestFetchAllInstances(t *testing.T) { Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning}, }, NumericId: 11, - Igm: GceRef{"893226960234", "zones", "test-igm1-grp"}, + Igm: GceRef{"myprojid", "zones", "test-igm1-grp"}, }, }, }, @@ -1084,7 +1084,7 @@ 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{ @@ -1092,7 +1092,7 @@ func TestFetchAllInstances(t *testing.T) { 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{ @@ -1100,7 +1100,7 @@ func TestFetchAllInstances(t *testing.T) { 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{ @@ -1108,7 +1108,7 @@ func TestFetchAllInstances(t *testing.T) { 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{ @@ -1116,7 +1116,7 @@ func TestFetchAllInstances(t *testing.T) { 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{ @@ -1124,7 +1124,7 @@ func TestFetchAllInstances(t *testing.T) { Status: &cloudprovider.InstanceStatus{State: cloudprovider.InstanceRunning}, }, NumericId: 15, - Igm: GceRef{"893226960234", "zones", "test-igm1-grp"}, + Igm: GceRef{"myprojid", "zones", "test-igm1-grp"}, }, }, }, @@ -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"}, }, }, }