Skip to content

Commit

Permalink
Fix channel subscribers patching for v1alpha1 channels. (knative#2986) (
Browse files Browse the repository at this point in the history
knative#3020)

Co-authored-by: Alexey Karnov <void.alexey@gmail.com>
  • Loading branch information
grantr and v0id3r authored Apr 21, 2020
1 parent 4c05c4f commit 6615249
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
17 changes: 16 additions & 1 deletion pkg/reconciler/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func (r *Reconciler) updateChannelRemoveSubscription(ctx context.Context, channe
return
}
}
r.updateChannelAddSubscriptionV1Alpha1(ctx, channel, sub)
r.updateChannelRemoveSubscriptionV1Alpha1(ctx, channel, sub)
}

func (r *Reconciler) updateChannelRemoveSubscriptionV1Beta1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1alpha1.Subscription) {
Expand All @@ -487,6 +487,21 @@ func (r *Reconciler) updateChannelRemoveSubscriptionV1Beta1(ctx context.Context,
}
}

func (r *Reconciler) updateChannelRemoveSubscriptionV1Alpha1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1alpha1.Subscription) {
if channel.Spec.Subscribable == nil {
return
}

for i, v := range channel.Spec.Subscribable.Subscribers {
if v.UID == sub.UID {
channel.Spec.Subscribable.Subscribers = append(
channel.Spec.Subscribable.Subscribers[:i],
channel.Spec.Subscribable.Subscribers[i+1:]...)
return
}
}
}

func (r *Reconciler) updateChannelAddSubscription(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1alpha1.Subscription) {
if channel.Annotations != nil {
if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" {
Expand Down
11 changes: 5 additions & 6 deletions pkg/reconciler/subscription/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,9 @@ func TestAllCases(t *testing.T) {
NewInMemoryChannel(channelName, testNS,
WithInitInMemoryChannelConditions,
WithInMemoryChannelAddress(channelDNS),
WithInMemoryChannelSubscribers([]eventingduck.SubscriberSpec{
{UID: subscriptionUID, SubscriberURI: subscriberURI},
}),
),
},
Key: testNS + "/" + subscriptionName,
Expand All @@ -966,9 +969,7 @@ func TestAllCases(t *testing.T) {
Eventf(corev1.EventTypeNormal, "SubscriberRemoved", "Subscription was removed from channel \"origin\""),
},
WantPatches: []clientgotesting.PatchActionImpl{
patchSubscribers(testNS, channelName, []eventingduck.SubscriberSpec{
{UID: subscriptionUID, SubscriberURI: serviceURI},
}),
patchSubscribers(testNS, channelName, nil),
patchRemoveFinalizers(testNS, subscriptionName),
},
}, {
Expand Down Expand Up @@ -1017,9 +1018,7 @@ func TestAllCases(t *testing.T) {
),
}},
WantPatches: []clientgotesting.PatchActionImpl{
patchSubscribers(testNS, channelName, []eventingduck.SubscriberSpec{
{UID: subscriptionUID, SubscriberURI: serviceURI},
}),
patchSubscribers(testNS, channelName, nil),
},
}, {
Name: "subscription deleted - channel does not exists",
Expand Down

0 comments on commit 6615249

Please sign in to comment.