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
31 changes: 15 additions & 16 deletions pkg/reconciler/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,21 @@ func (r *Reconciler) getChannelableStatus(ctx context.Context, bc *duckv1alpha1.
bc.AddressStatus.Address.ConvertTo(ctx, channelableStatus.AddressStatus.Address)
}
channelableStatus.Status = bc.Status
if cAnnotations != nil {
if cAnnotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" {
if len(bc.SubscribableStatus.Subscribers) > 0 {
channelableStatus.SubscribableStatus.Subscribers = bc.SubscribableStatus.Subscribers
}
} else { //v1alpha1
if bc.SubscribableTypeStatus.SubscribableStatus != nil &&
len(bc.SubscribableTypeStatus.SubscribableStatus.Subscribers) > 0 {
channelableStatus.SubscribableStatus.Subscribers = make([]duckv1beta1.SubscriberStatus, len(bc.SubscribableTypeStatus.SubscribableStatus.Subscribers))
for i, ss := range bc.SubscribableTypeStatus.SubscribableStatus.Subscribers {
channelableStatus.SubscribableStatus.Subscribers[i] = duckv1beta1.SubscriberStatus{
UID: ss.UID,
ObservedGeneration: ss.ObservedGeneration,
Ready: ss.Ready,
Message: ss.Message,
}
if cAnnotations != nil &&
cAnnotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" {
if len(bc.SubscribableStatus.Subscribers) > 0 {
channelableStatus.SubscribableStatus.Subscribers = bc.SubscribableStatus.Subscribers
}
} else { //we assume v1alpha1 if no tag according to the spec
if bc.SubscribableTypeStatus.SubscribableStatus != nil &&
len(bc.SubscribableTypeStatus.SubscribableStatus.Subscribers) > 0 {
channelableStatus.SubscribableStatus.Subscribers = make([]duckv1beta1.SubscriberStatus, len(bc.SubscribableTypeStatus.SubscribableStatus.Subscribers))
for i, ss := range bc.SubscribableTypeStatus.SubscribableStatus.Subscribers {
channelableStatus.SubscribableStatus.Subscribers[i] = duckv1beta1.SubscriberStatus{
UID: ss.UID,
ObservedGeneration: ss.ObservedGeneration,
Ready: ss.Ready,
Message: ss.Message,
}
}
}
Expand Down
63 changes: 63 additions & 0 deletions pkg/reconciler/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
clientgotesting "k8s.io/client-go/testing"
eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1"
eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1"
fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake"
"knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined"
Expand Down Expand Up @@ -247,6 +248,38 @@ func TestReconcile(t *testing.T) {
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "ChannelReconciled", "Channel reconciled: %q", testKey),
},
}, {
Name: "Updating v1alpha1 imc subscribers statuses",
Key: testKey,
Objects: []runtime.Object{
NewChannelV1Beta1(channelName, testNS,
WithChannelTemplateV1Beta1(channelV1Alpha1CRD()),
WithInitChannelConditionsV1Beta1,
WithBackingChannelObjRefV1Beta1(backingChannelObjRefV1Alpha1()),
WithBackingChannelReadyV1Beta1,
WithChannelAddressV1Beta1(backingChannelHostname)),
NewInMemoryChannel(channelName, testNS,
WithInMemoryChannelDuckAnnotationV1Alpha1,
WithInMemoryChannelDeploymentReady(),
WithInMemoryChannelServiceReady(),
WithInMemoryChannelEndpointsReady(),
WithInMemoryChannelChannelServiceReady(),
WithInMemoryChannelAddress(backingChannelHostname),
WithInMemoryChannelSubscribers(subscribersV1Alpha1()),
WithInMemoryChannelStatusSubscribers(subscriberStatuses())),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewChannelV1Beta1(channelName, testNS,
WithChannelTemplateV1Beta1(channelV1Alpha1CRD()),
WithInitChannelConditionsV1Beta1,
WithBackingChannelObjRefV1Beta1(backingChannelObjRefV1Alpha1()),
WithBackingChannelReadyV1Beta1,
WithChannelAddressV1Beta1(backingChannelHostname),
WithChannelSubscriberStatusesV1Beta1(subscriberStatuses())),
}},
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "ChannelReconciled", "Channel reconciled: %q", testKey),
},
}}

logger := logtesting.TestLogger(t)
Expand All @@ -273,6 +306,13 @@ func channelCRD() metav1.TypeMeta {
}
}

func channelV1Alpha1CRD() metav1.TypeMeta {
return metav1.TypeMeta{
APIVersion: "messaging.knative.dev/v1alpha1",
Kind: "InMemoryChannel",
}
}

func subscribers() []eventingduckv1beta1.SubscriberSpec {
return []eventingduckv1beta1.SubscriberSpec{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
Expand All @@ -287,6 +327,20 @@ func subscribers() []eventingduckv1beta1.SubscriberSpec {
}}
}

func subscribersV1Alpha1() []eventingduckv1alpha1.SubscriberSpec {
return []eventingduckv1alpha1.SubscriberSpec{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
Generation: 1,
SubscriberURI: apis.HTTP("call1"),
ReplyURI: apis.HTTP("sink2"),
}, {
UID: "34c5aec8-deb6-11e8-9f32-f2801f1b9fd1",
Generation: 2,
SubscriberURI: apis.HTTP("call2"),
ReplyURI: apis.HTTP("sink2"),
}}
}

func subscriberStatuses() []eventingduckv1beta1.SubscriberStatus {
return []eventingduckv1beta1.SubscriberStatus{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
Expand Down Expand Up @@ -341,6 +395,15 @@ func backingChannelObjRef() *duckv1.KReference {
}
}

func backingChannelObjRefV1Alpha1() *duckv1.KReference {
return &duckv1.KReference{
APIVersion: "messaging.knative.dev/v1alpha1",
Kind: "InMemoryChannel",
Namespace: testNS,
Name: channelName,
}
}

func createChannel(namespace, name string, ready bool) *unstructured.Unstructured {
var hostname string
var url string
Expand Down
8 changes: 8 additions & 0 deletions pkg/reconciler/testing/inmemorychannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ func WithInMemoryChannelDuckAnnotationV1Beta1(imc *v1beta1.InMemoryChannel) {

}

func WithInMemoryChannelDuckAnnotationV1Alpha1(imc *v1alpha1.InMemoryChannel) {
annotations := map[string]string{
messaging.SubscribableDuckVersionAnnotation: "v1alpha1",
}
imc.ObjectMeta.SetAnnotations(annotations)

}

func WithInMemoryChannelGenerationV1Beta1(gen int64) InMemoryChannelOptionV1Beta1 {
return func(s *v1beta1.InMemoryChannel) {
s.Generation = gen
Expand Down