Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions resolver/addressable_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,18 @@ func (r *URIResolver) URIFromObjectReference(ctx context.Context, ref *corev1.Ob
return nil, apierrs.NewNotFound(gvr.GroupResource(), ref.Name)
}

lister, err := r.listerFactory(gvr)
if err != nil {
return nil, apierrs.NewNotFound(gvr.GroupResource(), "Lister")
}

obj, err := lister.ByNamespace(ref.Namespace).Get(ref.Name)
if err != nil {
return nil, apierrs.NewNotFound(gvr.GroupResource(), ref.Name)
}

Comment on lines +162 to +170
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this code was here before but is there not a distinction between an error and object not found

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, always a bit odd to see a dropped err value

// K8s Services are special cased. They can be called, even though they do not satisfy the
// Callable interface.
// TODO(spencer-p,n3wscott) Verify that the service actually exists in K8s.
if ref.APIVersion == "v1" && ref.Kind == "Service" {
url := &apis.URL{
Scheme: "http",
Expand All @@ -170,16 +179,6 @@ func (r *URIResolver) URIFromObjectReference(ctx context.Context, ref *corev1.Ob
return url, nil
}

lister, err := r.listerFactory(gvr)
if err != nil {
return nil, apierrs.NewNotFound(gvr.GroupResource(), "Lister")
}

obj, err := lister.ByNamespace(ref.Namespace).Get(ref.Name)
if err != nil {
return nil, apierrs.NewNotFound(gvr.GroupResource(), ref.Name)
}

addressable, ok := obj.(*duckv1.AddressableType)
if !ok {
return nil, apierrs.NewBadRequest(fmt.Sprintf("%+v (%T) is not an AddressableType", ref, ref))
Expand Down
23 changes: 22 additions & 1 deletion resolver/addressable_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func TestGetURIDestinationV1(t *testing.T) {
wantURI: addressableDNS,
}, "happy ref to k8s service": {
objects: []runtime.Object{
getAddressable(),
getAddressableFromKRef(k8sServiceRef()),
},
dest: duckv1.Destination{Ref: k8sServiceRef()},
wantURI: "http://testsink.testnamespace.svc.cluster.local/",
Expand Down Expand Up @@ -511,6 +511,9 @@ func TestGetURIDestinationV1(t *testing.T) {
}, "notFound": {
dest: duckv1.Destination{Ref: unaddressableKnativeRef()},
wantErr: fmt.Sprintf("%s %q not found", unaddressableResource, unaddressableName),
}, "notFound k8s service": {
dest: duckv1.Destination{Ref: k8sServiceRef()},
wantErr: fmt.Sprintf("services %q not found", addressableName),
}}

for n, tc := range tests {
Expand Down Expand Up @@ -753,3 +756,21 @@ func unaddressableRef() *corev1.ObjectReference {
Namespace: testNS,
}
}

func getAddressableFromKRef(ref *duckv1.KReference) *unstructured.Unstructured {
return &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": ref.APIVersion,
"kind": ref.Kind,
"metadata": map[string]interface{}{
"namespace": ref.Namespace,
"name": ref.Name,
},
"status": map[string]interface{}{
"address": map[string]interface{}{
"url": addressableDNS,
},
},
},
}
}