From 0d817e09997881ebe3fb4180b98e0f13314f8b27 Mon Sep 17 00:00:00 2001 From: Evan Anderson Date: Sat, 8 Dec 2018 00:32:50 +0000 Subject: [PATCH] Fix #673: add support for status.domainInternal --- .../eventing/subscription/reconcile.go | 16 ++++--- .../eventing/subscription/reconcile_test.go | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/pkg/controller/eventing/subscription/reconcile.go b/pkg/controller/eventing/subscription/reconcile.go index 87dfce24be8..62922355920 100644 --- a/pkg/controller/eventing/subscription/reconcile.go +++ b/pkg/controller/eventing/subscription/reconcile.go @@ -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 { + 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") } diff --git a/pkg/controller/eventing/subscription/reconcile_test.go b/pkg/controller/eventing/subscription/reconcile_test.go index b0737db271f..bd74767c365 100644 --- a/pkg/controller/eventing/subscription/reconcile_test.go +++ b/pkg/controller/eventing/subscription/reconcile_test.go @@ -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{