Skip to content

Commit

Permalink
Use namespace of the reference on Get
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Oct 31, 2024
1 parent e75b4e7 commit a41b03c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions controllers/external/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ import (
)

// Get uses the client and reference to get an external, unstructured object.
func Get(ctx context.Context, c client.Reader, ref *corev1.ObjectReference, namespace string) (*unstructured.Unstructured, error) {
func Get(ctx context.Context, c client.Reader, ref *corev1.ObjectReference, _ string) (*unstructured.Unstructured, error) {
if ref == nil {
return nil, errors.Errorf("cannot get object - object reference not set")
}
obj := new(unstructured.Unstructured)
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
}
Expand Down

0 comments on commit a41b03c

Please sign in to comment.