From 3a8f8ac973da9e78f1a54ea51d0cf9435fca638a Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Thu, 31 Oct 2024 19:17:34 +0100 Subject: [PATCH] Use namespace of the reference on Get Signed-off-by: Danil-Grigorev --- controllers/external/util.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/external/util.go b/controllers/external/util.go index 4efdb9c133f2..505f7a2f5987 100644 --- a/controllers/external/util.go +++ b/controllers/external/util.go @@ -39,9 +39,9 @@ func Get(ctx context.Context, c client.Reader, ref *corev1.ObjectReference, name obj.SetAPIVersion(ref.APIVersion) obj.SetKind(ref.Kind) obj.SetName(ref.Name) - key := client.ObjectKey{Name: obj.GetName(), Namespace: namespace} - if err := c.Get(ctx, key, obj); err != nil { - return nil, errors.Wrapf(err, "failed to retrieve %s external object %q/%q", obj.GetKind(), key.Namespace, key.Name) + obj.SetNamespace(ref.Namespace) + if err := c.Get(ctx, client.ObjectKeyFromObject(obj), obj); err != nil { + return nil, errors.Wrapf(err, "failed to retrieve %s external object %q/%q", obj.GetKind(), ref.Namespace, ref.Name) } return obj, nil }