diff --git a/pkg/apis/duck/v1alpha1/channelable_combined_types.go b/pkg/apis/duck/v1alpha1/channelable_combined_types.go index 7e0847e7e55..2e77a3f4012 100644 --- a/pkg/apis/duck/v1alpha1/channelable_combined_types.go +++ b/pkg/apis/duck/v1alpha1/channelable_combined_types.go @@ -53,7 +53,7 @@ type ChannelableCombinedSpec struct { SubscribableTypeSpec `json:",inline"` // SubscribableSpec is for the v1beta1 spec compatibility. - eventingduckv1beta1.SubscribableSpec `json:",inline"` + SubscribableSpecv1beta1 eventingduckv1beta1.SubscribableSpec `json:",inline"` // DeliverySpec contains options controlling the event delivery // for the v1beta1 spec compatibility. @@ -61,7 +61,7 @@ type ChannelableCombinedSpec struct { 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. @@ -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"` + SubscribableStatusv1beta1 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"` @@ -111,7 +111,7 @@ func (c *ChannelableCombined) Populate() { ReplyURI: apis.HTTP("sink2"), }}, } - c.Spec.SubscribableSpec = eventingduckv1beta1.SubscribableSpec{ + c.Spec.SubscribableSpecv1beta1 = eventingduckv1beta1.SubscribableSpec{ // Populate ALL fields Subscribers: []eventingduckv1beta1.SubscriberSpec{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", @@ -125,7 +125,7 @@ func (c *ChannelableCombined) Populate() { 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", @@ -164,7 +164,7 @@ func (c *ChannelableCombined) Populate() { BackoffPolicy: &linearv1, BackoffDelay: &delay, } - subscribers := []eventingduckv1beta1.SubscriberStatus{{ + subscribersv1beta1 := []eventingduckv1beta1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -175,7 +175,7 @@ func (c *ChannelableCombined) Populate() { Ready: corev1.ConditionFalse, Message: "Some message", }} - subscribersv1 := []eventingduckv1.SubscriberStatus{{ + subscribers := []eventingduckv1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -199,16 +199,16 @@ func (c *ChannelableCombined) Populate() { Hostname: "test-domain", }, }, - SubscribableStatus: eventingduckv1beta1.SubscribableStatus{ - Subscribers: subscribers, + SubscribableStatusv1beta1: eventingduckv1beta1.SubscribableStatus{ + Subscribers: subscribersv1beta1, }, - SubscribableStatusv1: eventingduckv1.SubscribableStatus{ - Subscribers: subscribersv1, + SubscribableStatus: eventingduckv1.SubscribableStatus{ + Subscribers: subscribers, }, SubscribableTypeStatus: SubscribableTypeStatus{ SubscribableStatus: &SubscribableStatus{ - Subscribers: subscribers, - Subscribersv1: subscribersv1, + Subscribers: subscribers, + Subscribersv1beta1: subscribersv1beta1, }, }, } diff --git a/pkg/apis/duck/v1alpha1/channelable_combined_types_test.go b/pkg/apis/duck/v1alpha1/channelable_combined_types_test.go index 9033044a170..8d452be3423 100644 --- a/pkg/apis/duck/v1alpha1/channelable_combined_types_test.go +++ b/pkg/apis/duck/v1alpha1/channelable_combined_types_test.go @@ -49,7 +49,7 @@ func TestChannelableCombinedPopulate(t *testing.T) { delay := "5s" want := &ChannelableCombined{ Spec: ChannelableCombinedSpec{ - SubscribableSpec: eventingduckv1beta1.SubscribableSpec{ + SubscribableSpecv1beta1: eventingduckv1beta1.SubscribableSpec{ // Populate ALL fields Subscribers: []eventingduckv1beta1.SubscriberSpec{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", @@ -63,7 +63,7 @@ func TestChannelableCombinedPopulate(t *testing.T) { ReplyURI: apis.HTTP("sink2"), }}, }, - SubscribableSpecv1: eventingduckv1.SubscribableSpec{ + SubscribableSpec: eventingduckv1.SubscribableSpec{ // Populate ALL fields Subscribers: []eventingduckv1.SubscriberSpec{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", @@ -135,7 +135,7 @@ func TestChannelableCombinedPopulate(t *testing.T) { Hostname: "test-domain", }, }, - SubscribableStatus: eventingduckv1beta1.SubscribableStatus{ + SubscribableStatusv1beta1: eventingduckv1beta1.SubscribableStatus{ Subscribers: []eventingduckv1beta1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, @@ -148,7 +148,7 @@ func TestChannelableCombinedPopulate(t *testing.T) { Message: "Some message", }}, }, - SubscribableStatusv1: eventingduckv1.SubscribableStatus{ + SubscribableStatus: eventingduckv1.SubscribableStatus{ Subscribers: []eventingduckv1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, @@ -163,7 +163,7 @@ func TestChannelableCombinedPopulate(t *testing.T) { }, SubscribableTypeStatus: SubscribableTypeStatus{ SubscribableStatus: &SubscribableStatus{ - Subscribers: []eventingduckv1beta1.SubscriberStatus{{ + Subscribersv1beta1: []eventingduckv1beta1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -174,7 +174,7 @@ func TestChannelableCombinedPopulate(t *testing.T) { Ready: corev1.ConditionFalse, Message: "Some message", }}, - Subscribersv1: []eventingduckv1.SubscriberStatus{{ + Subscribers: []eventingduckv1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, diff --git a/pkg/apis/duck/v1alpha1/channelable_types.go b/pkg/apis/duck/v1alpha1/channelable_types.go index b9910cbfbcf..e0c453273c4 100644 --- a/pkg/apis/duck/v1alpha1/channelable_types.go +++ b/pkg/apis/duck/v1alpha1/channelable_types.go @@ -20,6 +20,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" @@ -123,7 +124,18 @@ func (c *Channelable) Populate() { }, SubscribableTypeStatus: SubscribableTypeStatus{ SubscribableStatus: &SubscribableStatus{ - Subscribers: []eventingduckv1beta1.SubscriberStatus{{ + Subscribers: []eventingduckv1.SubscriberStatus{{ + UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", + ObservedGeneration: 1, + Ready: corev1.ConditionTrue, + Message: "Some message", + }, { + UID: "34c5aec8-deb6-11e8-9f32-f2801f1b9fd1", + ObservedGeneration: 2, + Ready: corev1.ConditionFalse, + Message: "Some message", + }}, + Subscribersv1beta1: []eventingduckv1beta1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, diff --git a/pkg/apis/duck/v1alpha1/channelable_types_test.go b/pkg/apis/duck/v1alpha1/channelable_types_test.go index a699e147004..f9f4eb1f892 100644 --- a/pkg/apis/duck/v1alpha1/channelable_types_test.go +++ b/pkg/apis/duck/v1alpha1/channelable_types_test.go @@ -20,6 +20,7 @@ import ( "testing" corev1 "k8s.io/api/core/v1" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" @@ -93,7 +94,18 @@ func TestChannelablePopulate(t *testing.T) { }, SubscribableTypeStatus: SubscribableTypeStatus{ SubscribableStatus: &SubscribableStatus{ - Subscribers: []eventingduckv1beta1.SubscriberStatus{{ + Subscribersv1beta1: []eventingduckv1beta1.SubscriberStatus{{ + UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", + ObservedGeneration: 1, + Ready: corev1.ConditionTrue, + Message: "Some message", + }, { + UID: "34c5aec8-deb6-11e8-9f32-f2801f1b9fd1", + ObservedGeneration: 2, + Ready: corev1.ConditionFalse, + Message: "Some message", + }}, + Subscribers: []eventingduckv1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, diff --git a/pkg/apis/duck/v1alpha1/subscribable_types.go b/pkg/apis/duck/v1alpha1/subscribable_types.go index 43c073c55d7..88656cd9c8d 100644 --- a/pkg/apis/duck/v1alpha1/subscribable_types.go +++ b/pkg/apis/duck/v1alpha1/subscribable_types.go @@ -72,12 +72,12 @@ type SubscribableStatus struct { // This is the list of subscription's statuses for this channel. // +patchMergeKey=uid // +patchStrategy=merge - Subscribers []duckv1beta1.SubscriberStatus `json:"subscribers,omitempty" patchStrategy:"merge" patchMergeKey:"uid"` + Subscribersv1beta1 []duckv1beta1.SubscriberStatus `json:"subscribers,omitempty" patchStrategy:"merge" patchMergeKey:"uid"` // This is the list of subscription's statuses for this channel. // +patchMergeKey=uid // +patchStrategy=merge - Subscribersv1 []duckv1.SubscriberStatus `json:"subscribersv1,omitempty" patchStrategy:"merge" patchMergeKey:"uid"` + Subscribers []duckv1.SubscriberStatus `json:"subscribersv1,omitempty" patchStrategy:"merge" patchMergeKey:"uid"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -139,17 +139,17 @@ func (s *SubscribableTypeStatus) SetSubscribableTypeStatus(subscriberStatus Subs // AddSubscriberToSubscribableStatus method is a Helper method for type SubscribableTypeStatus, if Subscribable Status needs to be appended // with Subscribers, use this function, so that the value is reflected in both the duplicate fields residing // in SubscribableTypeStatus -func (s *SubscribableTypeStatus) AddSubscriberToSubscribableStatus(subscriberStatus duckv1beta1.SubscriberStatus) { - subscribers := append(s.GetSubscribableTypeStatus().Subscribers, subscriberStatus) - s.SubscribableStatus.Subscribers = subscribers +func (s *SubscribableTypeStatus) AddSubscriberv1beta1ToSubscribableStatus(subscriberStatus duckv1beta1.SubscriberStatus) { + subscribers := append(s.GetSubscribableTypeStatus().Subscribersv1beta1, subscriberStatus) + s.SubscribableStatus.Subscribersv1beta1 = subscribers } // AddSubscriberToSubscribableStatus method is a Helper method for type SubscribableTypeStatus, if Subscribable Status needs to be appended // with Subscribers, use this function, so that the value is reflected in both the duplicate fields residing // in SubscribableTypeStatus -func (s *SubscribableTypeStatus) AddSubscriberV1ToSubscribableStatus(subscriberStatus duckv1.SubscriberStatus) { - subscribersv1 := append(s.GetSubscribableTypeStatus().Subscribersv1, subscriberStatus) - s.SubscribableStatus.Subscribersv1 = subscribersv1 +func (s *SubscribableTypeStatus) AddSubscriberToSubscribableStatus(subscriberStatus duckv1.SubscriberStatus) { + subscribersv1 := append(s.GetSubscribableTypeStatus().Subscribers, subscriberStatus) + s.SubscribableStatus.Subscribers = subscribersv1 } // GetFullType implements duck.Implementable @@ -175,7 +175,7 @@ func (c *SubscribableType) Populate() { } c.Status.SetSubscribableTypeStatus(SubscribableStatus{ // Populate ALL fields - Subscribers: []duckv1beta1.SubscriberStatus{{ + Subscribersv1beta1: []duckv1beta1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -186,7 +186,7 @@ func (c *SubscribableType) Populate() { Ready: corev1.ConditionFalse, Message: "Some message", }}, - Subscribersv1: []duckv1.SubscriberStatus{{ + Subscribers: []duckv1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, diff --git a/pkg/apis/duck/v1alpha1/subscribable_types_conversion.go b/pkg/apis/duck/v1alpha1/subscribable_types_conversion.go index 5c819b29007..cdabe274b84 100644 --- a/pkg/apis/duck/v1alpha1/subscribable_types_conversion.go +++ b/pkg/apis/duck/v1alpha1/subscribable_types_conversion.go @@ -126,9 +126,9 @@ func (source *SubscribableTypeStatus) ConvertTo(ctx context.Context, obj apis.Co switch sink := obj.(type) { case *eventingduckv1beta1.SubscribableStatus: if source.SubscribableStatus != nil && - len(source.SubscribableStatus.Subscribers) > 0 { - sink.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, len(source.SubscribableStatus.Subscribers)) - for i, ss := range source.SubscribableStatus.Subscribers { + len(source.SubscribableStatus.Subscribersv1beta1) > 0 { + sink.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, len(source.SubscribableStatus.Subscribersv1beta1)) + for i, ss := range source.SubscribableStatus.Subscribersv1beta1 { sink.Subscribers[i] = eventingduckv1beta1.SubscriberStatus{ UID: ss.UID, ObservedGeneration: ss.ObservedGeneration, @@ -139,9 +139,9 @@ func (source *SubscribableTypeStatus) ConvertTo(ctx context.Context, obj apis.Co } case *eventingduckv1.SubscribableStatus: if source.SubscribableStatus != nil && - len(source.SubscribableStatus.Subscribersv1) > 0 { - sink.Subscribers = make([]eventingduckv1.SubscriberStatus, len(source.SubscribableStatus.Subscribersv1)) - for i, ss := range source.SubscribableStatus.Subscribersv1 { + len(source.SubscribableStatus.Subscribers) > 0 { + sink.Subscribers = make([]eventingduckv1.SubscriberStatus, len(source.SubscribableStatus.Subscribers)) + for i, ss := range source.SubscribableStatus.Subscribers { sink.Subscribers[i] = eventingduckv1.SubscriberStatus{ UID: ss.UID, ObservedGeneration: ss.ObservedGeneration, @@ -250,10 +250,10 @@ func (sink *SubscribableTypeStatus) ConvertFrom(ctx context.Context, obj apis.Co case *eventingduckv1beta1.SubscribableStatus: if len(source.Subscribers) > 0 { sink.SubscribableStatus = &SubscribableStatus{ - Subscribers: make([]eventingduckv1beta1.SubscriberStatus, len(source.Subscribers)), + Subscribersv1beta1: make([]eventingduckv1beta1.SubscriberStatus, len(source.Subscribers)), } for i, ss := range source.Subscribers { - sink.SubscribableStatus.Subscribers[i] = eventingduckv1beta1.SubscriberStatus{ + sink.SubscribableStatus.Subscribersv1beta1[i] = eventingduckv1beta1.SubscriberStatus{ UID: ss.UID, ObservedGeneration: ss.ObservedGeneration, Ready: ss.Ready, @@ -264,10 +264,10 @@ func (sink *SubscribableTypeStatus) ConvertFrom(ctx context.Context, obj apis.Co case *eventingduckv1.SubscribableStatus: if len(source.Subscribers) > 0 { sink.SubscribableStatus = &SubscribableStatus{ - Subscribersv1: make([]eventingduckv1.SubscriberStatus, len(source.Subscribers)), + Subscribers: make([]eventingduckv1.SubscriberStatus, len(source.Subscribers)), } for i, ss := range source.Subscribers { - sink.SubscribableStatus.Subscribersv1[i] = eventingduckv1.SubscriberStatus{ + sink.SubscribableStatus.Subscribers[i] = eventingduckv1.SubscriberStatus{ UID: ss.UID, ObservedGeneration: ss.ObservedGeneration, Ready: ss.Ready, diff --git a/pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go b/pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go index 0ca39c24ac3..18ec9cb107b 100644 --- a/pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go +++ b/pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go @@ -109,7 +109,7 @@ func TestSubscribableTypeConversionV1alphaV1beta1(t *testing.T) { }, Status: SubscribableTypeStatus{ SubscribableStatus: &SubscribableStatus{ - Subscribers: []v1beta1.SubscriberStatus{ + Subscribersv1beta1: []v1beta1.SubscriberStatus{ { UID: "status-uid-1", ObservedGeneration: 99, @@ -208,7 +208,7 @@ func TestSubscribableTypeConversionV1alphaV1(t *testing.T) { }, Status: SubscribableTypeStatus{ SubscribableStatus: &SubscribableStatus{ - Subscribersv1: []v1.SubscriberStatus{ + Subscribers: []v1.SubscriberStatus{ { UID: "status-uid-1", ObservedGeneration: 99, diff --git a/pkg/apis/duck/v1alpha1/subscribable_types_test.go b/pkg/apis/duck/v1alpha1/subscribable_types_test.go index f5538dd9a8c..643f3892ec5 100644 --- a/pkg/apis/duck/v1alpha1/subscribable_types_test.go +++ b/pkg/apis/duck/v1alpha1/subscribable_types_test.go @@ -68,7 +68,7 @@ func TestSubscribablePopulate(t *testing.T) { Status: SubscribableTypeStatus{ SubscribableStatus: &SubscribableStatus{ // Populate ALL fields - Subscribers: []eventingduckv1beta1.SubscriberStatus{{ + Subscribersv1beta1: []eventingduckv1beta1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -79,7 +79,7 @@ func TestSubscribablePopulate(t *testing.T) { Ready: corev1.ConditionFalse, Message: "Some message", }}, - Subscribersv1: []eventingduckv1.SubscriberStatus{{ + Subscribers: []eventingduckv1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -105,7 +105,7 @@ func TestSubscribablePopulate(t *testing.T) { func TestSubscribableTypeStatusHelperMethods(t *testing.T) { s := &SubscribableStatus{ // Populate ALL fields - Subscribers: []eventingduckv1beta1.SubscriberStatus{{ + Subscribersv1beta1: []eventingduckv1beta1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -116,7 +116,7 @@ func TestSubscribableTypeStatusHelperMethods(t *testing.T) { Ready: corev1.ConditionFalse, Message: "This is new field", }}, - Subscribersv1: []eventingduckv1.SubscriberStatus{{ + Subscribers: []eventingduckv1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -150,7 +150,7 @@ func TestSubscribableTypeStatusHelperMethods(t *testing.T) { } /* Test AddSubscriberToSubscribableStatus */ - subscribableTypeStatus.AddSubscriberToSubscribableStatus(eventingduckv1beta1.SubscriberStatus{ + subscribableTypeStatus.AddSubscriberv1beta1ToSubscribableStatus(eventingduckv1beta1.SubscriberStatus{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, @@ -158,7 +158,7 @@ func TestSubscribableTypeStatusHelperMethods(t *testing.T) { }) /* Test AddSubscriberV1ToSubscribableStatus */ - subscribableTypeStatus.AddSubscriberV1ToSubscribableStatus(eventingduckv1.SubscriberStatus{ + subscribableTypeStatus.AddSubscriberToSubscribableStatus(eventingduckv1.SubscriberStatus{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, Ready: corev1.ConditionTrue, diff --git a/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go index 43c16005d70..722e7d1fd72 100644 --- a/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go @@ -121,13 +121,13 @@ func (in *ChannelableCombinedList) DeepCopyObject() runtime.Object { func (in *ChannelableCombinedSpec) DeepCopyInto(out *ChannelableCombinedSpec) { *out = *in in.SubscribableTypeSpec.DeepCopyInto(&out.SubscribableTypeSpec) - in.SubscribableSpec.DeepCopyInto(&out.SubscribableSpec) + in.SubscribableSpecv1beta1.DeepCopyInto(&out.SubscribableSpecv1beta1) if in.Delivery != nil { in, out := &in.Delivery, &out.Delivery *out = new(v1beta1.DeliverySpec) (*in).DeepCopyInto(*out) } - in.SubscribableSpecv1.DeepCopyInto(&out.SubscribableSpecv1) + in.SubscribableSpec.DeepCopyInto(&out.SubscribableSpec) if in.Deliveryv1 != nil { in, out := &in.Deliveryv1, &out.Deliveryv1 *out = new(v1.DeliverySpec) @@ -152,8 +152,8 @@ func (in *ChannelableCombinedStatus) DeepCopyInto(out *ChannelableCombinedStatus in.Status.DeepCopyInto(&out.Status) in.AddressStatus.DeepCopyInto(&out.AddressStatus) in.SubscribableTypeStatus.DeepCopyInto(&out.SubscribableTypeStatus) + in.SubscribableStatusv1beta1.DeepCopyInto(&out.SubscribableStatusv1beta1) in.SubscribableStatus.DeepCopyInto(&out.SubscribableStatus) - in.SubscribableStatusv1.DeepCopyInto(&out.SubscribableStatusv1) if in.ErrorChannel != nil { in, out := &in.ErrorChannel, &out.ErrorChannel *out = new(corev1.ObjectReference) @@ -336,13 +336,13 @@ func (in *Subscribable) DeepCopy() *Subscribable { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SubscribableStatus) DeepCopyInto(out *SubscribableStatus) { *out = *in - if in.Subscribers != nil { - in, out := &in.Subscribers, &out.Subscribers + if in.Subscribersv1beta1 != nil { + in, out := &in.Subscribersv1beta1, &out.Subscribersv1beta1 *out = make([]v1beta1.SubscriberStatus, len(*in)) copy(*out, *in) } - if in.Subscribersv1 != nil { - in, out := &in.Subscribersv1, &out.Subscribersv1 + if in.Subscribers != nil { + in, out := &in.Subscribers, &out.Subscribers *out = make([]v1.SubscriberStatus, len(*in)) copy(*out, *in) } diff --git a/pkg/reconciler/channel/channel.go b/pkg/reconciler/channel/channel.go index 54a91947726..9e05504384c 100644 --- a/pkg/reconciler/channel/channel.go +++ b/pkg/reconciler/channel/channel.go @@ -25,12 +25,12 @@ import ( "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/dynamic" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/eventing/pkg/apis/messaging" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1beta1/channel" - listers "knative.dev/eventing/pkg/client/listers/messaging/v1beta1" + v1 "knative.dev/eventing/pkg/apis/messaging/v1" + channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/channel" + listers "knative.dev/eventing/pkg/client/listers/messaging/v1" eventingduck "knative.dev/eventing/pkg/duck" "knative.dev/eventing/pkg/logging" "knative.dev/eventing/pkg/reconciler/channel/resources" @@ -52,7 +52,7 @@ type Reconciler struct { var _ channelreconciler.Interface = (*Reconciler)(nil) // ReconcileKind implements Interface.ReconcileKind. -func (r *Reconciler) ReconcileKind(ctx context.Context, c *v1beta1.Channel) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, c *v1.Channel) pkgreconciler.Event { // 1. Create the backing Channel CRD, if it doesn't exist. // 2. Propagate the backing Channel CRD Status, Address, and SubscribableStatus into this Channel. @@ -88,38 +88,30 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, c *v1beta1.Channel) pkgr return nil } -func (r *Reconciler) getChannelableStatus(ctx context.Context, bc *duckv1alpha1.ChannelableCombinedStatus, cAnnotations map[string]string) *duckv1beta1.ChannelableStatus { +func (r *Reconciler) getChannelableStatus(ctx context.Context, bc *duckv1alpha1.ChannelableCombinedStatus, cAnnotations map[string]string) *eventingduckv1.ChannelableStatus { - channelableStatus := &duckv1beta1.ChannelableStatus{} + channelableStatus := &eventingduckv1.ChannelableStatus{} if bc.AddressStatus.Address != nil { channelableStatus.AddressStatus.Address = &duckv1.Addressable{} bc.AddressStatus.Address.ConvertTo(ctx, channelableStatus.AddressStatus.Address) } channelableStatus.Status = bc.Status if cAnnotations != nil && - cAnnotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" { + cAnnotations[messaging.SubscribableDuckVersionAnnotation] == "v1" { 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, - } - } + channelableStatus.SubscribableStatus.Subscribers = bc.SubscribableTypeStatus.SubscribableStatus.Subscribers } } return channelableStatus } // reconcileBackingChannel reconciles Channel's 'c' underlying CRD channel. -func (r *Reconciler) reconcileBackingChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, c *v1beta1.Channel, backingChannelObjRef duckv1.KReference) (*duckv1alpha1.ChannelableCombined, error) { +func (r *Reconciler) reconcileBackingChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, c *v1.Channel, backingChannelObjRef duckv1.KReference) (*duckv1alpha1.ChannelableCombined, error) { lister, err := r.channelableTracker.ListerForKReference(backingChannelObjRef) if err != nil { logging.FromContext(ctx).Error("Error getting lister for Channel", zap.Any("backingChannel", backingChannelObjRef), zap.Error(err)) diff --git a/pkg/reconciler/channel/channel_test.go b/pkg/reconciler/channel/channel_test.go index dc81d841771..d45e6d81133 100644 --- a/pkg/reconciler/channel/channel_test.go +++ b/pkg/reconciler/channel/channel_test.go @@ -21,7 +21,6 @@ import ( "fmt" "testing" - "k8s.io/api/apps/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -29,13 +28,17 @@ 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" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" + v1 "knative.dev/eventing/pkg/apis/duck/v1" + v1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined" - channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1beta1/channel" + channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/channel" "knative.dev/eventing/pkg/duck" - . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" + . "knative.dev/eventing/pkg/reconciler/testing/v1" "knative.dev/eventing/pkg/utils" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" @@ -59,8 +62,12 @@ var ( func init() { // Add types to scheme - _ = v1beta1.AddToScheme(scheme.Scheme) - _ = eventingduckv1alpha1.AddToScheme(scheme.Scheme) + // TODO(nlopezgi): figure out what is the right list to have here. + _ = messagingv1beta1.AddToScheme(scheme.Scheme) + _ = messagingv1.AddToScheme(scheme.Scheme) + _ = v1.AddToScheme(scheme.Scheme) + _ = v1alpha1.AddToScheme(scheme.Scheme) + _ = eventingduckv1.AddToScheme(scheme.Scheme) } func TestReconcile(t *testing.T) { @@ -280,7 +287,7 @@ func TestReconcile(t *testing.T) { func channelCRD() metav1.TypeMeta { return metav1.TypeMeta{ - APIVersion: "messaging.knative.dev/v1beta1", + APIVersion: "messaging.knative.dev/v1", Kind: "InMemoryChannel", } } @@ -292,8 +299,8 @@ func channelableV1Alpha1CRD() metav1.TypeMeta { } } -func subscribers() []eventingduckv1beta1.SubscriberSpec { - return []eventingduckv1beta1.SubscriberSpec{{ +func subscribers() []eventingduckv1.SubscriberSpec { + return []eventingduckv1.SubscriberSpec{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", Generation: 1, SubscriberURI: apis.HTTP("call1"), @@ -306,8 +313,8 @@ func subscribers() []eventingduckv1beta1.SubscriberSpec { }} } -func subscribersV1Alpha1() []eventingduckv1alpha1.SubscriberSpec { - return []eventingduckv1alpha1.SubscriberSpec{{ +func subscribersV1Alpha1() []v1alpha1.SubscriberSpec { + return []v1alpha1.SubscriberSpec{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", Generation: 1, SubscriberURI: apis.HTTP("call1"), @@ -320,7 +327,18 @@ func subscribersV1Alpha1() []eventingduckv1alpha1.SubscriberSpec { }} } -func subscriberStatuses() []eventingduckv1beta1.SubscriberStatus { +func subscriberStatuses() []eventingduckv1.SubscriberStatus { + return []eventingduckv1.SubscriberStatus{{ + UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", + ObservedGeneration: 1, + Ready: "True", + }, { + UID: "34c5aec8-deb6-11e8-9f32-f2801f1b9fd1", + ObservedGeneration: 2, + Ready: "True", + }} +} +func subscriberStatusesV1beta1() []eventingduckv1beta1.SubscriberStatus { return []eventingduckv1beta1.SubscriberStatus{{ UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", ObservedGeneration: 1, @@ -335,7 +353,7 @@ func subscriberStatuses() []eventingduckv1beta1.SubscriberStatus { func createChannelCRD(namespace, name string, ready bool) *unstructured.Unstructured { u := &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1beta1", + "apiVersion": "messaging.knative.dev/v1", "kind": "InMemoryChannel", "metadata": map[string]interface{}{ "creationTimestamp": nil, @@ -343,7 +361,7 @@ func createChannelCRD(namespace, name string, ready bool) *unstructured.Unstruct "name": name, "ownerReferences": []interface{}{ map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1beta1", + "apiVersion": "messaging.knative.dev/v1", "blockOwnerDeletion": true, "controller": true, "kind": "Channel", @@ -367,7 +385,7 @@ func createChannelCRD(namespace, name string, ready bool) *unstructured.Unstruct func backingChannelObjRef() *duckv1.KReference { return &duckv1.KReference{ - APIVersion: "messaging.knative.dev/v1beta1", + APIVersion: "messaging.knative.dev/v1", Kind: "InMemoryChannel", Namespace: testNS, Name: channelName, @@ -389,7 +407,7 @@ func createChannel(namespace, name string, ready bool) *unstructured.Unstructure if ready { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1beta1", + "apiVersion": "messaging.knative.dev/v1", "kind": "InMemoryChannel", "metadata": map[string]interface{}{ "creationTimestamp": nil, @@ -397,7 +415,7 @@ func createChannel(namespace, name string, ready bool) *unstructured.Unstructure "name": name, "ownerReferences": []interface{}{ map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1beta1", + "apiVersion": "messaging.knative.dev/v1", "blockOwnerDeletion": true, "controller": true, "kind": "Channel", @@ -418,7 +436,7 @@ func createChannel(namespace, name string, ready bool) *unstructured.Unstructure return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1beta1", + "apiVersion": "messaging.knative.dev/v1", "kind": "InMemoryChannel", "metadata": map[string]interface{}{ "creationTimestamp": nil, @@ -426,7 +444,7 @@ func createChannel(namespace, name string, ready bool) *unstructured.Unstructure "name": name, "ownerReferences": []interface{}{ map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1beta1", + "apiVersion": "messaging.knative.dev/v1", "blockOwnerDeletion": true, "controller": true, "kind": "Channel", diff --git a/pkg/reconciler/channel/controller.go b/pkg/reconciler/channel/controller.go index 285999bdbf9..07511f841fa 100644 --- a/pkg/reconciler/channel/controller.go +++ b/pkg/reconciler/channel/controller.go @@ -25,8 +25,8 @@ import ( "knative.dev/pkg/logging" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined" - channelinformer "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/channel" - channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1beta1/channel" + channelinformer "knative.dev/eventing/pkg/client/injection/informers/messaging/v1/channel" + channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/channel" "knative.dev/eventing/pkg/duck" ) diff --git a/pkg/reconciler/channel/controller_test.go b/pkg/reconciler/channel/controller_test.go index d2346a87de3..3126685a3ee 100644 --- a/pkg/reconciler/channel/controller_test.go +++ b/pkg/reconciler/channel/controller_test.go @@ -25,7 +25,7 @@ import ( // Fake injection informers _ "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/v1/channel/fake" _ "knative.dev/pkg/client/injection/kube/client/fake" _ "knative.dev/pkg/injection/clients/dynamicclient/fake" ) diff --git a/pkg/reconciler/channel/resources/channel.go b/pkg/reconciler/channel/resources/channel.go index b6cb1c2d036..3d2c9da7fe5 100644 --- a/pkg/reconciler/channel/resources/channel.go +++ b/pkg/reconciler/channel/resources/channel.go @@ -23,13 +23,13 @@ import ( "knative.dev/pkg/kmeta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" + v1 "knative.dev/eventing/pkg/apis/messaging/v1" ) // NewChannel returns an unstructured.Unstructured based on the ChannelTemplateSpec for a given Channel. -func NewChannel(c *v1beta1.Channel) (*unstructured.Unstructured, error) { +func NewChannel(c *v1.Channel) (*unstructured.Unstructured, error) { // Set the name of the resource we're creating as well as the namespace, etc. - template := v1beta1.ChannelTemplateSpecInternal{ + template := v1.ChannelTemplateSpecInternal{ TypeMeta: metav1.TypeMeta{ Kind: c.Spec.ChannelTemplate.Kind, APIVersion: c.Spec.ChannelTemplate.APIVersion, diff --git a/pkg/reconciler/subscription/controller.go b/pkg/reconciler/subscription/controller.go index 295e8cb232f..f8f8a5ec0ca 100644 --- a/pkg/reconciler/subscription/controller.go +++ b/pkg/reconciler/subscription/controller.go @@ -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" ) @@ -67,7 +67,7 @@ func NewController( // populated. controller.EnsureTypeMeta( r.tracker.OnChanged, - messagingv1beta1.SchemeGroupVersion.WithKind("Channel"), + messagingv1.SchemeGroupVersion.WithKind("Channel"), ), )) diff --git a/pkg/reconciler/subscription/controller_test.go b/pkg/reconciler/subscription/controller_test.go index b956c556c6a..1a34920eb20 100644 --- a/pkg/reconciler/subscription/controller_test.go +++ b/pkg/reconciler/subscription/controller_test.go @@ -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" ) diff --git a/pkg/reconciler/subscription/subscription.go b/pkg/reconciler/subscription/subscription.go index d9e94ea25fa..56a0c1e07ac 100644 --- a/pkg/reconciler/subscription/subscription.go +++ b/pkg/reconciler/subscription/subscription.go @@ -35,13 +35,12 @@ import ( "knative.dev/pkg/resolver" "knative.dev/pkg/tracker" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/eventing/pkg/apis/messaging" v1 "knative.dev/eventing/pkg/apis/messaging/v1" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - subscriptionreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1beta1/subscription" - listers "knative.dev/eventing/pkg/client/listers/messaging/v1beta1" + subscriptionreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/subscription" + listers "knative.dev/eventing/pkg/client/listers/messaging/v1" eventingduck "knative.dev/eventing/pkg/duck" "knative.dev/eventing/pkg/logging" ) @@ -58,8 +57,7 @@ const ( ) var ( - v1beta1ChannelGVK = v1beta1.SchemeGroupVersion.WithKind("Channel") - v1ChannelGVK = v1.SchemeGroupVersion.WithKind("Channel") + v1ChannelGVK = v1.SchemeGroupVersion.WithKind("Channel") ) func newChannelWarnEvent(messageFmt string, args ...interface{}) pkgreconciler.Event { @@ -85,7 +83,7 @@ var _ subscriptionreconciler.Interface = (*Reconciler)(nil) var _ subscriptionreconciler.Finalizer = (*Reconciler)(nil) // ReconcileKind implements Interface.ReconcileKind. -func (r *Reconciler) ReconcileKind(ctx context.Context, subscription *v1beta1.Subscription) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, subscription *v1.Subscription) pkgreconciler.Event { // Find the channel for this subscription. channel, err := r.getChannel(ctx, subscription) if err != nil { @@ -116,7 +114,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, subscription *v1beta1.Su return nil } -func (r *Reconciler) FinalizeKind(ctx context.Context, subscription *v1beta1.Subscription) pkgreconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, subscription *v1.Subscription) pkgreconciler.Event { channel, err := r.getChannel(ctx, subscription) if err != nil { // If the channel was deleted (i.e., error == notFound), just return nil so that @@ -133,7 +131,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, subscription *v1beta1.Sub return nil } -func (r Reconciler) checkChannelStatusForSubscription(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) pkgreconciler.Event { +func (r Reconciler) checkChannelStatusForSubscription(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) pkgreconciler.Event { ss, err := r.getSubStatus(sub, channel) if err != nil { logging.FromContext(ctx).Warn("Failed to get subscription status.", zap.Error(err)) @@ -153,7 +151,7 @@ func (r Reconciler) checkChannelStatusForSubscription(ctx context.Context, chann return nil } -func (r Reconciler) syncChannel(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) pkgreconciler.Event { +func (r Reconciler) syncChannel(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) pkgreconciler.Event { // Ok, now that we have the Channel and at least one of the Call/Result, let's reconcile // the Channel with this information. if patched, err := r.syncPhysicalChannel(ctx, sub, channel, false); err != nil { @@ -174,7 +172,7 @@ func (r Reconciler) syncChannel(ctx context.Context, channel *eventingduckv1alph return nil } -func (r *Reconciler) resolveSubscriptionURIs(ctx context.Context, subscription *v1beta1.Subscription) pkgreconciler.Event { +func (r *Reconciler) resolveSubscriptionURIs(ctx context.Context, subscription *v1.Subscription) pkgreconciler.Event { // Everything that was supposed to be resolved was, so flip the status bit on that. subscription.Status.MarkReferencesResolvedUnknown("Resolving", "Subscription resolution interrupted.") @@ -195,7 +193,7 @@ func (r *Reconciler) resolveSubscriptionURIs(ctx context.Context, subscription * return nil } -func (r *Reconciler) resolveSubscriber(ctx context.Context, subscription *v1beta1.Subscription) pkgreconciler.Event { +func (r *Reconciler) resolveSubscriber(ctx context.Context, subscription *v1.Subscription) pkgreconciler.Event { // Resolve Subscriber. subscriber := subscription.Spec.Subscriber.DeepCopy() if !isNilOrEmptyDestination(subscriber) { @@ -222,7 +220,7 @@ func (r *Reconciler) resolveSubscriber(ctx context.Context, subscription *v1beta return nil } -func (r *Reconciler) resolveReply(ctx context.Context, subscription *v1beta1.Subscription) pkgreconciler.Event { +func (r *Reconciler) resolveReply(ctx context.Context, subscription *v1.Subscription) pkgreconciler.Event { // Resolve Reply. reply := subscription.Spec.Reply.DeepCopy() if !isNilOrEmptyDestination(reply) { @@ -249,7 +247,7 @@ func (r *Reconciler) resolveReply(ctx context.Context, subscription *v1beta1.Sub return nil } -func (r *Reconciler) resolveDeadLetterSink(ctx context.Context, subscription *v1beta1.Subscription) pkgreconciler.Event { +func (r *Reconciler) resolveDeadLetterSink(ctx context.Context, subscription *v1.Subscription) pkgreconciler.Event { // Resolve DeadLetterSink. delivery := subscription.Spec.Delivery.DeepCopy() if !isNilOrEmptyDeliveryDeadLetterSink(delivery) { @@ -277,9 +275,9 @@ func (r *Reconciler) resolveDeadLetterSink(ctx context.Context, subscription *v1 return nil } -func (r *Reconciler) getSubStatus(subscription *v1beta1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1beta1.SubscriberStatus, error) { +func (r *Reconciler) getSubStatus(subscription *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1.SubscriberStatus, error) { if channel.Annotations != nil { - if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" || + if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" || channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" { return r.getSubStatusV1Beta1(subscription, channel) } @@ -287,11 +285,11 @@ func (r *Reconciler) getSubStatus(subscription *v1beta1.Subscription, channel *e return r.getSubStatusV1Alpha1(subscription, channel) } -func (r *Reconciler) getSubStatusV1Alpha1(subscription *v1beta1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1beta1.SubscriberStatus, error) { +func (r *Reconciler) getSubStatusV1Alpha1(subscription *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1.SubscriberStatus, error) { subscribableStatus := channel.Status.GetSubscribableTypeStatus() if subscribableStatus == nil { - return eventingduckv1beta1.SubscriberStatus{}, fmt.Errorf("channel.Status.SubscribableStatus is nil") + return eventingduckv1.SubscriberStatus{}, fmt.Errorf("channel.Status.SubscribableStatus is nil") } for _, sub := range subscribableStatus.Subscribers { if sub.UID == subscription.GetUID() && @@ -299,14 +297,14 @@ func (r *Reconciler) getSubStatusV1Alpha1(subscription *v1beta1.Subscription, ch return sub, nil } } - return eventingduckv1beta1.SubscriberStatus{}, fmt.Errorf("subscription %q not present in channel %q subscriber's list", subscription.Name, channel.Name) + return eventingduckv1.SubscriberStatus{}, fmt.Errorf("subscription %q not present in channel %q subscriber's list", subscription.Name, channel.Name) } -func (r *Reconciler) getSubStatusV1Beta1(subscription *v1beta1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1beta1.SubscriberStatus, error) { +func (r *Reconciler) getSubStatusV1Beta1(subscription *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1.SubscriberStatus, error) { for _, sub := range channel.Status.Subscribers { if sub.UID == subscription.GetUID() && sub.ObservedGeneration == subscription.GetGeneration() { - return eventingduckv1beta1.SubscriberStatus{ + return eventingduckv1.SubscriberStatus{ UID: sub.UID, ObservedGeneration: sub.ObservedGeneration, Ready: sub.Ready, @@ -314,10 +312,10 @@ func (r *Reconciler) getSubStatusV1Beta1(subscription *v1beta1.Subscription, cha }, nil } } - return eventingduckv1beta1.SubscriberStatus{}, fmt.Errorf("subscription %q not present in channel %q subscriber's list", subscription.Name, channel.Name) + return eventingduckv1.SubscriberStatus{}, fmt.Errorf("subscription %q not present in channel %q subscriber's list", subscription.Name, channel.Name) } -func (r *Reconciler) trackAndFetchChannel(ctx context.Context, sub *v1beta1.Subscription, ref corev1.ObjectReference) (runtime.Object, pkgreconciler.Event) { +func (r *Reconciler) trackAndFetchChannel(ctx context.Context, sub *v1.Subscription, ref corev1.ObjectReference) (runtime.Object, pkgreconciler.Event) { // Track the channel using the channelableTracker. // We don't need the explicitly set a channelInformer, as this will dynamically generate one for us. // This code needs to be called before checking the existence of the `channel`, in order to make sure the @@ -342,7 +340,7 @@ func (r *Reconciler) trackAndFetchChannel(ctx context.Context, sub *v1beta1.Subs // and verifies it's a channelable (so that we can operate on it via patches). // If the Channel is a channels.messaging type (hence, it's only a factory for // underlying channels), fetch and validate the "backing" channel. -func (r *Reconciler) getChannel(ctx context.Context, sub *v1beta1.Subscription) (*eventingduckv1alpha1.ChannelableCombined, pkgreconciler.Event) { +func (r *Reconciler) getChannel(ctx context.Context, sub *v1.Subscription) (*eventingduckv1alpha1.ChannelableCombined, pkgreconciler.Event) { logging.FromContext(ctx).Info("Getting channel", zap.Any("channel", sub.Spec.Channel)) // 1. Track the channel pointed by subscription. @@ -358,7 +356,7 @@ func (r *Reconciler) getChannel(ctx context.Context, sub *v1beta1.Subscription) // Test to see if the channel is Channel.messaging because it is going // to have a "backing" channel that is what we need to actually operate on // as well as keep track of. - if (v1beta1ChannelGVK.Group == gvk.Group && v1beta1ChannelGVK.Kind == gvk.Kind) || + if (v1ChannelGVK.Group == gvk.Group && v1ChannelGVK.Kind == gvk.Kind) || (v1ChannelGVK.Group == gvk.Group && v1ChannelGVK.Kind == gvk.Kind) { // Track changes on Channel. // Ref: https://github.com/knative/eventing/issues/2641 @@ -371,7 +369,7 @@ func (r *Reconciler) getChannel(ctx context.Context, sub *v1beta1.Subscription) // to the cache we intend to use to pull the Channel from. This linkage // is setup in NewController for r.tracker. if err := r.tracker.TrackReference(tracker.Reference{ - APIVersion: "messaging.knative.dev/v1beta1", + APIVersion: "messaging.knative.dev/v1", Kind: "Channel", Namespace: sub.Namespace, Name: sub.Spec.Channel.Name, @@ -412,8 +410,8 @@ func (r *Reconciler) getChannel(ctx context.Context, sub *v1beta1.Subscription) return ch.DeepCopy(), nil } -func isNilOrEmptyDeliveryDeadLetterSink(delivery *eventingduckv1beta1.DeliverySpec) bool { - return delivery == nil || equality.Semantic.DeepEqual(delivery, &eventingduckv1beta1.DeliverySpec{}) || +func isNilOrEmptyDeliveryDeadLetterSink(delivery *eventingduckv1.DeliverySpec) bool { + return delivery == nil || equality.Semantic.DeepEqual(delivery, &eventingduckv1.DeliverySpec{}) || delivery.DeadLetterSink == nil } @@ -421,7 +419,7 @@ func isNilOrEmptyDestination(destination *duckv1.Destination) bool { return destination == nil || equality.Semantic.DeepEqual(destination, &duckv1.Destination{}) } -func (r *Reconciler) syncPhysicalChannel(ctx context.Context, sub *v1beta1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined, isDeleted bool) (bool, error) { +func (r *Reconciler) syncPhysicalChannel(ctx context.Context, sub *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined, isDeleted bool) (bool, error) { logging.FromContext(ctx).Debug("Reconciling physical from Channel", zap.Any("sub", sub)) if patched, patchErr := r.patchSubscription(ctx, sub.Namespace, channel, sub); patchErr != nil { if isDeleted && apierrors.IsNotFound(patchErr) { @@ -434,7 +432,7 @@ func (r *Reconciler) syncPhysicalChannel(ctx context.Context, sub *v1beta1.Subsc } } -func (r *Reconciler) patchSubscription(ctx context.Context, namespace string, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) (bool, error) { +func (r *Reconciler) patchSubscription(ctx context.Context, namespace string, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) (bool, error) { after := channel.DeepCopy() if sub.DeletionTimestamp.IsZero() { @@ -467,9 +465,9 @@ func (r *Reconciler) patchSubscription(ctx context.Context, namespace string, ch return true, nil } -func (r *Reconciler) updateChannelRemoveSubscription(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) { +func (r *Reconciler) updateChannelRemoveSubscription(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { if channel.Annotations != nil { - if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" || + if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" || channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" { r.updateChannelRemoveSubscriptionV1Beta1(ctx, channel, sub) return @@ -478,7 +476,7 @@ func (r *Reconciler) updateChannelRemoveSubscription(ctx context.Context, channe r.updateChannelRemoveSubscriptionV1Alpha1(ctx, channel, sub) } -func (r *Reconciler) updateChannelRemoveSubscriptionV1Beta1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) { +func (r *Reconciler) updateChannelRemoveSubscriptionV1Beta1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { for i, v := range channel.Spec.Subscribers { if v.UID == sub.UID { channel.Spec.Subscribers = append( @@ -489,7 +487,7 @@ func (r *Reconciler) updateChannelRemoveSubscriptionV1Beta1(ctx context.Context, } } -func (r *Reconciler) updateChannelRemoveSubscriptionV1Alpha1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) { +func (r *Reconciler) updateChannelRemoveSubscriptionV1Alpha1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { if channel.Spec.Subscribable == nil { return } @@ -504,9 +502,9 @@ func (r *Reconciler) updateChannelRemoveSubscriptionV1Alpha1(ctx context.Context } } -func (r *Reconciler) updateChannelAddSubscription(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) { +func (r *Reconciler) updateChannelAddSubscription(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { if channel.Annotations != nil { - if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" || + if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" || channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" { r.updateChannelAddSubscriptionV1Beta1(ctx, channel, sub) return @@ -515,7 +513,7 @@ func (r *Reconciler) updateChannelAddSubscription(ctx context.Context, channel * r.updateChannelAddSubscriptionV1Alpha1(ctx, channel, sub) } -func (r *Reconciler) updateChannelAddSubscriptionV1Alpha1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) { +func (r *Reconciler) updateChannelAddSubscriptionV1Alpha1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { if channel.Spec.Subscribable == nil { channel.Spec.Subscribable = &eventingduckv1alpha1.Subscribable{ Subscribers: []eventingduckv1alpha1.SubscriberSpec{{ @@ -551,7 +549,7 @@ func (r *Reconciler) updateChannelAddSubscriptionV1Alpha1(ctx context.Context, c }) } -func (r *Reconciler) updateChannelAddSubscriptionV1Beta1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1beta1.Subscription) { +func (r *Reconciler) updateChannelAddSubscriptionV1Beta1(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { // Look to update subscriber. for i, v := range channel.Spec.Subscribers { if v.UID == sub.UID { @@ -561,7 +559,7 @@ func (r *Reconciler) updateChannelAddSubscriptionV1Beta1(ctx context.Context, ch // Only set the deadletter sink if it's not nil. Otherwise we'll just end up patching // empty delivery in there. if sub.Status.PhysicalSubscription.DeadLetterSinkURI != nil { - channel.Spec.Subscribers[i].Delivery = &eventingduckv1beta1.DeliverySpec{ + channel.Spec.Subscribers[i].Delivery = &eventingduckv1.DeliverySpec{ DeadLetterSink: &duckv1.Destination{ URI: sub.Status.PhysicalSubscription.DeadLetterSinkURI, }, @@ -571,7 +569,7 @@ func (r *Reconciler) updateChannelAddSubscriptionV1Beta1(ctx context.Context, ch } } - toAdd := eventingduckv1beta1.SubscriberSpec{ + toAdd := eventingduckv1.SubscriberSpec{ UID: sub.UID, Generation: sub.Generation, SubscriberURI: sub.Status.PhysicalSubscription.SubscriberURI, @@ -580,7 +578,7 @@ func (r *Reconciler) updateChannelAddSubscriptionV1Beta1(ctx context.Context, ch // Only set the deadletter sink if it's not nil. Otherwise we'll just end up patching // empty delivery in there. if sub.Status.PhysicalSubscription.DeadLetterSinkURI != nil { - toAdd.Delivery = &eventingduckv1beta1.DeliverySpec{ + toAdd.Delivery = &eventingduckv1.DeliverySpec{ DeadLetterSink: &duckv1.Destination{ URI: sub.Status.PhysicalSubscription.DeadLetterSinkURI, }, diff --git a/pkg/reconciler/subscription/subscription_test.go b/pkg/reconciler/subscription/subscription_test.go index b785e2b9203..648f5a8962e 100644 --- a/pkg/reconciler/subscription/subscription_test.go +++ b/pkg/reconciler/subscription/subscription_test.go @@ -22,23 +22,23 @@ import ( "fmt" "testing" - eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" + eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" eventingclient "knative.dev/eventing/pkg/client/injection/client" "knative.dev/pkg/injection/clients/dynamicclient" corev1 "k8s.io/api/core/v1" - apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" clientgotesting "k8s.io/client-go/testing" + eventingduck "knative.dev/eventing/pkg/apis/duck/v1" eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1beta1" - 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/channelable" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined" - "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1beta1/subscription" + "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/subscription" "knative.dev/eventing/pkg/duck" "knative.dev/eventing/pkg/utils" "knative.dev/pkg/apis" @@ -50,9 +50,9 @@ import ( logtesting "knative.dev/pkg/logging/testing" "knative.dev/pkg/resolver" - _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/channel/fake" - _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/inmemorychannel/fake" - . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" + _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1/channel/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1/inmemorychannel/fake" + . "knative.dev/eventing/pkg/reconciler/testing/v1" . "knative.dev/pkg/reconciler/testing" ) @@ -139,11 +139,11 @@ var ( func init() { // Add types to scheme - _ = eventingv1beta1.AddToScheme(scheme.Scheme) + _ = eventingv1.AddToScheme(scheme.Scheme) _ = duckv1alpha1.AddToScheme(scheme.Scheme) _ = eventingduckv1alpha1.AddToScheme(scheme.Scheme) - _ = apiextensionsv1beta1.AddToScheme(scheme.Scheme) - _ = messagingv1beta1.AddToScheme(scheme.Scheme) + _ = apiextensionsv1.AddToScheme(scheme.Scheme) + _ = messagingv1.AddToScheme(scheme.Scheme) } func TestAllCases(t *testing.T) { diff --git a/pkg/reconciler/testing/v1/channel.go b/pkg/reconciler/testing/v1/channel.go new file mode 100644 index 00000000000..1a9215a55a1 --- /dev/null +++ b/pkg/reconciler/testing/v1/channel.go @@ -0,0 +1,144 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + "context" + "time" + + "k8s.io/apimachinery/pkg/types" + + v1 "k8s.io/api/core/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" + eventingv1 "knative.dev/eventing/pkg/apis/messaging/v1" + messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +// ChannelOption enables further configuration of a Channel. +type ChannelOption func(*eventingv1.Channel) + +// NewChannel creates a Channel with ChannelOptions +func NewChannel(name, namespace string, o ...ChannelOption) *eventingv1.Channel { + c := &eventingv1.Channel{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Channel", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + } + for _, opt := range o { + opt(c) + } + c.SetDefaults(context.Background()) + return c +} + +// WithInitChannelConditions initializes the Channel's conditions. +func WithInitChannelConditions(c *eventingv1.Channel) { + c.Status.InitializeConditions() +} + +func WithNoAnnotations(c *eventingv1.Channel) { + c.ObjectMeta.Annotations = nil +} + +func WithChannelGeneration(gen int64) ChannelOption { + return func(s *eventingv1.Channel) { + s.Generation = gen + } +} + +func WithChannelObservedGeneration(gen int64) ChannelOption { + return func(s *eventingv1.Channel) { + s.Status.ObservedGeneration = gen + } +} + +func WithChannelDeleted(c *eventingv1.Channel) { + t := metav1.NewTime(time.Unix(1e9, 0)) + c.ObjectMeta.SetDeletionTimestamp(&t) +} + +func WithChannelTemplate(typeMeta metav1.TypeMeta) ChannelOption { + return func(c *eventingv1.Channel) { + c.Spec.ChannelTemplate = &messagingv1.ChannelTemplateSpec{ + TypeMeta: typeMeta, + } + } +} + +func WithBackingChannelFailed(reason, msg string) ChannelOption { + return func(c *eventingv1.Channel) { + c.Status.MarkBackingChannelFailed(reason, msg) + } +} + +func WithBackingChannelUnknown(reason, msg string) ChannelOption { + return func(c *eventingv1.Channel) { + c.Status.MarkBackingChannelUnknown(reason, msg) + } +} + +func WithBackingChannelReady(c *eventingv1.Channel) { + c.Status.MarkBackingChannelReady() +} + +func WithBackingChannelObjRef(objRef *duckv1.KReference) ChannelOption { + return func(c *eventingv1.Channel) { + c.Status.Channel = objRef + } +} + +func WithChannelNoAddress() ChannelOption { + return func(c *eventingv1.Channel) { + c.Status.SetAddress(nil) + } +} + +func WithChannelAddress(hostname string) ChannelOption { + return func(c *eventingv1.Channel) { + c.Status.SetAddress(&duckv1.Addressable{URL: apis.HTTP(hostname)}) + } +} + +func WithChannelReadySubscriber(uid string) ChannelOption { + return WithChannelReadySubscriberAndGeneration(uid, 0) +} + +func WithChannelReadySubscriberAndGeneration(uid string, observedGeneration int64) ChannelOption { + return func(c *eventingv1.Channel) { + c.Status.Subscribers = append(c.Status.Subscribers, eventingduckv1.SubscriberStatus{ + UID: types.UID(uid), + ObservedGeneration: observedGeneration, + Ready: v1.ConditionTrue, + }) + } +} + +func WithChannelSubscriberStatuses(subscriberStatuses []eventingduckv1.SubscriberStatus) ChannelOption { + return func(c *eventingv1.Channel) { + c.Status.Subscribers = subscriberStatuses + } +} diff --git a/pkg/reconciler/testing/v1/channelable.go b/pkg/reconciler/testing/v1/channelable.go new file mode 100644 index 00000000000..018f5872b70 --- /dev/null +++ b/pkg/reconciler/testing/v1/channelable.go @@ -0,0 +1,113 @@ +/* +Copyright 2020 The Knative Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + "time" + + "k8s.io/apimachinery/pkg/types" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + duckv1 "knative.dev/eventing/pkg/apis/duck/v1" + "knative.dev/eventing/pkg/apis/duck/v1alpha1" + "knative.dev/eventing/pkg/apis/messaging" + "knative.dev/pkg/apis" + pkgduckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" + pkgduckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" +) + +// Channelable allows us to have a fake channel for testinv1alpha1 + +// ChannelableOption enables further configuration of a v1alpha1.Channelable. +type ChannelableOption func(*v1alpha1.Channelable) + +// NewChannelable creates an Channelable with ChannelableOptions. +func NewChannelable(name, namespace string, imcopt ...ChannelableOption) *v1alpha1.Channelable { + c := &v1alpha1.Channelable{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + Annotations: map[string]string{messaging.SubscribableDuckVersionAnnotation: "v1alpha1"}, + }, + Spec: v1alpha1.ChannelableSpec{}, + } + for _, opt := range imcopt { + opt(c) + } + return c +} + +func WithChannelableGeneration(gen int64) ChannelableOption { + return func(s *v1alpha1.Channelable) { + s.Generation = gen + } +} + +func WithChannelableStatusObservedGeneration(gen int64) ChannelableOption { + return func(s *v1alpha1.Channelable) { + s.Status.ObservedGeneration = gen + } +} + +func WithChannelableDeleted(imc *v1alpha1.Channelable) { + deleteTime := metav1.NewTime(time.Unix(1e9, 0)) + imc.ObjectMeta.SetDeletionTimestamp(&deleteTime) +} + +func WithChannelableSubscribers(subscribers []v1alpha1.SubscriberSpec) ChannelableOption { + return func(c *v1alpha1.Channelable) { + c.Spec.Subscribable = &v1alpha1.Subscribable{Subscribers: subscribers} + } +} + +func WithChannelableReadySubscriber(uid string) ChannelableOption { + return WithChannelableReadySubscriberAndGeneration(uid, 0) +} + +func WithChannelableReadySubscriberAndGeneration(uid string, observedGeneration int64) ChannelableOption { + return func(c *v1alpha1.Channelable) { + if c.Status.GetSubscribableTypeStatus() == nil { // Both the SubscribableStatus fields are nil + c.Status.SetSubscribableTypeStatus(v1alpha1.SubscribableStatus{}) + } + c.Status.SubscribableTypeStatus.AddSubscriberToSubscribableStatus(duckv1.SubscriberStatus{ + UID: types.UID(uid), + ObservedGeneration: observedGeneration, + Ready: corev1.ConditionTrue, + }) + } +} + +func WithChannelableStatusSubscribers(subscriberStatuses []duckv1.SubscriberStatus) ChannelableOption { + return func(c *v1alpha1.Channelable) { + c.Status.SetSubscribableTypeStatus(v1alpha1.SubscribableStatus{ + Subscribers: subscriberStatuses}) + } +} + +func WithChannelableReady() ChannelableOption { + return func(c *v1alpha1.Channelable) { + c.Status.Conditions = []apis.Condition{{Type: apis.ConditionReady, Status: corev1.ConditionTrue}} + } +} + +func WithChannelableAddress(a string) ChannelableOption { + return func(c *v1alpha1.Channelable) { + c.Status.Address = &pkgduckv1alpha1.Addressable{ + Addressable: pkgduckv1beta1.Addressable{ + URL: apis.HTTP(a), + }, + } + } +} diff --git a/pkg/reconciler/testing/v1/service.go b/pkg/reconciler/testing/v1/service.go new file mode 100644 index 00000000000..1eb8817d1dc --- /dev/null +++ b/pkg/reconciler/testing/v1/service.go @@ -0,0 +1,62 @@ +/* +Copyright 2020 The Knative Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// ServiceOption enables further configuration of a Service. +type ServiceOption func(*corev1.Service) + +// NewService creates a Service with ServiceOptions +func NewService(name, namespace string, so ...ServiceOption) *corev1.Service { + s := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: corev1.ServiceSpec{}, + } + for _, opt := range so { + opt(s) + } + return s +} + +func WithServiceOwnerReferences(ownerReferences []metav1.OwnerReference) ServiceOption { + return func(s *corev1.Service) { + s.OwnerReferences = ownerReferences + } +} + +func WithServiceLabels(labels map[string]string) ServiceOption { + return func(s *corev1.Service) { + s.ObjectMeta.Labels = labels + s.Spec.Selector = labels + } +} + +func WithServicePorts(ports []corev1.ServicePort) ServiceOption { + return func(s *corev1.Service) { + s.Spec.Ports = ports + } +} + +func WithServiceAnnotations(annotations map[string]string) ServiceOption { + return func(s *corev1.Service) { + s.ObjectMeta.Annotations = annotations + } +} diff --git a/pkg/reconciler/testing/v1/subscription.go b/pkg/reconciler/testing/v1/subscription.go new file mode 100644 index 00000000000..bfd6c45cdcf --- /dev/null +++ b/pkg/reconciler/testing/v1/subscription.go @@ -0,0 +1,224 @@ +/* +Copyright 2020 The Knative Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + "context" + "errors" + "time" + + "k8s.io/apimachinery/pkg/types" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" + eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" + v1 "knative.dev/eventing/pkg/apis/messaging/v1" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +// SubscriptionOption enables further configuration of a Subscription. +type SubscriptionOption func(*v1.Subscription) + +// NewSubscription creates a Subscription with SubscriptionOptions +func NewSubscription(name, namespace string, so ...SubscriptionOption) *v1.Subscription { + s := &v1.Subscription{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + } + for _, opt := range so { + opt(s) + } + s.SetDefaults(context.Background()) + return s +} + +// NewSubscriptionWithoutNamespace creates a Subscription with SubscriptionOptions but without a specific namespace +func NewSubscriptionWithoutNamespace(name string, so ...SubscriptionOption) *v1.Subscription { + s := &v1.Subscription{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + }, + } + for _, opt := range so { + opt(s) + } + s.SetDefaults(context.Background()) + return s +} + +func WithSubscriptionUID(uid types.UID) SubscriptionOption { + return func(s *v1.Subscription) { + s.UID = uid + } +} + +func WithSubscriptionGeneration(gen int64) SubscriptionOption { + return func(s *v1.Subscription) { + s.Generation = gen + } +} + +func WithSubscriptionStatusObservedGeneration(gen int64) SubscriptionOption { + return func(s *v1.Subscription) { + s.Status.ObservedGeneration = gen + } +} + +func WithSubscriptionGenerateName(generateName string) SubscriptionOption { + return func(c *v1.Subscription) { + c.ObjectMeta.GenerateName = generateName + } +} + +// WithInitSubscriptionConditions initializes the Subscriptions's conditions. +func WithInitSubscriptionConditions(s *v1.Subscription) { + s.Status.InitializeConditions() +} + +func WithSubscriptionReady(s *v1.Subscription) { + s.Status = *eventingv1.TestHelper.ReadySubscriptionStatus() +} + +// TODO: this can be a runtime object +func WithSubscriptionDeleted(s *v1.Subscription) { + t := metav1.NewTime(time.Unix(1e9, 0)) + s.ObjectMeta.SetDeletionTimestamp(&t) +} + +func WithSubscriptionLabels(labels map[string]string) SubscriptionOption { + return func(c *v1.Subscription) { + c.ObjectMeta.Labels = labels + } +} + +func WithSubscriptionChannel(gvk metav1.GroupVersionKind, name string) SubscriptionOption { + return func(s *v1.Subscription) { + s.Spec.Channel = corev1.ObjectReference{ + APIVersion: apiVersion(gvk), + Kind: gvk.Kind, + Name: name, + } + } +} + +func WithSubscriptionSubscriberRef(gvk metav1.GroupVersionKind, name, namespace string) SubscriptionOption { + return func(s *v1.Subscription) { + s.Spec.Subscriber = &duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: apiVersion(gvk), + Kind: gvk.Kind, + Name: name, + Namespace: namespace, + }, + } + } +} + +func WithSubscriptionDeliveryRef(gvk metav1.GroupVersionKind, name, namespace string) SubscriptionOption { + return func(s *v1.Subscription) { + s.Spec.Delivery = &eventingduckv1.DeliverySpec{ + DeadLetterSink: &duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: apiVersion(gvk), + Kind: gvk.Kind, + Name: name, + Namespace: namespace, + }, + }, + } + } +} + +func WithSubscriptionPhysicalSubscriptionSubscriber(uri *apis.URL) SubscriptionOption { + return func(s *v1.Subscription) { + if uri == nil { + panic(errors.New("nil URI")) + } + s.Status.PhysicalSubscription.SubscriberURI = uri + } +} + +func WithSubscriptionPhysicalSubscriptionReply(uri *apis.URL) SubscriptionOption { + return func(s *v1.Subscription) { + if uri == nil { + panic(errors.New("nil URI")) + } + s.Status.PhysicalSubscription.ReplyURI = uri + } +} + +func WithSubscriptionDeadLetterSinkURI(uri *apis.URL) SubscriptionOption { + return func(s *v1.Subscription) { + if uri == nil { + panic(errors.New("nil URI")) + } + s.Status.PhysicalSubscription.DeadLetterSinkURI = uri + } +} + +func WithSubscriptionFinalizers(finalizers ...string) SubscriptionOption { + return func(s *v1.Subscription) { + s.Finalizers = finalizers + } +} + +func MarkSubscriptionReady(s *v1.Subscription) { + s.Status.MarkChannelReady() + s.Status.MarkReferencesResolved() + s.Status.MarkAddedToChannel() +} + +func MarkAddedToChannel(s *v1.Subscription) { + s.Status.MarkAddedToChannel() +} + +func MarkNotAddedToChannel(reason, msg string) SubscriptionOption { + return func(s *v1.Subscription) { + s.Status.MarkNotAddedToChannel(reason, msg) + } +} + +func MarkReferencesResolved(s *v1.Subscription) { + s.Status.MarkReferencesResolved() +} + +func WithSubscriptionReferencesNotResolved(reason, msg string) SubscriptionOption { + return func(s *v1.Subscription) { + s.Status.MarkReferencesNotResolved(reason, msg) + } +} + +func WithSubscriptionReferencesResolvedUnknown(reason, msg string) SubscriptionOption { + return func(s *v1.Subscription) { + s.Status.MarkReferencesResolvedUnknown(reason, msg) + } +} + +func WithSubscriptionReply(gvk metav1.GroupVersionKind, name, namespace string) SubscriptionOption { + return func(s *v1.Subscription) { + s.Spec.Reply = &duckv1.Destination{ + Ref: &duckv1.KReference{ + APIVersion: apiVersion(gvk), + Kind: gvk.Kind, + Name: name, + Namespace: namespace, + }, + } + } +} diff --git a/pkg/reconciler/testing/v1beta1/channelable.go b/pkg/reconciler/testing/v1beta1/channelable.go index 3eda0f675f4..59f21b32b4c 100644 --- a/pkg/reconciler/testing/v1beta1/channelable.go +++ b/pkg/reconciler/testing/v1beta1/channelable.go @@ -28,7 +28,7 @@ import ( pkgduckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) -// Channelable allows us to have a fake channel for testing that implements a v1alpha1.Channelable type. +// Channelable allows us to have a fake channel for testinv1alpha1 // ChannelableOption enables further configuration of a v1alpha1.Channelable. type ChannelableOption func(*v1alpha1.Channelable) @@ -81,7 +81,7 @@ func WithChannelableReadySubscriberAndGeneration(uid string, observedGeneration if c.Status.GetSubscribableTypeStatus() == nil { // Both the SubscribableStatus fields are nil c.Status.SetSubscribableTypeStatus(v1alpha1.SubscribableStatus{}) } - c.Status.SubscribableTypeStatus.AddSubscriberToSubscribableStatus(duckv1beta1.SubscriberStatus{ + c.Status.SubscribableTypeStatus.AddSubscriberv1beta1ToSubscribableStatus(duckv1beta1.SubscriberStatus{ UID: types.UID(uid), ObservedGeneration: observedGeneration, Ready: corev1.ConditionTrue, @@ -92,7 +92,7 @@ func WithChannelableReadySubscriberAndGeneration(uid string, observedGeneration func WithChannelableStatusSubscribers(subscriberStatuses []duckv1beta1.SubscriberStatus) ChannelableOption { return func(c *v1alpha1.Channelable) { c.Status.SetSubscribableTypeStatus(v1alpha1.SubscribableStatus{ - Subscribers: subscriberStatuses}) + Subscribersv1beta1: subscriberStatuses}) } } diff --git a/test/conformance/helpers/channel.go b/test/conformance/helpers/channel.go index 019d818aabc..ec1166a867f 100644 --- a/test/conformance/helpers/channel.go +++ b/test/conformance/helpers/channel.go @@ -23,6 +23,7 @@ import ( "knative.dev/eventing/test/lib/resources" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" @@ -60,6 +61,20 @@ func getChannelDuckTypeSupportVersion(channelName string, client *testlib.Client return channelable.ObjectMeta.Annotations[messaging.SubscribableDuckVersionAnnotation], nil } +func getChannelAsV1Channelable(channelName string, client *testlib.Client, channel metav1.TypeMeta) (*eventingduckv1.Channelable, error) { + metaResource := resources.NewMetaResource(channelName, client.Namespace, &channel) + obj, err := duck.GetGenericObject(client.Dynamic, metaResource, &eventingduckv1.Channelable{}) + if err != nil { + return nil, errors.Wrapf(err, "Unable to get the channel as v1 Channel duck type: %q", channel) + } + channelable, ok := obj.(*eventingduckv1.Channelable) + if !ok { + return nil, errors.Errorf("Unable to cast channel %q to v1 duck type", channel) + } + + return channelable, nil +} + func getChannelAsV1Beta1Channelable(channelName string, client *testlib.Client, channel metav1.TypeMeta) (*eventingduckv1beta1.Channelable, error) { metaResource := resources.NewMetaResource(channelName, client.Namespace, &channel) obj, err := duck.GetGenericObject(client.Dynamic, metaResource, &eventingduckv1beta1.Channelable{}) diff --git a/test/conformance/helpers/channel_status_subscriber_test_helper.go b/test/conformance/helpers/channel_status_subscriber_test_helper.go index 125661a16b3..d26cfd03c14 100644 --- a/test/conformance/helpers/channel_status_subscriber_test_helper.go +++ b/test/conformance/helpers/channel_status_subscriber_test_helper.go @@ -19,6 +19,7 @@ package helpers import ( "testing" + duckv1 "knative.dev/eventing/pkg/apis/duck/v1" duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" eventingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" testlib "knative.dev/eventing/test/lib" @@ -85,7 +86,7 @@ func channelHasRequiredSubscriberStatus(st *testing.T, client *testlib.Client, c if channelable.Status.SubscribableStatus == nil || channelable.Status.SubscribableStatus.Subscribers == nil { st.Fatalf("%q does not have status.subscribers", channel) } - ss := findSubscriberStatus(channelable.Status.SubscribableStatus.Subscribers, subscription) + ss := findSubscriberStatusV1(channelable.Status.SubscribableStatus.Subscribers, subscription) if ss == nil { st.Fatalf("No subscription status found for channel %q and subscription %v", channel, subscription) } @@ -94,7 +95,7 @@ func channelHasRequiredSubscriberStatus(st *testing.T, client *testlib.Client, c if ss.Ready != corev1.ConditionTrue { st.Fatalf("Subscription not ready found for channel %q and subscription %v", channel, subscription) } - } else if dtsv == "v1beta1" || dtsv == "v1" { + } else if dtsv == "v1beta1" { channelable, err := getChannelAsV1Beta1Channelable(channelName, client, channel) if err != nil { st.Fatalf("Unable to get channel %q to v1beta1 duck type: %q", channel, err) @@ -104,7 +105,26 @@ func channelHasRequiredSubscriberStatus(st *testing.T, client *testlib.Client, c if channelable.Status.Subscribers == nil { st.Fatalf("%q does not have status.subscribers", channel) } - ss := findSubscriberStatus(channelable.Status.Subscribers, subscription) + ss := findSubscriberStatusV1Beta1(channelable.Status.Subscribers, subscription) + if ss == nil { + st.Fatalf("No subscription status found for channel %q and subscription %v", channel, subscription) + } + + // SPEC: The ready field of the subscriber identified by its uid MUST be set to True when the subscription is ready to be processed. + if ss.Ready != corev1.ConditionTrue { + st.Fatalf("Subscription not ready found for channel %q and subscription %v", channel, subscription) + } + } else if dtsv == "v1" { + channelable, err := getChannelAsV1Channelable(channelName, client, channel) + if err != nil { + st.Fatalf("Unable to get channel %q to v1 duck type: %q", channel, err) + } + + // SPEC: Each subscription to a channel is added to the channel status.subscribers automatically. + if channelable.Status.Subscribers == nil { + st.Fatalf("%q does not have status.subscribers", channel) + } + ss := findSubscriberStatusV1(channelable.Status.Subscribers, subscription) if ss == nil { st.Fatalf("No subscription status found for channel %q and subscription %v", channel, subscription) } @@ -118,7 +138,16 @@ func channelHasRequiredSubscriberStatus(st *testing.T, client *testlib.Client, c } } -func findSubscriberStatus(statusArr []duckv1beta1.SubscriberStatus, subscription *eventingv1beta1.Subscription) *duckv1beta1.SubscriberStatus { +func findSubscriberStatusV1Beta1(statusArr []duckv1beta1.SubscriberStatus, subscription *eventingv1beta1.Subscription) *duckv1beta1.SubscriberStatus { + for _, v := range statusArr { + if v.UID == subscription.UID { + return &v + } + } + return nil +} + +func findSubscriberStatusV1(statusArr []duckv1.SubscriberStatus, subscription *eventingv1beta1.Subscription) *duckv1.SubscriberStatus { for _, v := range statusArr { if v.UID == subscription.UID { return &v