Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to status.domainInternal if not Addressable #684

Merged
merged 1 commit into from
Dec 17, 2018
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
16 changes: 10 additions & 6 deletions pkg/controller/eventing/subscription/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,19 @@ func (r *reconciler) resolveSubscriberSpec(namespace string, s v1alpha1.Subscrib
return "", err
}
t := duckv1alpha1.AddressableType{}
err = duck.FromUnstructured(obj, &t)
if err != nil {
glog.Warningf("Failed to deserialize legacy target: %s", err)
return "", err
if err := duck.FromUnstructured(obj, &t); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this err ever have useful information? If so, we should return it in some form (even if it is part of a larger message).

Copy link
Member Author

Choose a reason for hiding this comment

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

This err would either be from obj.MarshallJSON or json.Unmarshall, which would suggest that the object wasn't JSON-able, which would make the "does not contain address" error below accurate.

if t.Status.Address != nil {
return domainToURL(t.Status.Address.Hostname), nil
}
}

if t.Status.Address != nil {
return domainToURL(t.Status.Address.Hostname), nil
legacy := duckv1alpha1.LegacyTarget{}
if err := duck.FromUnstructured(obj, &legacy); err == nil {
if legacy.Status.DomainInternal != "" {
return domainToURL(legacy.Status.DomainInternal), nil
}
}

return "", fmt.Errorf("status does not contain address")
}

Expand Down
44 changes: 44 additions & 0 deletions pkg/controller/eventing/subscription/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,50 @@ var testCases = []controllertesting.TestCase{
},
},
},
}, {
Name: "new subscription: adds status, target points to the legacy targetable interface",
InitialState: []runtime.Object{
Subscription().EmptyNonNilReply(),
},
// TODO: JSON patch is not working on the fake, see
// https://github.com/kubernetes/client-go/issues/478. Marking this as expecting a specific
// failure for now, until upstream is fixed.
WantResult: reconcile.Result{},
WantPresent: []runtime.Object{
Subscription().ReferencesResolved().PhysicalSubscriber(targetDNS).EmptyNonNilReply(),
},
WantErrMsg: "invalid JSON document",
Scheme: scheme.Scheme,
Objects: []runtime.Object{
// Source channel
&unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": eventingv1alpha1.SchemeGroupVersion.String(),
"kind": channelKind,
"metadata": map[string]interface{}{
"namespace": testNS,
"name": fromChannelName,
},
"spec": map[string]interface{}{
"subscribable": map[string]interface{}{},
},
},
},
// Subscriber (using knative route)
&unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "serving.knative.dev/v1alpha1",
"kind": routeKind,
"metadata": map[string]interface{}{
"namespace": testNS,
"name": routeName,
},
"status": map[string]interface{}{
"domainInternal": targetDNS,
},
},
},
},
}, {
Name: "new subscription: adds status, all targets resolved, subscribers modified -- empty but non-nil subscriber",
InitialState: []runtime.Object{
Expand Down