From d981524006e2bd48fe9ec2c67670db480b8dee1f Mon Sep 17 00:00:00 2001 From: Abhijit Hoskeri Date: Fri, 8 Nov 2024 01:06:29 +0000 Subject: [PATCH] Honor project in node.spec.providerID Change-Id: I094e9bbad0d354b16735ab8912fc1d7799c74315 --- providers/gce/gce_instances.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/providers/gce/gce_instances.go b/providers/gce/gce_instances.go index e66e0ab0a..568ce220d 100644 --- a/providers/gce/gce_instances.go +++ b/providers/gce/gce_instances.go @@ -236,12 +236,12 @@ func (g *Cloud) NodeAddressesByProviderID(ctx context.Context, providerID string timeoutCtx, cancel := context.WithTimeout(ctx, 1*time.Hour) defer cancel() - _, zone, name, err := splitProviderID(providerID) + project, zone, name, err := splitProviderID(providerID) if err != nil { return []v1.NodeAddress{}, err } - instance, err := g.c.Instances().Get(timeoutCtx, meta.ZonalKey(canonicalizeInstanceName(name), zone)) + instance, err := g.c.Instances().Get(timeoutCtx, meta.ZonalKey(canonicalizeInstanceName(name), zone), cloud.ForceProjectID(project)) if err != nil { return []v1.NodeAddress{}, fmt.Errorf("error while querying for providerID %q: %v", providerID, err) } @@ -365,7 +365,7 @@ func (g *Cloud) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprov } } - _, zone, name, err := splitProviderID(providerID) + project, zone, name, err := splitProviderID(providerID) if err != nil { return nil, err } @@ -377,7 +377,7 @@ func (g *Cloud) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprov var addresses []v1.NodeAddress var instanceType string - instance, err := g.c.Instances().Get(timeoutCtx, meta.ZonalKey(canonicalizeInstanceName(name), zone)) + instance, err := g.c.Instances().Get(timeoutCtx, meta.ZonalKey(canonicalizeInstanceName(name), zone), cloud.ForceProjectID(project)) if err != nil { return nil, fmt.Errorf("error while querying for providerID %q: %v", providerID, err) } @@ -578,13 +578,13 @@ func (g *Cloud) AliasRangesByProviderID(providerID string) (cidrs []string, err ctx, cancel := cloud.ContextWithCallTimeout() defer cancel() - _, zone, name, err := splitProviderID(providerID) + project, zone, name, err := splitProviderID(providerID) if err != nil { return nil, err } var res *compute.Instance - res, err = g.c.Instances().Get(ctx, meta.ZonalKey(canonicalizeInstanceName(name), zone)) + res, err = g.c.Instances().Get(ctx, meta.ZonalKey(canonicalizeInstanceName(name), zone), cloud.ForceProjectID(project)) if err != nil { return } @@ -623,12 +623,12 @@ func (g *Cloud) AddAliasToInstanceByProviderID(providerID string, alias *net.IPN ctx, cancel := cloud.ContextWithCallTimeout() defer cancel() - _, zone, name, err := splitProviderID(providerID) + project, zone, name, err := splitProviderID(providerID) if err != nil { return err } - instance, err := g.c.BetaInstances().Get(ctx, meta.ZonalKey(canonicalizeInstanceName(name), zone)) + instance, err := g.c.BetaInstances().Get(ctx, meta.ZonalKey(canonicalizeInstanceName(name), zone), cloud.ForceProjectID(project)) if err != nil { return err } @@ -763,7 +763,7 @@ func (g *Cloud) getInstanceFromProjectInZoneByName(project, zone, name string) ( name = canonicalizeInstanceName(name) mc := newInstancesMetricContext("get", zone) - res, err := g.c.Instances().Get(ctx, meta.ZonalKey(name, zone)) + res, err := g.c.Instances().Get(ctx, meta.ZonalKey(name, zone), cloud.ForceProjectID(project)) mc.Observe(err) if err != nil { return nil, err @@ -917,12 +917,12 @@ func (g *Cloud) InstanceByProviderID(providerID string) (res *compute.Instance, ctx, cancel := cloud.ContextWithCallTimeout() defer cancel() - _, zone, name, err := splitProviderID(providerID) + project, zone, name, err := splitProviderID(providerID) if err != nil { return nil, err } - res, err = g.c.Instances().Get(ctx, meta.ZonalKey(canonicalizeInstanceName(name), zone)) + res, err = g.c.Instances().Get(ctx, meta.ZonalKey(canonicalizeInstanceName(name), zone), cloud.ForceProjectID(project)) if err != nil { return nil, err }