From 91c27e1b1c1172faff898db36cb7ecb95d8d59cf Mon Sep 17 00:00:00 2001 From: Calum Murray Date: Mon, 18 Mar 2024 13:35:11 -0400 Subject: [PATCH] fix: imc dispatcher reconciler no longer panics on error Signed-off-by: Calum Murray --- .../dispatcher/inmemorychannel.go | 10 ++++++---- .../dispatcher/inmemorychannel_test.go | 20 +++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel.go b/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel.go index ae6c1e18368..a2717927399 100644 --- a/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel.go +++ b/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel.go @@ -230,16 +230,18 @@ func newConfigForInMemoryChannel(ctx context.Context, imc *v1.InMemoryChannel) ( for i, sub := range imc.Spec.Subscribers { conf, err := fanout.SubscriberSpecToFanoutConfig(sub) - conf.Namespace = imc.GetNamespace() + if err != nil { + return nil, err + } + + conf.Namespace = imc.Namespace if isOIDCEnabled { conf.ServiceAccount = &types.NamespacedName{ Name: *sub.Auth.ServiceAccountName, Namespace: imc.Namespace, } } - if err != nil { - return nil, err - } + subs[i] = *conf } diff --git a/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel_test.go b/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel_test.go index 59e3cd93e4e..5e5d8862291 100644 --- a/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel_test.go +++ b/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel_test.go @@ -354,13 +354,16 @@ func TestReconciler_ReconcileKind(t *testing.T) { Reply: &duckv1.Addressable{ URL: apis.HTTP("sink2"), }, + Namespace: testNS, }, { Subscriber: duckv1.Addressable{ URL: apis.HTTP("call2"), }, Reply: &duckv1.Addressable{ URL: apis.HTTP("sink2"), - }}, + }, + Namespace: testNS, + }, }, }, "with one subscriber, one added": { @@ -375,12 +378,14 @@ func TestReconciler_ReconcileKind(t *testing.T) { WithInMemoryChannelDLSUnknown()), subs: []fanout.Subscription{*subscription1}, wantSubs: []fanout.Subscription{{ + Namespace: testNS, Subscriber: duckv1.Addressable{ URL: apis.HTTP("call1"), }, Reply: &duckv1.Addressable{ URL: apis.HTTP("sink2"), }}, { + Namespace: testNS, Subscriber: duckv1.Addressable{ URL: apis.HTTP("call2"), }, @@ -401,12 +406,14 @@ func TestReconciler_ReconcileKind(t *testing.T) { WithInMemoryChannelDLSUnknown()), subs: []fanout.Subscription{*subscription1, *subscription2}, wantSubs: []fanout.Subscription{{ + Namespace: testNS, Subscriber: duckv1.Addressable{ URL: apis.HTTP("call1"), }, Reply: &duckv1.Addressable{ URL: apis.HTTP("sink2"), }}, { + Namespace: testNS, Subscriber: duckv1.Addressable{ URL: apis.HTTP("call2"), }, @@ -428,6 +435,7 @@ func TestReconciler_ReconcileKind(t *testing.T) { subs: []fanout.Subscription{*subscription1, *subscription2}, wantSubs: []fanout.Subscription{ { + Namespace: testNS, Subscriber: duckv1.Addressable{ URL: apis.HTTP("call1"), }, @@ -449,12 +457,14 @@ func TestReconciler_ReconcileKind(t *testing.T) { subs: []fanout.Subscription{*subscription1, *subscription2}, wantSubs: []fanout.Subscription{ { + Namespace: testNS, Subscriber: duckv1.Addressable{ URL: apis.HTTP("call1"), }, Reply: &duckv1.Addressable{ URL: apis.HTTP("sink2"), }}, { + Namespace: testNS, Subscriber: duckv1.Addressable{ URL: apis.HTTP("call3"), }, @@ -482,9 +492,11 @@ func TestReconciler_ReconcileKind(t *testing.T) { }, RetryConfig: &kncloudevents.RetryConfig{RetryMax: 2, BackoffPolicy: &exponential}}}, wantSubs: []fanout.Subscription{ - {Subscriber: duckv1.Addressable{ - URL: apis.HTTP("call1"), - }, + { + Namespace: testNS, + Subscriber: duckv1.Addressable{ + URL: apis.HTTP("call1"), + }, Reply: &duckv1.Addressable{ URL: apis.HTTP("sink2"), },