Skip to content

Commit

Permalink
also migrate subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Lopez committed Aug 11, 2020
1 parent 54b9ec0 commit 7bc321e
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 127 deletions.
20 changes: 10 additions & 10 deletions pkg/apis/duck/v1alpha1/channelable_combined_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ type ChannelableCombinedSpec struct {
SubscribableTypeSpec `json:",inline"`

// SubscribableSpec is for the v1beta1 spec compatibility.
eventingduckv1beta1.SubscribableSpec `json:",inline"`
//SubscribableSpec eventingduckv1beta1.SubscribableSpec `json:",inline"`

// DeliverySpec contains options controlling the event delivery
// for the v1beta1 spec compatibility.
// +optional
Delivery *eventingduckv1beta1.DeliverySpec `json:"delivery,omitempty"`

// SubscribableSpecv1 is for the v1 spec compatibility.
SubscribableSpecv1 eventingduckv1.SubscribableSpec `json:",inline"`
eventingduckv1.SubscribableSpec `json:",inline"`

// DeliverySpecv1 contains options controlling the event delivery
// for the v1 spec compatibility.
Expand All @@ -80,9 +80,9 @@ type ChannelableCombinedStatus struct {
// SubscribableTypeStatus is the v1alpha1 part of the Subscribers status
SubscribableTypeStatus `json:",inline"`
// SubscribableStatus is the v1beta1 part of the Subscribers status.
eventingduckv1beta1.SubscribableStatus `json:",inline"`
//eventingduckv1beta1.SubscribableStatus `json:",inline"`
// SubscribableStatusv1 is the v1 part of the Subscribers status.
SubscribableStatusv1 eventingduckv1.SubscribableStatus `json:",inline"`
eventingduckv1.SubscribableStatus `json:",inline"`
// ErrorChannel is set by the channel when it supports native error handling via a channel
// +optional
ErrorChannel *corev1.ObjectReference `json:"errorChannel,omitempty"`
Expand Down Expand Up @@ -111,7 +111,7 @@ func (c *ChannelableCombined) Populate() {
ReplyURI: apis.HTTP("sink2"),
}},
}
c.Spec.SubscribableSpec = eventingduckv1beta1.SubscribableSpec{
/*c.Spec.SubscribableSpec = eventingduckv1beta1.SubscribableSpec{
// Populate ALL fields
Subscribers: []eventingduckv1beta1.SubscriberSpec{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
Expand All @@ -124,8 +124,8 @@ func (c *ChannelableCombined) Populate() {
SubscriberURI: apis.HTTP("call2"),
ReplyURI: apis.HTTP("sink2"),
}},
}
c.Spec.SubscribableSpecv1 = eventingduckv1.SubscribableSpec{
}*/
c.Spec.SubscribableSpec = eventingduckv1.SubscribableSpec{
// Populate ALL fields
Subscribers: []eventingduckv1.SubscriberSpec{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
Expand Down Expand Up @@ -199,10 +199,10 @@ func (c *ChannelableCombined) Populate() {
Hostname: "test-domain",
},
},
SubscribableStatus: eventingduckv1beta1.SubscribableStatus{
/*SubscribableStatus: eventingduckv1beta1.SubscribableStatus{
Subscribers: subscribers,
},
SubscribableStatusv1: eventingduckv1.SubscribableStatus{
},*/
SubscribableStatus: eventingduckv1.SubscribableStatus{
Subscribers: subscribersv1,
},
SubscribableTypeStatus: SubscribableTypeStatus{
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/duck/v1alpha1/channelable_combined_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestChannelableCombinedPopulate(t *testing.T) {
delay := "5s"
want := &ChannelableCombined{
Spec: ChannelableCombinedSpec{
SubscribableSpec: eventingduckv1beta1.SubscribableSpec{
/*SubscribableSpec: eventingduckv1beta1.SubscribableSpec{
// Populate ALL fields
Subscribers: []eventingduckv1beta1.SubscriberSpec{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
Expand All @@ -62,8 +62,8 @@ func TestChannelableCombinedPopulate(t *testing.T) {
SubscriberURI: apis.HTTP("call2"),
ReplyURI: apis.HTTP("sink2"),
}},
},
SubscribableSpecv1: eventingduckv1.SubscribableSpec{
},*/
SubscribableSpec: eventingduckv1.SubscribableSpec{
// Populate ALL fields
Subscribers: []eventingduckv1.SubscriberSpec{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestChannelableCombinedPopulate(t *testing.T) {
Hostname: "test-domain",
},
},
SubscribableStatus: eventingduckv1beta1.SubscribableStatus{
/*SubscribableStatus: eventingduckv1beta1.SubscribableStatus{
Subscribers: []eventingduckv1beta1.SubscriberStatus{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
ObservedGeneration: 1,
Expand All @@ -147,8 +147,8 @@ func TestChannelableCombinedPopulate(t *testing.T) {
Ready: corev1.ConditionFalse,
Message: "Some message",
}},
},
SubscribableStatusv1: eventingduckv1.SubscribableStatus{
},*/
SubscribableStatus: eventingduckv1.SubscribableStatus{
Subscribers: []eventingduckv1.SubscriberStatus{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
ObservedGeneration: 1,
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 3 additions & 15 deletions pkg/reconciler/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,13 @@ func (r *Reconciler) getChannelableStatus(ctx context.Context, bc *duckv1alpha1.
channelableStatus.Status = bc.Status
if cAnnotations != nil &&
cAnnotations[messaging.SubscribableDuckVersionAnnotation] == "v1" {
subs := make([]eventingduckv1.SubscriberStatus, len(bc.SubscribableStatus.Subscribers))
for i, sub := range bc.SubscribableStatus.Subscribers {
sub.ConvertTo(ctx, &subs[i])
}
if len(bc.SubscribableStatus.Subscribers) > 0 {
channelableStatus.SubscribableStatus.Subscribers = subs
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([]eventingduckv1.SubscriberStatus, len(bc.SubscribableTypeStatus.SubscribableStatus.Subscribers))
for i, ss := range bc.SubscribableTypeStatus.SubscribableStatus.Subscribers {
channelableStatus.SubscribableStatus.Subscribers[i] = eventingduckv1.SubscriberStatus{
UID: ss.UID,
ObservedGeneration: ss.ObservedGeneration,
Ready: ss.Ready,
Message: ss.Message,
}
}
len(bc.SubscribableTypeStatus.SubscribableStatus.Subscribersv1) > 0 {
channelableStatus.SubscribableStatus.Subscribers = bc.SubscribableTypeStatus.SubscribableStatus.Subscribersv1
}
}
return channelableStatus
Expand Down
14 changes: 6 additions & 8 deletions pkg/reconciler/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
clientgotesting "k8s.io/client-go/testing"
eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"
v1 "knative.dev/eventing/pkg/apis/duck/v1"
eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1"
v1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1"
eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
Expand All @@ -40,7 +39,6 @@ import (
channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/channel"
"knative.dev/eventing/pkg/duck"
. "knative.dev/eventing/pkg/reconciler/testing/v1"
testingv1beta1 "knative.dev/eventing/pkg/reconciler/testing/v1beta1"
"knative.dev/eventing/pkg/utils"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
Expand Down Expand Up @@ -68,7 +66,7 @@ func init() {
_ = messagingv1beta1.AddToScheme(scheme.Scheme)
_ = messagingv1.AddToScheme(scheme.Scheme)
_ = v1.AddToScheme(scheme.Scheme)
_ = eventingduckv1alpha1.AddToScheme(scheme.Scheme)
_ = v1alpha1.AddToScheme(scheme.Scheme)
_ = eventingduckv1.AddToScheme(scheme.Scheme)
}

Expand Down Expand Up @@ -253,11 +251,11 @@ func TestReconcile(t *testing.T) {
WithBackingChannelObjRef(backingChannelObjRefV1Alpha1()),
WithBackingChannelReady,
WithChannelAddress(backingChannelHostname)),
testingv1beta1.NewChannelable(channelName, testNS,
testingv1beta1.WithChannelableReady(),
testingv1beta1.WithChannelableAddress(backingChannelHostname),
testingv1beta1.WithChannelableSubscribers(subscribersV1Alpha1()),
testingv1beta1.WithChannelableStatusSubscribers(subscriberStatusesV1beta1())),
NewChannelable(channelName, testNS,
WithChannelableReady(),
WithChannelableAddress(backingChannelHostname),
WithChannelableSubscribers(subscribersV1Alpha1()),
WithChannelableStatusSubscribers(subscriberStatuses())),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewChannel(channelName, testNS,
Expand Down
10 changes: 5 additions & 5 deletions pkg/reconciler/subscription/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"knative.dev/pkg/resolver"
"knative.dev/pkg/tracker"

messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
"knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined"
"knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/channel"
"knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/subscription"
subscriptionreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1beta1/subscription"
"knative.dev/eventing/pkg/client/injection/informers/messaging/v1/channel"
"knative.dev/eventing/pkg/client/injection/informers/messaging/v1/subscription"
subscriptionreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/subscription"
"knative.dev/eventing/pkg/duck"
"knative.dev/pkg/injection/clients/dynamicclient"
)
Expand Down Expand Up @@ -67,7 +67,7 @@ func NewController(
// populated.
controller.EnsureTypeMeta(
r.tracker.OnChanged,
messagingv1beta1.SchemeGroupVersion.WithKind("Channel"),
messagingv1.SchemeGroupVersion.WithKind("Channel"),
),
))

Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/subscription/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
// Fake injection informers
_ "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelable/fake"
_ "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/fake"
_ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/channel/fake"
_ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/subscription/fake"
_ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1/channel/fake"
_ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1/subscription/fake"
_ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake"
)

Expand Down
Loading

0 comments on commit 7bc321e

Please sign in to comment.