From 8dbb4b50c8da70c199fd6e67f1b3b470cbf8a997 Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Tue, 2 Mar 2021 13:42:25 -0800 Subject: [PATCH 1/9] remove v1alpha1 channelable from the spec --- docs/spec/channel.md | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/docs/spec/channel.md b/docs/spec/channel.md index a5dea76470f..20446d841ff 100644 --- a/docs/spec/channel.md +++ b/docs/spec/channel.md @@ -152,7 +152,6 @@ Each instantiated Channel (ie, Custom Object) SHOULD have an annotation indicating which version of the `Channelable` duck type it conforms to. We currently have these versions: -1. [v1alpha1](https://github.com/knative/eventing/blob/master/pkg/apis/duck/v1alpha1/channelable_types.go) 1. [v1beta1](https://github.com/knative/eventing/blob/master/pkg/apis/duck/v1beta1/channelable_types.go) 1. [v1](https://github.com/knative/eventing/blob/master/pkg/apis/duck/v1/channelable_types.go) @@ -173,11 +172,6 @@ if no annotation is given, we assume it's `v1alpha1`. #### Spec Requirements -##### v1alpha1 Spec - -Each channel CRD MUST contain an array of subscribers: -[`spec.subscribable.subscribers`](https://github.com/knative/eventing/blob/master/pkg/apis/duck/v1alpha1/subscribable_types.go) - ##### v1beta1 Spec Each channel CRD MUST contain an array of subscribers: @@ -208,21 +202,6 @@ that particular Subscription. #### Status Requirements -##### v1alpha1 Status - -Each channel CRD MUST have a `status` subresource which contains - -- [`address`](https://github.com/knative/pkg/blob/master/apis/duck/v1alpha1/addressable_types.go) -- [`subscribableStatus.subscribers`](https://github.com/knative/eventing/blob/master/pkg/apis/duck/v1alpha1/subscribable_types.go) - (as an array) - -Each channel CRD SHOULD have the following fields in `Status` - -- [`observedGeneration`](https://github.com/knative/pkg/blob/master/apis/duck/v1/status_types.go) - MUST be populated if present -- [`conditions`](https://github.com/knative/pkg/blob/master/apis/duck/v1/status_types.go) - (as an array) SHOULD indicate status transitions and error reasons if present - ##### v1beta1 Status Each channel CRD MUST have a `status` subresource which contains @@ -255,12 +234,6 @@ Each channel CRD SHOULD have the following fields in `Status` #### Channel Status -##### v1alpha1 - -When the channel instance is ready to receive events `status.address.hostname` -and `status.address.url` MUST be populated and `status.addressable` MUST be set -to `True`. - ##### v1beta1 When the channel instance is ready to receive events `status.address.url` MUST @@ -273,13 +246,6 @@ be populated and `status.addressable` MUST be set to `True`. #### Channel Subscriber Status -##### v1alpha1 - -Each subscription to a channel is added to the channel -`status.subscribableStatus.subscribers` automatically. The `ready` field of the -subscriber identified by its `uid` MUST be set to `True` when the subscription -is ready to be processed. - ##### v1beta1 Each subscription to a channel is added to the channel `status.subscribers` @@ -362,10 +328,8 @@ _Structured Content Mode_ of the HTTP Protocol Binding for CloudEvents, although dispatching events using _Binary Content Mode_ is RECOMMENDED. Channels MUST send events to all subscribers which are marked with a status of -`ready: "True"` in the channel's `status.subscribableStatus.subscribers` -(v1alpha1) or `status.subscribers` (v1beta1). The events must be sent to the -`subscriberURI` field of `spec.subscribable.subscribers` (v1alpha1) or -`spec.subscribers` (v1beta1). Each channel implementation will have its own +`ready: "True"` in the channel's `status.subscribers` (v1beta1 / v1). The events must be sent to the +`subscriberURI` field of `spec.subscribers` (v1beta1 / v1). Each channel implementation will have its own quality of service guarantees (e.g. at least once, at most once, etc) which SHOULD be documented. @@ -418,3 +382,4 @@ following attributes: promoted from `v1alpha1`to `v1beta1`. Add requirement for labeling Custom Objects to indicate which duck type they support as well as document differences. +- `0.22.x release`: Drop support for v1alpha1 channelable. From 39901e4a43a01b630cc6a8ac9081b2f467e0d1f2 Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Tue, 2 Mar 2021 13:56:04 -0800 Subject: [PATCH 2/9] remove pkg/apis/duck/v1alpha1 and gen --- .../v1alpha1/channelable_combined_types.go | 187 ------- .../channelable_combined_types_test.go | 145 ------ pkg/apis/duck/v1alpha1/channelable_types.go | 160 ------ .../duck/v1alpha1/channelable_types_test.go | 118 ----- pkg/apis/duck/v1alpha1/doc.go | 24 - pkg/apis/duck/v1alpha1/register.go | 46 -- pkg/apis/duck/v1alpha1/register_test.go | 52 -- pkg/apis/duck/v1alpha1/resource_types.go | 50 -- pkg/apis/duck/v1alpha1/resource_types_test.go | 31 -- pkg/apis/duck/v1alpha1/subscribable_types.go | 189 ------- .../v1alpha1/subscribable_types_conversion.go | 282 ---------- .../subscribable_types_conversion_test.go | 463 ----------------- .../duck/v1alpha1/subscribable_types_test.go | 141 ----- .../duck/v1alpha1/zz_generated.deepcopy.go | 486 ------------------ .../duck/v1alpha1/channelable/channelable.go | 60 --- .../duck/v1alpha1/channelable/fake/fake.go | 30 -- .../channelablecombined.go | 60 --- .../v1alpha1/channelablecombined/fake/fake.go | 30 -- .../duck/v1alpha1/subscribable/fake/fake.go | 30 -- .../v1alpha1/subscribable/subscribable.go | 60 --- 20 files changed, 2644 deletions(-) delete mode 100644 pkg/apis/duck/v1alpha1/channelable_combined_types.go delete mode 100644 pkg/apis/duck/v1alpha1/channelable_combined_types_test.go delete mode 100644 pkg/apis/duck/v1alpha1/channelable_types.go delete mode 100644 pkg/apis/duck/v1alpha1/channelable_types_test.go delete mode 100644 pkg/apis/duck/v1alpha1/doc.go delete mode 100644 pkg/apis/duck/v1alpha1/register.go delete mode 100644 pkg/apis/duck/v1alpha1/register_test.go delete mode 100644 pkg/apis/duck/v1alpha1/resource_types.go delete mode 100644 pkg/apis/duck/v1alpha1/resource_types_test.go delete mode 100644 pkg/apis/duck/v1alpha1/subscribable_types.go delete mode 100644 pkg/apis/duck/v1alpha1/subscribable_types_conversion.go delete mode 100644 pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go delete mode 100644 pkg/apis/duck/v1alpha1/subscribable_types_test.go delete mode 100644 pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go delete mode 100644 pkg/client/injection/ducks/duck/v1alpha1/channelable/channelable.go delete mode 100644 pkg/client/injection/ducks/duck/v1alpha1/channelable/fake/fake.go delete mode 100644 pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/channelablecombined.go delete mode 100644 pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/fake/fake.go delete mode 100644 pkg/client/injection/ducks/duck/v1alpha1/subscribable/fake/fake.go delete mode 100644 pkg/client/injection/ducks/duck/v1alpha1/subscribable/subscribable.go diff --git a/pkg/apis/duck/v1alpha1/channelable_combined_types.go b/pkg/apis/duck/v1alpha1/channelable_combined_types.go deleted file mode 100644 index 48d1e00cf58..00000000000 --- a/pkg/apis/duck/v1alpha1/channelable_combined_types.go +++ /dev/null @@ -1,187 +0,0 @@ -/* -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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" -) - -// +genduck -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// ChannelableCombined is a skeleton type wrapping Subscribable and Addressable of -// v1alpha1 and v1beta1 duck types. This is not to be used by resource writers and is -// only used by Subscription Controller to synthesize patches and read the Status -// of the Channelable Resources. -// This is not a real resource. -type ChannelableCombined struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Spec is the part where the Channelable fulfills the Subscribable contract. - Spec ChannelableCombinedSpec `json:"spec,omitempty"` - - Status ChannelableCombinedStatus `json:"status,omitempty"` -} - -// ChannelableSpec contains Spec of the Channelable object -type ChannelableCombinedSpec struct { - // SubscribableTypeSpec is for the v1alpha1 spec compatibility. - SubscribableTypeSpec `json:",inline"` - - // SubscribableSpec is for the v1beta1 spec compatibility. - eventingduckv1beta1.SubscribableSpec `json:",inline"` - - // DeliverySpec contains options controlling the event delivery - // +optional - Delivery *eventingduckv1beta1.DeliverySpec `json:"delivery,omitempty"` -} - -// ChannelableStatus contains the Status of a Channelable object. -type ChannelableCombinedStatus struct { - // inherits duck/v1 Status, which currently provides: - // * ObservedGeneration - the 'Generation' of the Service that was last processed by the controller. - // * Conditions - the latest available observations of a resource's current state. - duckv1.Status `json:",inline"` - // AddressStatus is the part where the Channelable fulfills the Addressable contract. - v1alpha1.AddressStatus `json:",inline"` - // 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"` - // ErrorChannel is set by the channel when it supports native error handling via a channel - // +optional - ErrorChannel *corev1.ObjectReference `json:"errorChannel,omitempty"` -} - -var ( - // Verify Channelable resources meet duck contracts. - _ duck.Populatable = (*ChannelableCombined)(nil) - _ duck.Implementable = (*ChannelableCombined)(nil) - _ apis.Listable = (*ChannelableCombined)(nil) -) - -// Populate implements duck.Populatable -func (c *ChannelableCombined) Populate() { - c.Spec.Subscribable = &Subscribable{ - // Populate ALL fields - Subscribers: []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"), - }}, - } - c.Spec.SubscribableSpec = eventingduckv1beta1.SubscribableSpec{ - // Populate ALL fields - Subscribers: []eventingduckv1beta1.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"), - }}, - } - retry := int32(5) - linear := eventingduckv1beta1.BackoffPolicyLinear - delay := "5s" - deadLetterSink := duckv1.Destination{ - Ref: &duckv1.KReference{ - Name: "aname", - }, - URI: &apis.URL{ - Scheme: "http", - Host: "test-error-domain", - }, - } - c.Spec.Delivery = &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &deadLetterSink, - Retry: &retry, - BackoffPolicy: &linear, - BackoffDelay: &delay, - } - subscribers := []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", - }} - c.Status = ChannelableCombinedStatus{ - AddressStatus: v1alpha1.AddressStatus{ - Address: &v1alpha1.Addressable{ - // Populate ALL fields - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: "test-domain", - }, - }, - Hostname: "test-domain", - }, - }, - SubscribableStatus: eventingduckv1beta1.SubscribableStatus{ - Subscribers: subscribers, - }, - SubscribableTypeStatus: SubscribableTypeStatus{ - SubscribableStatus: &SubscribableStatus{ - Subscribers: subscribers, - }, - }, - } -} - -// GetFullType implements duck.Implementable -func (s *ChannelableCombined) GetFullType() duck.Populatable { - return &ChannelableCombined{} -} - -// GetListType implements apis.Listable -func (c *ChannelableCombined) GetListType() runtime.Object { - return &ChannelableCombinedList{} -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// ChannelableList is a list of Channelable resources. -type ChannelableCombinedList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []ChannelableCombined `json:"items"` -} diff --git a/pkg/apis/duck/v1alpha1/channelable_combined_types_test.go b/pkg/apis/duck/v1alpha1/channelable_combined_types_test.go deleted file mode 100644 index e74dd26d164..00000000000 --- a/pkg/apis/duck/v1alpha1/channelable_combined_types_test.go +++ /dev/null @@ -1,145 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - - corev1 "k8s.io/api/core/v1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" - - "github.com/google/go-cmp/cmp" -) - -func TestChannelableCombinedGetListType(t *testing.T) { - c := &ChannelableCombined{} - switch c.GetListType().(type) { - case *ChannelableCombinedList: - // expected - default: - t.Errorf("expected GetListType to return *ChannelableCombinedList, got %T", c.GetListType()) - } -} - -func TestChannelableCombinedPopulate(t *testing.T) { - got := &ChannelableCombined{} - - retry := int32(5) - linear := eventingduckv1beta1.BackoffPolicyLinear - delay := "5s" - want := &ChannelableCombined{ - Spec: ChannelableCombinedSpec{ - SubscribableSpec: eventingduckv1beta1.SubscribableSpec{ - // Populate ALL fields - Subscribers: []eventingduckv1beta1.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"), - }}, - }, - SubscribableTypeSpec: SubscribableTypeSpec{ - Subscribable: &Subscribable{ - Subscribers: []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"), - }}, - }, - }, - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Name: "aname", - }, - URI: &apis.URL{ - Scheme: "http", - Host: "test-error-domain", - }, - }, - Retry: &retry, - BackoffPolicy: &linear, - BackoffDelay: &delay, - }, - }, - - Status: ChannelableCombinedStatus{ - AddressStatus: v1alpha1.AddressStatus{ - Address: &v1alpha1.Addressable{ - // Populate ALL fields - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: "test-domain", - }, - }, - Hostname: "test-domain", - }, - }, - SubscribableStatus: eventingduckv1beta1.SubscribableStatus{ - Subscribers: []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", - }}, - }, - SubscribableTypeStatus: SubscribableTypeStatus{ - SubscribableStatus: &SubscribableStatus{ - Subscribers: []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", - }}, - }, - }, - }, - } - - got.Populate() - - if diff := cmp.Diff(want, got); diff != "" { - t.Error("Unexpected difference (-want, +got):", diff) - } - -} diff --git a/pkg/apis/duck/v1alpha1/channelable_types.go b/pkg/apis/duck/v1alpha1/channelable_types.go deleted file mode 100644 index b9910cbfbcf..00000000000 --- a/pkg/apis/duck/v1alpha1/channelable_types.go +++ /dev/null @@ -1,160 +0,0 @@ -/* -Copyright 2019 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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" -) - -// +genduck -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// Channelable is a skeleton type wrapping Subscribable and Addressable in the manner we expect resource writers -// defining compatible resources to embed it. We will typically use this type to deserialize -// Channelable ObjectReferences and access their subscription and address data. This is not a real resource. -type Channelable struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Spec is the part where the Channelable fulfills the Subscribable contract. - Spec ChannelableSpec `json:"spec,omitempty"` - - Status ChannelableStatus `json:"status,omitempty"` -} - -// ChannelableSpec contains Spec of the Channelable object -type ChannelableSpec struct { - SubscribableTypeSpec `json:",inline"` - - // DeliverySpec contains options controlling the event delivery - // +optional - Delivery *eventingduckv1beta1.DeliverySpec `json:"delivery,omitempty"` -} - -// ChannelableStatus contains the Status of a Channelable object. -type ChannelableStatus struct { - // inherits duck/v1 Status, which currently provides: - // * ObservedGeneration - the 'Generation' of the Service that was last processed by the controller. - // * Conditions - the latest available observations of a resource's current state. - duckv1.Status `json:",inline"` - // AddressStatus is the part where the Channelable fulfills the Addressable contract. - v1alpha1.AddressStatus `json:",inline"` - // Subscribers is populated with the statuses of each of the Channelable's subscribers. - SubscribableTypeStatus `json:",inline"` - // ErrorChannel is set by the channel when it supports native error handling via a channel - // +optional - ErrorChannel *corev1.ObjectReference `json:"errorChannel,omitempty"` -} - -var ( - // Verify Channelable resources meet duck contracts. - _ duck.Populatable = (*Channelable)(nil) - _ duck.Implementable = (*Channelable)(nil) - _ apis.Listable = (*Channelable)(nil) -) - -// Populate implements duck.Populatable -func (c *Channelable) Populate() { - c.Spec.Subscribable = &Subscribable{ - // Populate ALL fields - Subscribers: []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"), - }}, - } - retry := int32(5) - linear := eventingduckv1beta1.BackoffPolicyLinear - delay := "5s" - c.Spec.Delivery = &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Name: "aname", - }, - URI: &apis.URL{ - Scheme: "http", - Host: "test-error-domain", - }, - }, - Retry: &retry, - BackoffPolicy: &linear, - BackoffDelay: &delay, - } - c.Status = ChannelableStatus{ - AddressStatus: v1alpha1.AddressStatus{ - Address: &v1alpha1.Addressable{ - // Populate ALL fields - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: "test-domain", - }, - }, - Hostname: "test-domain", - }, - }, - SubscribableTypeStatus: SubscribableTypeStatus{ - SubscribableStatus: &SubscribableStatus{ - Subscribers: []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", - }}, - }, - }, - } -} - -// GetFullType implements duck.Implementable -func (s *Channelable) GetFullType() duck.Populatable { - return &Channelable{} -} - -// GetListType implements apis.Listable -func (c *Channelable) GetListType() runtime.Object { - return &ChannelableList{} -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// ChannelableList is a list of Channelable resources. -type ChannelableList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []Channelable `json:"items"` -} diff --git a/pkg/apis/duck/v1alpha1/channelable_types_test.go b/pkg/apis/duck/v1alpha1/channelable_types_test.go deleted file mode 100644 index fd781c16f45..00000000000 --- a/pkg/apis/duck/v1alpha1/channelable_types_test.go +++ /dev/null @@ -1,118 +0,0 @@ -/* -Copyright 2019 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 v1alpha1 - -import ( - "testing" - - corev1 "k8s.io/api/core/v1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" - - "github.com/google/go-cmp/cmp" -) - -func TestChannelableGetListType(t *testing.T) { - c := &Channelable{} - switch c.GetListType().(type) { - case *ChannelableList: - // expected - default: - t.Errorf("expected GetListType to return *ChannelableList, got %T", c.GetListType()) - } -} - -func TestChannelablePopulate(t *testing.T) { - got := &Channelable{} - - retry := int32(5) - linear := eventingduckv1beta1.BackoffPolicyLinear - delay := "5s" - want := &Channelable{ - Spec: ChannelableSpec{ - SubscribableTypeSpec: SubscribableTypeSpec{ - Subscribable: &Subscribable{ - Subscribers: []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"), - }}, - }, - }, - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Name: "aname", - }, - URI: &apis.URL{ - Scheme: "http", - Host: "test-error-domain", - }, - }, - Retry: &retry, - BackoffPolicy: &linear, - BackoffDelay: &delay, - }, - }, - - Status: ChannelableStatus{ - AddressStatus: v1alpha1.AddressStatus{ - Address: &v1alpha1.Addressable{ - // Populate ALL fields - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: "test-domain", - }, - }, - Hostname: "test-domain", - }, - }, - SubscribableTypeStatus: SubscribableTypeStatus{ - SubscribableStatus: &SubscribableStatus{ - Subscribers: []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", - }}, - }, - }, - }, - } - - got.Populate() - - if diff := cmp.Diff(want, got); diff != "" { - t.Error("Unexpected difference (-want, +got):", diff) - } - -} diff --git a/pkg/apis/duck/v1alpha1/doc.go b/pkg/apis/duck/v1alpha1/doc.go deleted file mode 100644 index 5019094b1e5..00000000000 --- a/pkg/apis/duck/v1alpha1/doc.go +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright 2019 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. -*/ - -// Api versions allow the api contract for a resource to be changed while keeping -// backward compatibility by support multiple concurrent versions -// of the same resource - -// Package v1alpha1 is the v1alpha1 version of the API. -// +k8s:deepcopy-gen=package -// +groupName=duck.knative.dev -package v1alpha1 diff --git a/pkg/apis/duck/v1alpha1/register.go b/pkg/apis/duck/v1alpha1/register.go deleted file mode 100644 index ecd0879b3b6..00000000000 --- a/pkg/apis/duck/v1alpha1/register.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -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 v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: "duck.knative.dev", Version: "v1alpha1"} - -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -var ( - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme -) - -// Adds the list of known types to Scheme. -func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &Channelable{}, - &ChannelableList{}, - ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) - return nil -} diff --git a/pkg/apis/duck/v1alpha1/register_test.go b/pkg/apis/duck/v1alpha1/register_test.go deleted file mode 100644 index c38d81a2b71..00000000000 --- a/pkg/apis/duck/v1alpha1/register_test.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// Kind takes an unqualified resource and returns a Group qualified GroupKind -func TestKind(t *testing.T) { - want := schema.GroupKind{ - Group: "duck.knative.dev", - Kind: "kind", - } - - got := Kind("kind") - - if diff := cmp.Diff(want, got); diff != "" { - t.Error("unexpected resource (-want, +got) =", diff) - } -} - -// TestKnownTypes makes sure that expected types get added. -func TestKnownTypes(t *testing.T) { - scheme := runtime.NewScheme() - addKnownTypes(scheme) - types := scheme.KnownTypes(SchemeGroupVersion) - - for _, name := range []string{ - "Channelable", - "ChannelableList", - } { - if _, ok := types[name]; !ok { - t.Errorf("Did not find %q as registered type", name) - } - } - -} diff --git a/pkg/apis/duck/v1alpha1/resource_types.go b/pkg/apis/duck/v1alpha1/resource_types.go deleted file mode 100644 index 10f232d49f0..00000000000 --- a/pkg/apis/duck/v1alpha1/resource_types.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright 2019 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 v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "knative.dev/pkg/apis" -) - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// Resource is a skeleton type wrapping all Kubernetes resources. It is typically used to watch -// arbitrary other resources (such as any Source or Addressable). This is not a real resource. -type Resource struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` -} - -// Ensure Resource satisfies apis.Listable -var _ apis.Listable = (*Resource)(nil) - -// GetListType implements apis.Listable. -func (*Resource) GetListType() runtime.Object { - return &ResourceList{} -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// ResourceList is a list of KResource resources -type ResourceList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []Resource `json:"items"` -} diff --git a/pkg/apis/duck/v1alpha1/resource_types_test.go b/pkg/apis/duck/v1alpha1/resource_types_test.go deleted file mode 100644 index 73527853713..00000000000 --- a/pkg/apis/duck/v1alpha1/resource_types_test.go +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright 2019 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 v1alpha1 - -import ( - "testing" -) - -func TestResourceGetListType(t *testing.T) { - r := &Resource{} - switch r.GetListType().(type) { - case *ResourceList: - // expected - default: - t.Errorf("expected GetListType to return *ResourceList, got %T", r.GetListType()) - } -} diff --git a/pkg/apis/duck/v1alpha1/subscribable_types.go b/pkg/apis/duck/v1alpha1/subscribable_types.go deleted file mode 100644 index 6589b71e1b5..00000000000 --- a/pkg/apis/duck/v1alpha1/subscribable_types.go +++ /dev/null @@ -1,189 +0,0 @@ -/* -Copyright 2019 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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck" - - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" -) - -// +genduck - -// Subscribable is the schema for the subscribable portion of the spec -// section of the resource. -type Subscribable struct { - // This is the list of subscriptions for this subscribable. - // +patchMergeKey=uid - // +patchStrategy=merge - Subscribers []SubscriberSpec `json:"subscribers,omitempty" patchStrategy:"merge" patchMergeKey:"uid"` -} - -// Subscribable is an Implementable "duck type". -var _ duck.Implementable = (*Subscribable)(nil) - -// SubscriberSpec defines a single subscriber to a Subscribable. -// Ref is a reference to the Subscription this SubscriberSpec was created for -// SubscriberURI is the endpoint for the subscriber -// ReplyURI is the endpoint for the reply -// At least one of SubscriberURI and ReplyURI must be present -type SubscriberSpec struct { - // UID is used to understand the origin of the subscriber. - // +optional - UID types.UID `json:"uid,omitempty"` - // Generation of the origin of the subscriber with uid:UID. - // +optional - Generation int64 `json:"generation,omitempty"` - // +optional - SubscriberURI *apis.URL `json:"subscriberURI,omitempty"` - // +optional - ReplyURI *apis.URL `json:"replyURI,omitempty"` - // +optional - DeadLetterSinkURI *apis.URL `json:"deadLetterSink,omitempty"` - // +optional - Delivery *duckv1beta1.DeliverySpec `json:"delivery,omitempty"` -} - -// SubscribableStatus is the schema for the subscribable's status portion of the status -// section of the resource. -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"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// SubscribableType is a skeleton type wrapping Subscribable in the manner we expect resource writers -// defining compatible resources to embed it. We will typically use this type to deserialize -// SubscribableType ObjectReferences and access the Subscription data. This is not a real resource. -type SubscribableType struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // SubscribableTypeSpec is the part where Subscribable object is - // configured as to be compatible with Subscribable contract. - Spec SubscribableTypeSpec `json:"spec"` - - // SubscribableTypeStatus is the part where SubscribableStatus object is - // configured as to be compatible with Subscribable contract. - Status SubscribableTypeStatus `json:"status"` -} - -// SubscribableTypeSpec shows how we expect folks to embed Subscribable in their Spec field. -type SubscribableTypeSpec struct { - Subscribable *Subscribable `json:"subscribable,omitempty"` -} - -// SubscribableTypeStatus shows how we expect folks to embed Subscribable in their Status field. -type SubscribableTypeStatus struct { - SubscribableStatus *SubscribableStatus `json:"subscribableStatus,omitempty"` -} - -var ( - // Verify SubscribableType resources meet duck contracts. - _ duck.Populatable = (*SubscribableType)(nil) - _ apis.Listable = (*SubscribableType)(nil) - - _ apis.Convertible = (*SubscribableType)(nil) - - _ apis.Convertible = (*SubscribableTypeSpec)(nil) - _ apis.Convertible = (*SubscribableTypeStatus)(nil) - - _ apis.Convertible = (*SubscriberSpec)(nil) -) - -// GetSubscribableTypeStatus method Returns the Default SubscribableStatus in this case it's SubscribableStatus -// This is w.r.t https://github.com/knative/eventing/pull/1685#discussion_r314797276 -// Due to change in the API, we support reading of SubscribableTypeStatus#DeprecatedSubscribableStatus in a logical way -// where we read the V2 value first and if the value is absent then we read the V1 value, -// Having this function here makes it convenient to read the default value at runtime. -func (s *SubscribableTypeStatus) GetSubscribableTypeStatus() *SubscribableStatus { - return s.SubscribableStatus -} - -// SetSubscribableTypeStatus method sets the SubscribableStatus Values in th SubscribableTypeStatus structs -// This helper function ensures that we set both the values (SubscribableStatus and DeprecatedSubscribableStatus) -func (s *SubscribableTypeStatus) SetSubscribableTypeStatus(subscriberStatus SubscribableStatus) { - s.SubscribableStatus = &subscriberStatus -} - -// 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 -} - -// GetFullType implements duck.Implementable -func (s *Subscribable) GetFullType() duck.Populatable { - return &SubscribableType{} -} - -// Populate implements duck.Populatable -func (c *SubscribableType) Populate() { - c.Spec.Subscribable = &Subscribable{ - // Populate ALL fields - Subscribers: []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"), - }}, - } - c.Status.SetSubscribableTypeStatus(SubscribableStatus{ - // Populate ALL fields - Subscribers: []duckv1beta1.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", - }}, - }) -} - -// GetListType implements apis.Listable -func (c *SubscribableType) GetListType() runtime.Object { - return &SubscribableTypeList{} -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// SubscribableTypeList is a list of SubscribableType resources -type SubscribableTypeList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []SubscribableType `json:"items"` -} diff --git a/pkg/apis/duck/v1alpha1/subscribable_types_conversion.go b/pkg/apis/duck/v1alpha1/subscribable_types_conversion.go deleted file mode 100644 index 55f3ca3888e..00000000000 --- a/pkg/apis/duck/v1alpha1/subscribable_types_conversion.go +++ /dev/null @@ -1,282 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - "fmt" - - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - - eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" -) - -// ConvertTo implements apis.Convertible -func (source *SubscribableType) ConvertTo(ctx context.Context, obj apis.Convertible) error { - switch sink := obj.(type) { - case *eventingduckv1beta1.Subscribable: - sink.ObjectMeta = source.ObjectMeta - if err := source.Status.ConvertTo(ctx, &sink.Status); err != nil { - return err - } - if err := source.Spec.ConvertTo(ctx, &sink.Spec); err != nil { - return err - } - case *eventingduckv1.Subscribable: - sink.ObjectMeta = source.ObjectMeta - if err := source.Status.ConvertTo(ctx, &sink.Status); err != nil { - return err - } - if err := source.Spec.ConvertTo(ctx, &sink.Spec); err != nil { - return err - } - default: - return fmt.Errorf("unknown version, got: %T", sink) - } - return nil -} - -// ConvertTo implements apis.Convertible -func (source *SubscribableTypeSpec) ConvertTo(ctx context.Context, obj apis.Convertible) error { - switch sink := obj.(type) { - case *eventingduckv1beta1.SubscribableSpec: - if source.Subscribable != nil { - sink.Subscribers = make([]eventingduckv1beta1.SubscriberSpec, len(source.Subscribable.Subscribers)) - for i, s := range source.Subscribable.Subscribers { - if err := s.ConvertTo(ctx, &sink.Subscribers[i]); err != nil { - return err - } - } - } - case *eventingduckv1.SubscribableSpec: - if source.Subscribable != nil && len(source.Subscribable.Subscribers) > 0 { - sink.Subscribers = make([]eventingduckv1.SubscriberSpec, len(source.Subscribable.Subscribers)) - for i, s := range source.Subscribable.Subscribers { - if err := s.ConvertTo(ctx, &sink.Subscribers[i]); err != nil { - return err - } - } - } - default: - return fmt.Errorf("unknown version, got: %T", sink) - } - return nil -} - -// ConvertTo implements apis.Convertible -func (source *SubscriberSpec) ConvertTo(ctx context.Context, obj apis.Convertible) error { - switch sink := obj.(type) { - case *eventingduckv1beta1.SubscriberSpec: - sink.UID = source.UID - sink.Generation = source.Generation - sink.SubscriberURI = source.SubscriberURI - sink.ReplyURI = source.ReplyURI - - if source.Delivery != nil { - sink.Delivery = source.Delivery - } else { - // If however, there's a Deprecated DeadLetterSinkURI, convert that up - // to DeliverySpec. - sink.Delivery = &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - URI: source.DeadLetterSinkURI, - }, - } - } - case *eventingduckv1.SubscriberSpec: - sink.UID = source.UID - sink.Generation = source.Generation - sink.SubscriberURI = source.SubscriberURI - if source.Delivery != nil { - sink.Delivery = &eventingduckv1.DeliverySpec{} - if err := source.Delivery.ConvertTo(ctx, sink.Delivery); err != nil { - return err - } - } else { - // If however, there's a Deprecated DeadLetterSinkURI, convert that up - // to DeliverySpec. - sink.Delivery = &eventingduckv1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - URI: source.DeadLetterSinkURI, - }, - } - } - sink.ReplyURI = source.ReplyURI - default: - return fmt.Errorf("unknown version, got: %T", sink) - } - return nil -} - -// ConvertTo implements apis.Convertible -func (source *SubscribableTypeStatus) ConvertTo(ctx context.Context, obj apis.Convertible) error { - 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 { - sink.Subscribers[i] = eventingduckv1beta1.SubscriberStatus{ - UID: ss.UID, - ObservedGeneration: ss.ObservedGeneration, - Ready: ss.Ready, - Message: ss.Message, - } - } - } - case *eventingduckv1.SubscribableStatus: - if source.SubscribableStatus != nil && - 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{} - if err := ss.ConvertTo(ctx, &sink.Subscribers[i]); err != nil { - return err - } - } - } - default: - return fmt.Errorf("unknown version, got: %T", sink) - } - return nil -} - -// ConvertFrom implements apis.Convertible. -// Converts obj v1beta1.Subscribable into v1alpha1.SubscribableType -func (sink *SubscribableType) ConvertFrom(ctx context.Context, obj apis.Convertible) error { - switch source := obj.(type) { - case *eventingduckv1beta1.Subscribable: - sink.ObjectMeta = source.ObjectMeta - if err := sink.Status.ConvertFrom(ctx, &source.Status); err != nil { - return err - } - if err := sink.Spec.ConvertFrom(ctx, &source.Spec); err != nil { - return err - } - case *eventingduckv1.Subscribable: - sink.ObjectMeta = source.ObjectMeta - if err := sink.Status.ConvertFrom(ctx, &source.Status); err != nil { - return err - } - if err := sink.Spec.ConvertFrom(ctx, &source.Spec); err != nil { - return err - } - default: - return fmt.Errorf("unknown version, got: %T", source) - } - return nil -} - -// ConvertFrom implements apis.Convertible -func (sink *SubscribableTypeSpec) ConvertFrom(ctx context.Context, obj apis.Convertible) error { - switch source := obj.(type) { - case *eventingduckv1beta1.SubscribableSpec: - if len(source.Subscribers) > 0 { - sink.Subscribable = &Subscribable{ - Subscribers: make([]SubscriberSpec, len(source.Subscribers)), - } - for i := range source.Subscribers { - if err := sink.Subscribable.Subscribers[i].ConvertFrom(ctx, &source.Subscribers[i]); err != nil { - return err - } - } - } - case *eventingduckv1.SubscribableSpec: - if len(source.Subscribers) > 0 { - sink.Subscribable = &Subscribable{ - Subscribers: make([]SubscriberSpec, len(source.Subscribers)), - } - for i := range source.Subscribers { - if err := sink.Subscribable.Subscribers[i].ConvertFrom(ctx, &source.Subscribers[i]); err != nil { - return err - } - } - } - default: - return fmt.Errorf("unknown version, got: %T", source) - } - return nil -} - -// ConvertFrom implements apis.Convertible -func (sink *SubscriberSpec) ConvertFrom(ctx context.Context, obj apis.Convertible) error { - switch source := obj.(type) { - case *eventingduckv1beta1.SubscriberSpec: - var deadLetterSinkURI *apis.URL - if source.Delivery != nil && source.Delivery.DeadLetterSink != nil { - deadLetterSinkURI = source.Delivery.DeadLetterSink.URI - } - sink.UID = source.UID - sink.Generation = source.Generation - sink.SubscriberURI = source.SubscriberURI - sink.ReplyURI = source.ReplyURI - sink.Delivery = source.Delivery - sink.DeadLetterSinkURI = deadLetterSinkURI - case *eventingduckv1.SubscriberSpec: - sink.UID = source.UID - sink.Generation = source.Generation - sink.SubscriberURI = source.SubscriberURI - sink.ReplyURI = source.ReplyURI - if source.Delivery != nil { - sink.Delivery = &eventingduckv1beta1.DeliverySpec{} - if err := sink.Delivery.ConvertFrom(ctx, source.Delivery); err != nil { - return err - } - sink.DeadLetterSinkURI = source.Delivery.DeadLetterSink.URI - } - default: - return fmt.Errorf("unknown version, got: %T", sink) - } - return nil -} - -// ConvertFrom implements apis.Convertible -func (sink *SubscribableTypeStatus) ConvertFrom(ctx context.Context, obj apis.Convertible) error { - switch source := obj.(type) { - case *eventingduckv1beta1.SubscribableStatus: - if len(source.Subscribers) > 0 { - sink.SubscribableStatus = &SubscribableStatus{ - Subscribers: make([]eventingduckv1beta1.SubscriberStatus, len(source.Subscribers)), - } - for i, ss := range source.Subscribers { - sink.SubscribableStatus.Subscribers[i] = eventingduckv1beta1.SubscriberStatus{ - UID: ss.UID, - ObservedGeneration: ss.ObservedGeneration, - Ready: ss.Ready, - Message: ss.Message, - } - } - } - case *eventingduckv1.SubscribableStatus: - if len(source.Subscribers) > 0 { - sink.SubscribableStatus = &SubscribableStatus{ - Subscribers: make([]eventingduckv1beta1.SubscriberStatus, len(source.Subscribers)), - } - for i := range source.Subscribers { - sink.SubscribableStatus.Subscribers[i] = eventingduckv1beta1.SubscriberStatus{} - if err := sink.SubscribableStatus.Subscribers[i].ConvertFrom(ctx, &source.Subscribers[i]); err != nil { - return err - } - } - } - default: - return fmt.Errorf("unknown version, got: %T", sink) - } - return nil -} diff --git a/pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go b/pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go deleted file mode 100644 index 883f12a7900..00000000000 --- a/pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go +++ /dev/null @@ -1,463 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" - "knative.dev/pkg/apis" - pkgduckv1 "knative.dev/pkg/apis/duck/v1" - - v1 "knative.dev/eventing/pkg/apis/duck/v1" - "knative.dev/eventing/pkg/apis/duck/v1beta1" -) - -func TestSubscribableTypeConversionBadType(t *testing.T) { - good, bad := &SubscribableType{}, &pkgduckv1.Addressable{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -// Test v1alpha1 -> v1beta1 -> v1alpha1 -func TestSubscribableTypeConversionV1alphaV1beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.Subscribable{}} - - linear := v1beta1.BackoffPolicyLinear - - tests := []struct { - name string - in *SubscribableType - }{{ - name: "min configuration", - in: &SubscribableType{ - ObjectMeta: metav1.ObjectMeta{ - Name: "subscribable-name", - Namespace: "subscribable-ns", - Generation: 17, - }, - Spec: SubscribableTypeSpec{}, - Status: SubscribableTypeStatus{}, - }, - }, { - name: "full configuration", - in: &SubscribableType{ - ObjectMeta: metav1.ObjectMeta{ - Name: "subscribable-name", - Namespace: "subscribable-ns", - Generation: 17, - }, - Spec: SubscribableTypeSpec{ - Subscribable: &Subscribable{ - Subscribers: []SubscriberSpec{ - { - UID: "uid-1", - Generation: 7, - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - DeadLetterSinkURI: apis.HTTP("subscriber.dls.example.com"), - Delivery: &v1beta1.DeliverySpec{ - DeadLetterSink: &pkgduckv1.Destination{ - Ref: &pkgduckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("subscriber.dls.example.com"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - { - UID: "uid-2", - Generation: 8, - SubscriberURI: apis.HTTP("subscriber2.example.com"), - ReplyURI: apis.HTTP("reply2.example.com"), - DeadLetterSinkURI: apis.HTTP("subscriber2.dls.example.com"), - Delivery: nil, - }, - }, - }, - }, - Status: SubscribableTypeStatus{ - SubscribableStatus: &SubscribableStatus{ - Subscribers: []v1beta1.SubscriberStatus{ - { - UID: "status-uid-1", - ObservedGeneration: 99, - Ready: corev1.ConditionTrue, - Message: "msg", - }, - }, - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Error("ConvertTo() =", err) - } - got := &SubscribableType{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Error("ConvertFrom() =", err) - } - - fixed := fixSubscribableTypeDeprecated(test.in) - if diff := cmp.Diff(fixed, got); diff != "" { - t.Error("roundtrip (-want, +got) =", diff) - } - }) - } - } -} - -// Test v1alpha1 -> v1 -> v1alpha1 -func TestSubscribableTypeConversionV1alphaV1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1.Subscribable{}} - - linear := v1beta1.BackoffPolicyLinear - - tests := []struct { - name string - in *SubscribableType - }{{ - name: "min configuration", - in: &SubscribableType{ - ObjectMeta: metav1.ObjectMeta{ - Name: "subscribable-name", - Namespace: "subscribable-ns", - Generation: 17, - }, - Spec: SubscribableTypeSpec{}, - Status: SubscribableTypeStatus{}, - }, - }, { - name: "full configuration", - in: &SubscribableType{ - ObjectMeta: metav1.ObjectMeta{ - Name: "subscribable-name", - Namespace: "subscribable-ns", - Generation: 17, - }, - Spec: SubscribableTypeSpec{ - Subscribable: &Subscribable{ - Subscribers: []SubscriberSpec{ - { - UID: "uid-1", - Generation: 7, - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - DeadLetterSinkURI: apis.HTTP("subscriber.dls.example.com"), - Delivery: &v1beta1.DeliverySpec{ - DeadLetterSink: &pkgduckv1.Destination{ - Ref: &pkgduckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("subscriber.dls.example.com"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - { - UID: "uid-2", - Generation: 8, - SubscriberURI: apis.HTTP("subscriber2.example.com"), - ReplyURI: apis.HTTP("reply2.example.com"), - DeadLetterSinkURI: apis.HTTP("subscriber2.dls.example.com"), - Delivery: nil, - }, - }, - }, - }, - Status: SubscribableTypeStatus{ - SubscribableStatus: &SubscribableStatus{ - Subscribers: []v1beta1.SubscriberStatus{ - { - UID: "status-uid-1", - ObservedGeneration: 99, - Ready: corev1.ConditionTrue, - Message: "msg", - }, - }, - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Error("ConvertTo() =", err) - } - got := &SubscribableType{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Error("ConvertFrom() =", err) - } - - fixed := fixSubscribableTypeDeprecated(test.in) - if diff := cmp.Diff(fixed, got); diff != "" { - t.Error("roundtrip (-want, +got) =", diff) - } - }) - } - } -} - -// Test v1beta1 -> v1alpha1 -> v1beta1 -func TestSubscribableTypeConversionWithV1beta1V1alpha1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&SubscribableType{}} - - linear := v1beta1.BackoffPolicyLinear - - tests := []struct { - name string - in *v1beta1.Subscribable - }{{ - name: "min", - in: &v1beta1.Subscribable{ - ObjectMeta: metav1.ObjectMeta{ - Name: "subscribable-name", - Namespace: "subscribable-ns", - Generation: 17, - }, - Spec: v1beta1.SubscribableSpec{}, - Status: v1beta1.SubscribableStatus{}, - }, - }, { - name: "full configuration", - in: &v1beta1.Subscribable{ - ObjectMeta: metav1.ObjectMeta{ - Name: "subscribable-name", - Namespace: "subscribable-ns", - Generation: 17, - }, - Spec: v1beta1.SubscribableSpec{ - Subscribers: []v1beta1.SubscriberSpec{ - { - UID: "uid-1", - Generation: 7, - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - Delivery: &v1beta1.DeliverySpec{ - DeadLetterSink: &pkgduckv1.Destination{ - Ref: &pkgduckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("subscriber.dls.example.com"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - }, - }, - Status: v1beta1.SubscribableStatus{ - Subscribers: []v1beta1.SubscriberStatus{ - { - UID: "status-uid-1", - ObservedGeneration: 99, - Ready: corev1.ConditionTrue, - Message: "msg", - }, - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := version.ConvertFrom(context.Background(), test.in); err != nil { - t.Error("ConvertTo() =", err) - } - got := &v1beta1.Subscribable{} - if err := ver.ConvertTo(context.Background(), got); err != nil { - t.Error("ConvertFrom() =", err) - } - if diff := cmp.Diff(test.in, got); diff != "" { - t.Error("roundtrip (-want, +got) =", diff) - } - }) - } - } -} - -// Test v1 -> v1alpha1 -> v1 -func TestSubscribableTypeConversionWithV1V1alpha1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&SubscribableType{}} - - linear := v1.BackoffPolicyLinear - - tests := []struct { - name string - in *v1.Subscribable - }{{ - name: "min", - in: &v1.Subscribable{ - ObjectMeta: metav1.ObjectMeta{ - Name: "subscribable-name", - Namespace: "subscribable-ns", - Generation: 17, - }, - Spec: v1.SubscribableSpec{}, - Status: v1.SubscribableStatus{}, - }, - }, { - name: "full configuration", - in: &v1.Subscribable{ - ObjectMeta: metav1.ObjectMeta{ - Name: "subscribable-name", - Namespace: "subscribable-ns", - Generation: 17, - }, - Spec: v1.SubscribableSpec{ - Subscribers: []v1.SubscriberSpec{ - { - UID: "uid-1", - Generation: 7, - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - Delivery: &v1.DeliverySpec{ - DeadLetterSink: &pkgduckv1.Destination{ - Ref: &pkgduckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("subscriber.dls.example.com"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - }, - }, - Status: v1.SubscribableStatus{ - Subscribers: []v1.SubscriberStatus{ - { - UID: "status-uid-1", - ObservedGeneration: 99, - Ready: corev1.ConditionTrue, - Message: "msg", - }, - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := version.ConvertFrom(context.Background(), test.in); err != nil { - t.Error("ConvertTo() =", err) - } - got := &v1.Subscribable{} - if err := ver.ConvertTo(context.Background(), got); err != nil { - t.Error("ConvertFrom() =", err) - } - if diff := cmp.Diff(test.in, got); diff != "" { - t.Error("roundtrip (-want, +got) =", diff) - } - }) - } - } -} - -func TestSubscribableTypeSpecConversionBadType(t *testing.T) { - good, bad := &SubscribableTypeSpec{}, &SubscribableTypeSpec{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestSubscribableTypeStatusConversionBadType(t *testing.T) { - good, bad := &SubscribableTypeStatus{}, &SubscribableTypeStatus{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestSubscriberSpecConversionBadType(t *testing.T) { - good, bad := &SubscriberSpec{}, &SubscriberSpec{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -// Since v1beta1 to v1alpha1 is lossy. -func fixSubscribableTypeDeprecated(in *SubscribableType) *SubscribableType { - if in.Spec.Subscribable != nil && len(in.Spec.Subscribable.Subscribers) > 0 { - for i := range in.Spec.Subscribable.Subscribers { - if in.Spec.Subscribable.Subscribers[i].Delivery == nil { - in.Spec.Subscribable.Subscribers[i].Delivery = &v1beta1.DeliverySpec{ - DeadLetterSink: &pkgduckv1.Destination{ - URI: in.Spec.Subscribable.Subscribers[i].DeadLetterSinkURI, - }, - } - } - } - } - - return in -} diff --git a/pkg/apis/duck/v1alpha1/subscribable_types_test.go b/pkg/apis/duck/v1alpha1/subscribable_types_test.go deleted file mode 100644 index 078f80bfb2f..00000000000 --- a/pkg/apis/duck/v1alpha1/subscribable_types_test.go +++ /dev/null @@ -1,141 +0,0 @@ -/* -Copyright 2019 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 v1alpha1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/pkg/apis" -) - -func TestSubscribableGetFullType(t *testing.T) { - s := &Subscribable{} - switch s.GetFullType().(type) { - case *SubscribableType: - // expected - default: - t.Errorf("expected GetFullType to return *SubscribableType, got %T", s.GetFullType()) - } -} - -func TestSubscribableGetListType(t *testing.T) { - c := &SubscribableType{} - switch c.GetListType().(type) { - case *SubscribableTypeList: - // expected - default: - t.Errorf("expected GetListType to return *SubscribableTypeList, got %T", c.GetListType()) - } -} - -func TestSubscribablePopulate(t *testing.T) { - got := &SubscribableType{} - - want := &SubscribableType{ - Spec: SubscribableTypeSpec{ - Subscribable: &Subscribable{ - Subscribers: []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"), - }}, - }, - }, - Status: SubscribableTypeStatus{ - SubscribableStatus: &SubscribableStatus{ - // Populate ALL fields - Subscribers: []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", - }}, - }, - }, - } - - got.Populate() - - if diff := cmp.Diff(want, got); diff != "" { - t.Error("Unexpected difference (-want, +got):", diff) - } - -} - -func TestSubscribableTypeStatusHelperMethods(t *testing.T) { - s := &SubscribableStatus{ - // Populate ALL fields - Subscribers: []eventingduckv1beta1.SubscriberStatus{{ - UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", - ObservedGeneration: 1, - Ready: corev1.ConditionTrue, - Message: "This is new field", - }, { - UID: "34c5aec8-deb6-11e8-9f32-f2801f1b9fd1", - ObservedGeneration: 2, - Ready: corev1.ConditionFalse, - Message: "This is new field", - }}, - } - - subscribableTypeStatus := SubscribableTypeStatus{ - SubscribableStatus: s, - } - - /* Test GetSubscribableTypeStatus */ - - // Should return SubscribableTypeStatus#SubscribableStatus - subscribableStatus := subscribableTypeStatus.GetSubscribableTypeStatus() - if subscribableStatus.Subscribers[0].Message != "This is new field" { - t.Error("Testing of GetSubscribableTypeStatus failed as the function returned something unexpected") - } - - /* Test SetSubscribableTypeStatus */ - - // This should set both the fields to same value - subscribableTypeStatus.SetSubscribableTypeStatus(*s) - if subscribableTypeStatus.SubscribableStatus.Subscribers[0].Message != "This is new field" { - t.Error("SetSubscribableTypeStatus didn't work as expected") - } - - /* Test AddSubscriberToSubscribableStatus */ - subscribableTypeStatus.AddSubscriberToSubscribableStatus(eventingduckv1beta1.SubscriberStatus{ - UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", - ObservedGeneration: 1, - Ready: corev1.ConditionTrue, - Message: "This is new field", - }) - - // Check if the subscriber was added to both the fields of SubscribableTypeStatus - if len(subscribableTypeStatus.SubscribableStatus.Subscribers) != 3 { - t.Error("AddSubscriberToSubscribableStatus didn't add subscriberstatus to both the fields of SubscribableTypeStatus") - } -} diff --git a/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index a584b21406b..00000000000 --- a/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,486 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2021 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. -*/ - -// Code generated by deepcopy-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1 "k8s.io/api/core/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - v1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - apis "knative.dev/pkg/apis" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Channelable) DeepCopyInto(out *Channelable) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Channelable. -func (in *Channelable) DeepCopy() *Channelable { - if in == nil { - return nil - } - out := new(Channelable) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Channelable) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelableCombined) DeepCopyInto(out *ChannelableCombined) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelableCombined. -func (in *ChannelableCombined) DeepCopy() *ChannelableCombined { - if in == nil { - return nil - } - out := new(ChannelableCombined) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ChannelableCombined) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelableCombinedList) DeepCopyInto(out *ChannelableCombinedList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]ChannelableCombined, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelableCombinedList. -func (in *ChannelableCombinedList) DeepCopy() *ChannelableCombinedList { - if in == nil { - return nil - } - out := new(ChannelableCombinedList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ChannelableCombinedList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelableCombinedSpec) DeepCopyInto(out *ChannelableCombinedSpec) { - *out = *in - in.SubscribableTypeSpec.DeepCopyInto(&out.SubscribableTypeSpec) - in.SubscribableSpec.DeepCopyInto(&out.SubscribableSpec) - if in.Delivery != nil { - in, out := &in.Delivery, &out.Delivery - *out = new(v1beta1.DeliverySpec) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelableCombinedSpec. -func (in *ChannelableCombinedSpec) DeepCopy() *ChannelableCombinedSpec { - if in == nil { - return nil - } - out := new(ChannelableCombinedSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelableCombinedStatus) DeepCopyInto(out *ChannelableCombinedStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) - in.AddressStatus.DeepCopyInto(&out.AddressStatus) - in.SubscribableTypeStatus.DeepCopyInto(&out.SubscribableTypeStatus) - in.SubscribableStatus.DeepCopyInto(&out.SubscribableStatus) - if in.ErrorChannel != nil { - in, out := &in.ErrorChannel, &out.ErrorChannel - *out = new(v1.ObjectReference) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelableCombinedStatus. -func (in *ChannelableCombinedStatus) DeepCopy() *ChannelableCombinedStatus { - if in == nil { - return nil - } - out := new(ChannelableCombinedStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelableList) DeepCopyInto(out *ChannelableList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Channelable, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelableList. -func (in *ChannelableList) DeepCopy() *ChannelableList { - if in == nil { - return nil - } - out := new(ChannelableList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ChannelableList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelableSpec) DeepCopyInto(out *ChannelableSpec) { - *out = *in - in.SubscribableTypeSpec.DeepCopyInto(&out.SubscribableTypeSpec) - if in.Delivery != nil { - in, out := &in.Delivery, &out.Delivery - *out = new(v1beta1.DeliverySpec) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelableSpec. -func (in *ChannelableSpec) DeepCopy() *ChannelableSpec { - if in == nil { - return nil - } - out := new(ChannelableSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelableStatus) DeepCopyInto(out *ChannelableStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) - in.AddressStatus.DeepCopyInto(&out.AddressStatus) - in.SubscribableTypeStatus.DeepCopyInto(&out.SubscribableTypeStatus) - if in.ErrorChannel != nil { - in, out := &in.ErrorChannel, &out.ErrorChannel - *out = new(v1.ObjectReference) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelableStatus. -func (in *ChannelableStatus) DeepCopy() *ChannelableStatus { - if in == nil { - return nil - } - out := new(ChannelableStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Resource) DeepCopyInto(out *Resource) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resource. -func (in *Resource) DeepCopy() *Resource { - if in == nil { - return nil - } - out := new(Resource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Resource) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ResourceList) DeepCopyInto(out *ResourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Resource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceList. -func (in *ResourceList) DeepCopy() *ResourceList { - if in == nil { - return nil - } - out := new(ResourceList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ResourceList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Subscribable) DeepCopyInto(out *Subscribable) { - *out = *in - if in.Subscribers != nil { - in, out := &in.Subscribers, &out.Subscribers - *out = make([]SubscriberSpec, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Subscribable. -func (in *Subscribable) DeepCopy() *Subscribable { - if in == nil { - return nil - } - out := new(Subscribable) - in.DeepCopyInto(out) - return out -} - -// 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 - *out = make([]v1beta1.SubscriberStatus, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscribableStatus. -func (in *SubscribableStatus) DeepCopy() *SubscribableStatus { - if in == nil { - return nil - } - out := new(SubscribableStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscribableType) DeepCopyInto(out *SubscribableType) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscribableType. -func (in *SubscribableType) DeepCopy() *SubscribableType { - if in == nil { - return nil - } - out := new(SubscribableType) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *SubscribableType) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscribableTypeList) DeepCopyInto(out *SubscribableTypeList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]SubscribableType, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscribableTypeList. -func (in *SubscribableTypeList) DeepCopy() *SubscribableTypeList { - if in == nil { - return nil - } - out := new(SubscribableTypeList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *SubscribableTypeList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscribableTypeSpec) DeepCopyInto(out *SubscribableTypeSpec) { - *out = *in - if in.Subscribable != nil { - in, out := &in.Subscribable, &out.Subscribable - *out = new(Subscribable) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscribableTypeSpec. -func (in *SubscribableTypeSpec) DeepCopy() *SubscribableTypeSpec { - if in == nil { - return nil - } - out := new(SubscribableTypeSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscribableTypeStatus) DeepCopyInto(out *SubscribableTypeStatus) { - *out = *in - if in.SubscribableStatus != nil { - in, out := &in.SubscribableStatus, &out.SubscribableStatus - *out = new(SubscribableStatus) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscribableTypeStatus. -func (in *SubscribableTypeStatus) DeepCopy() *SubscribableTypeStatus { - if in == nil { - return nil - } - out := new(SubscribableTypeStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriberSpec) DeepCopyInto(out *SubscriberSpec) { - *out = *in - if in.SubscriberURI != nil { - in, out := &in.SubscriberURI, &out.SubscriberURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - if in.ReplyURI != nil { - in, out := &in.ReplyURI, &out.ReplyURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - if in.DeadLetterSinkURI != nil { - in, out := &in.DeadLetterSinkURI, &out.DeadLetterSinkURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - if in.Delivery != nil { - in, out := &in.Delivery, &out.Delivery - *out = new(v1beta1.DeliverySpec) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriberSpec. -func (in *SubscriberSpec) DeepCopy() *SubscriberSpec { - if in == nil { - return nil - } - out := new(SubscriberSpec) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/client/injection/ducks/duck/v1alpha1/channelable/channelable.go b/pkg/client/injection/ducks/duck/v1alpha1/channelable/channelable.go deleted file mode 100644 index f3c881bd93a..00000000000 --- a/pkg/client/injection/ducks/duck/v1alpha1/channelable/channelable.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2021 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package channelable - -import ( - context "context" - - v1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duck "knative.dev/pkg/apis/duck" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - dynamicclient "knative.dev/pkg/injection/clients/dynamicclient" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterDuck(WithDuck) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func WithDuck(ctx context.Context) context.Context { - dc := dynamicclient.Get(ctx) - dif := &duck.CachedInformerFactory{ - Delegate: &duck.TypedInformerFactory{ - Client: dc, - Type: (&v1alpha1.Channelable{}).GetFullType(), - ResyncPeriod: controller.GetResyncPeriod(ctx), - StopChannel: ctx.Done(), - }, - } - return context.WithValue(ctx, Key{}, dif) -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) duck.InformerFactory { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch knative.dev/pkg/apis/duck.InformerFactory from context.") - } - return untyped.(duck.InformerFactory) -} diff --git a/pkg/client/injection/ducks/duck/v1alpha1/channelable/fake/fake.go b/pkg/client/injection/ducks/duck/v1alpha1/channelable/fake/fake.go deleted file mode 100644 index 2aa31573a5a..00000000000 --- a/pkg/client/injection/ducks/duck/v1alpha1/channelable/fake/fake.go +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2021 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - channelable "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelable" - injection "knative.dev/pkg/injection" -) - -var Get = channelable.Get - -func init() { - injection.Fake.RegisterDuck(channelable.WithDuck) -} diff --git a/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/channelablecombined.go b/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/channelablecombined.go deleted file mode 100644 index f6d593580df..00000000000 --- a/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/channelablecombined.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2021 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package channelablecombined - -import ( - context "context" - - v1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duck "knative.dev/pkg/apis/duck" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - dynamicclient "knative.dev/pkg/injection/clients/dynamicclient" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterDuck(WithDuck) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func WithDuck(ctx context.Context) context.Context { - dc := dynamicclient.Get(ctx) - dif := &duck.CachedInformerFactory{ - Delegate: &duck.TypedInformerFactory{ - Client: dc, - Type: (&v1alpha1.ChannelableCombined{}).GetFullType(), - ResyncPeriod: controller.GetResyncPeriod(ctx), - StopChannel: ctx.Done(), - }, - } - return context.WithValue(ctx, Key{}, dif) -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) duck.InformerFactory { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch knative.dev/pkg/apis/duck.InformerFactory from context.") - } - return untyped.(duck.InformerFactory) -} diff --git a/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/fake/fake.go b/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/fake/fake.go deleted file mode 100644 index 1e0a58c3016..00000000000 --- a/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/fake/fake.go +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2021 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - channelablecombined "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined" - injection "knative.dev/pkg/injection" -) - -var Get = channelablecombined.Get - -func init() { - injection.Fake.RegisterDuck(channelablecombined.WithDuck) -} diff --git a/pkg/client/injection/ducks/duck/v1alpha1/subscribable/fake/fake.go b/pkg/client/injection/ducks/duck/v1alpha1/subscribable/fake/fake.go deleted file mode 100644 index d060b64f06c..00000000000 --- a/pkg/client/injection/ducks/duck/v1alpha1/subscribable/fake/fake.go +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2021 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - subscribable "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/subscribable" - injection "knative.dev/pkg/injection" -) - -var Get = subscribable.Get - -func init() { - injection.Fake.RegisterDuck(subscribable.WithDuck) -} diff --git a/pkg/client/injection/ducks/duck/v1alpha1/subscribable/subscribable.go b/pkg/client/injection/ducks/duck/v1alpha1/subscribable/subscribable.go deleted file mode 100644 index 4ceab1b39ad..00000000000 --- a/pkg/client/injection/ducks/duck/v1alpha1/subscribable/subscribable.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2021 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package subscribable - -import ( - context "context" - - v1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duck "knative.dev/pkg/apis/duck" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - dynamicclient "knative.dev/pkg/injection/clients/dynamicclient" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterDuck(WithDuck) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func WithDuck(ctx context.Context) context.Context { - dc := dynamicclient.Get(ctx) - dif := &duck.CachedInformerFactory{ - Delegate: &duck.TypedInformerFactory{ - Client: dc, - Type: (&v1alpha1.Subscribable{}).GetFullType(), - ResyncPeriod: controller.GetResyncPeriod(ctx), - StopChannel: ctx.Done(), - }, - } - return context.WithValue(ctx, Key{}, dif) -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) duck.InformerFactory { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch knative.dev/pkg/apis/duck.InformerFactory from context.") - } - return untyped.(duck.InformerFactory) -} From 5b2125c660554dad8e740808b0d79e4fa7016aa2 Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Tue, 2 Mar 2021 14:47:30 -0800 Subject: [PATCH 3/9] remove v1alpha1/Channelable from Subscription --- pkg/reconciler/subscription/controller.go | 4 +- .../subscription/controller_test.go | 3 +- pkg/reconciler/subscription/subscription.go | 140 +++--------------- .../subscription/subscription_test.go | 8 +- 4 files changed, 22 insertions(+), 133 deletions(-) diff --git a/pkg/reconciler/subscription/controller.go b/pkg/reconciler/subscription/controller.go index 87908e43b48..63e3931a98f 100644 --- a/pkg/reconciler/subscription/controller.go +++ b/pkg/reconciler/subscription/controller.go @@ -26,7 +26,7 @@ import ( "knative.dev/pkg/tracker" messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" - "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined" + "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable" "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" @@ -56,7 +56,7 @@ func NewController( // Trackers used to notify us when the resources Subscription depends on change, so that the // Subscription needs to reconcile again. - r.channelableTracker = duck.NewListableTracker(ctx, channelablecombined.Get, impl.EnqueueKey, controller.GetTrackerLease(ctx)) + r.channelableTracker = duck.NewListableTracker(ctx, channelable.Get, impl.EnqueueKey, controller.GetTrackerLease(ctx)) r.destinationResolver = resolver.NewURIResolver(ctx, impl.EnqueueKey) // Track changes to Channels. diff --git a/pkg/reconciler/subscription/controller_test.go b/pkg/reconciler/subscription/controller_test.go index adb8c0c0be4..01d961ce950 100644 --- a/pkg/reconciler/subscription/controller_test.go +++ b/pkg/reconciler/subscription/controller_test.go @@ -23,8 +23,7 @@ import ( . "knative.dev/pkg/reconciler/testing" // 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/ducks/duck/v1/channelable/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 201570e9539..95e55bd26b0 100644 --- a/pkg/reconciler/subscription/subscription.go +++ b/pkg/reconciler/subscription/subscription.go @@ -37,9 +37,6 @@ import ( "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" subscriptionreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/subscription" listers "knative.dev/eventing/pkg/client/listers/messaging/v1" @@ -132,7 +129,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, subscription *v1.Subscrip return nil } -func (r Reconciler) checkChannelStatusForSubscription(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) pkgreconciler.Event { +func (r Reconciler) checkChannelStatusForSubscription(ctx context.Context, channel *eventingduckv1.Channelable, sub *v1.Subscription) pkgreconciler.Event { ss, err := r.getSubStatus(ctx, sub, channel) if err != nil { logging.FromContext(ctx).Warnw("Failed to get subscription status.", zap.Error(err)) @@ -152,7 +149,7 @@ func (r Reconciler) checkChannelStatusForSubscription(ctx context.Context, chann return nil } -func (r Reconciler) syncChannel(ctx context.Context, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) pkgreconciler.Event { +func (r Reconciler) syncChannel(ctx context.Context, channel *eventingduckv1.Channelable, 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 { @@ -173,7 +170,7 @@ func (r Reconciler) syncChannel(ctx context.Context, channel *eventingduckv1alph return nil } -func (r *Reconciler) resolveSubscriptionURIs(ctx context.Context, subscription *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) pkgreconciler.Event { +func (r *Reconciler) resolveSubscriptionURIs(ctx context.Context, subscription *v1.Subscription, channel *eventingduckv1.Channelable) pkgreconciler.Event { // Everything that was supposed to be resolved was, so flip the status bit on that. subscription.Status.MarkReferencesResolvedUnknown("Resolving", "Subscription resolution interrupted.") @@ -281,34 +278,7 @@ func (r *Reconciler) resolveDeadLetterSink(ctx context.Context, deadLetterSink * return nil } -func (r *Reconciler) getSubStatus(ctx context.Context, subscription *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1.SubscriberStatus, error) { - if channel.Annotations != nil { - if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" || - channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" { - return r.getSubStatusV1(subscription, channel) - } - } - return r.getSubStatusV1Alpha1(ctx, subscription, channel) -} - -func (r *Reconciler) getSubStatusV1Alpha1(ctx context.Context, subscription *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1.SubscriberStatus, error) { - subscribableStatus := channel.Status.GetSubscribableTypeStatus() - - if subscribableStatus == nil { - return eventingduckv1.SubscriberStatus{}, fmt.Errorf("channel.Status.SubscribableStatus is nil") - } - for _, sub := range subscribableStatus.Subscribers { - if sub.UID == subscription.GetUID() && - sub.ObservedGeneration == subscription.GetGeneration() { - subv1 := eventingduckv1.SubscriberStatus{} - sub.ConvertTo(ctx, &subv1) - return subv1, nil - } - } - return eventingduckv1.SubscriberStatus{}, fmt.Errorf("subscription %q not present in channel %q subscriber's list", subscription.Name, channel.Name) -} - -func (r *Reconciler) getSubStatusV1(subscription *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (eventingduckv1.SubscriberStatus, error) { +func (r *Reconciler) getSubStatus(ctx context.Context, subscription *v1.Subscription, channel *eventingduckv1.Channelable) (eventingduckv1.SubscriberStatus, error) { for _, sub := range channel.Status.Subscribers { if sub.UID == subscription.GetUID() && sub.ObservedGeneration == subscription.GetGeneration() { @@ -348,7 +318,7 @@ func (r *Reconciler) trackAndFetchChannel(ctx context.Context, sub *v1.Subscript // 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 *v1.Subscription) (*eventingduckv1alpha1.ChannelableCombined, pkgreconciler.Event) { +func (r *Reconciler) getChannel(ctx context.Context, sub *v1.Subscription) (*eventingduckv1.Channelable, pkgreconciler.Event) { logging.FromContext(ctx).Infow("Getting channel", zap.Any("channel", sub.Spec.Channel)) // 1. Track the channel pointed by subscription. @@ -408,7 +378,7 @@ func (r *Reconciler) getChannel(ctx context.Context, sub *v1.Subscription) (*eve } // Now obj is supposed to be a Channelable, so check it. - ch, ok := obj.(*eventingduckv1alpha1.ChannelableCombined) + ch, ok := obj.(*eventingduckv1.Channelable) if !ok { logging.FromContext(ctx).Errorw("Failed to convert to Channelable Object", zap.Any("channel", sub.Spec.Channel), zap.Error(err)) return nil, fmt.Errorf("Failed to convert to Channelable Object: %+v", obj) @@ -421,7 +391,7 @@ func isNilOrEmptyDestination(destination *duckv1.Destination) bool { return destination == nil || equality.Semantic.DeepEqual(destination, &duckv1.Destination{}) } -func (r *Reconciler) syncPhysicalChannel(ctx context.Context, sub *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined, isDeleted bool) (bool, error) { +func (r *Reconciler) syncPhysicalChannel(ctx context.Context, sub *v1.Subscription, channel *eventingduckv1.Channelable, isDeleted bool) (bool, error) { logging.FromContext(ctx).Debugw("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 +404,7 @@ func (r *Reconciler) syncPhysicalChannel(ctx context.Context, sub *v1.Subscripti } } -func (r *Reconciler) patchSubscription(ctx context.Context, namespace string, channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) (bool, error) { +func (r *Reconciler) patchSubscription(ctx context.Context, namespace string, channel *eventingduckv1.Channelable, sub *v1.Subscription) (bool, error) { after := channel.DeepCopy() if sub.DeletionTimestamp.IsZero() { @@ -467,18 +437,7 @@ func (r *Reconciler) patchSubscription(ctx context.Context, namespace string, ch return true, nil } -func (r *Reconciler) updateChannelRemoveSubscription(channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { - if channel.Annotations != nil { - if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" || - channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" { - r.updateChannelRemoveSubscriptionV1Beta1(channel, sub) - return - } - } - r.updateChannelRemoveSubscriptionV1Alpha1(channel, sub) -} - -func (r *Reconciler) updateChannelRemoveSubscriptionV1Beta1(channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { +func (r *Reconciler) updateChannelRemoveSubscription(channel *eventingduckv1.Channelable, sub *v1.Subscription) { for i, v := range channel.Spec.Subscribers { if v.UID == sub.UID { channel.Spec.Subscribers = append( @@ -489,72 +448,7 @@ func (r *Reconciler) updateChannelRemoveSubscriptionV1Beta1(channel *eventingduc } } -func (r *Reconciler) updateChannelRemoveSubscriptionV1Alpha1(channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { - if channel.Spec.Subscribable == nil { - return - } - - for i, v := range channel.Spec.Subscribable.Subscribers { - if v.UID == sub.UID { - channel.Spec.Subscribable.Subscribers = append( - channel.Spec.Subscribable.Subscribers[:i], - channel.Spec.Subscribable.Subscribers[i+1:]...) - return - } - } -} - -func (r *Reconciler) updateChannelAddSubscription(channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { - if channel.Annotations != nil { - if channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" || - channel.Annotations[messaging.SubscribableDuckVersionAnnotation] == "v1" { - r.updateChannelAddSubscriptionV1Beta1(channel, sub) - return - } - } - r.updateChannelAddSubscriptionV1Alpha1(channel, sub) -} - -func (r *Reconciler) updateChannelAddSubscriptionV1Alpha1(channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { - if channel.Spec.Subscribable == nil { - channel.Spec.Subscribable = &eventingduckv1alpha1.Subscribable{ - Subscribers: []eventingduckv1alpha1.SubscriberSpec{{ - UID: sub.UID, - Generation: sub.Generation, - SubscriberURI: sub.Status.PhysicalSubscription.SubscriberURI, - ReplyURI: sub.Status.PhysicalSubscription.ReplyURI, - DeadLetterSinkURI: sub.Status.PhysicalSubscription.DeadLetterSinkURI, - Delivery: deliverySpec(sub, channel), - }}, - } - return - } - - // Look to update subscriber. - for i, v := range channel.Spec.Subscribable.Subscribers { - if v.UID == sub.UID { - channel.Spec.Subscribable.Subscribers[i].Generation = sub.Generation - channel.Spec.Subscribable.Subscribers[i].SubscriberURI = sub.Status.PhysicalSubscription.SubscriberURI - channel.Spec.Subscribable.Subscribers[i].ReplyURI = sub.Status.PhysicalSubscription.ReplyURI - channel.Spec.Subscribable.Subscribers[i].DeadLetterSinkURI = sub.Status.PhysicalSubscription.DeadLetterSinkURI - channel.Spec.Subscribable.Subscribers[i].Delivery = deliverySpec(sub, channel) - return - } - } - - // Must not have been found. Add it. - channel.Spec.Subscribable.Subscribers = append(channel.Spec.Subscribable.Subscribers, - eventingduckv1alpha1.SubscriberSpec{ - UID: sub.UID, - Generation: sub.Generation, - SubscriberURI: sub.Status.PhysicalSubscription.SubscriberURI, - ReplyURI: sub.Status.PhysicalSubscription.ReplyURI, - DeadLetterSinkURI: sub.Status.PhysicalSubscription.DeadLetterSinkURI, - Delivery: deliverySpec(sub, channel), - }) -} - -func (r *Reconciler) updateChannelAddSubscriptionV1Beta1(channel *eventingduckv1alpha1.ChannelableCombined, sub *v1.Subscription) { +func (r *Reconciler) updateChannelAddSubscription(channel *eventingduckv1.Channelable, sub *v1.Subscription) { // Look to update subscriber. for i, v := range channel.Spec.Subscribers { if v.UID == sub.UID { @@ -566,7 +460,7 @@ func (r *Reconciler) updateChannelAddSubscriptionV1Beta1(channel *eventingduckv1 } } - toAdd := eventingduckv1beta1.SubscriberSpec{ + toAdd := eventingduckv1.SubscriberSpec{ UID: sub.UID, Generation: sub.Generation, SubscriberURI: sub.Status.PhysicalSubscription.SubscriberURI, @@ -578,11 +472,11 @@ func (r *Reconciler) updateChannelAddSubscriptionV1Beta1(channel *eventingduckv1 channel.Spec.Subscribers = append(channel.Spec.Subscribers, toAdd) } -func deliverySpec(sub *v1.Subscription, channel *eventingduckv1alpha1.ChannelableCombined) (delivery *eventingduckv1beta1.DeliverySpec) { +func deliverySpec(sub *v1.Subscription, channel *eventingduckv1.Channelable) (delivery *eventingduckv1.DeliverySpec) { if sub.Spec.Delivery == nil && channel.Spec.Delivery != nil { // Default to the channel spec if sub.Status.PhysicalSubscription.DeadLetterSinkURI != nil { - delivery = &eventingduckv1beta1.DeliverySpec{ + delivery = &eventingduckv1.DeliverySpec{ DeadLetterSink: &duckv1.Destination{ URI: sub.Status.PhysicalSubscription.DeadLetterSinkURI, }, @@ -590,7 +484,7 @@ func deliverySpec(sub *v1.Subscription, channel *eventingduckv1alpha1.Channelabl } if channel.Spec.Delivery.BackoffDelay != nil || channel.Spec.Delivery.Retry != nil || channel.Spec.Delivery.BackoffPolicy != nil { if delivery == nil { - delivery = &eventingduckv1beta1.DeliverySpec{} + delivery = &eventingduckv1.DeliverySpec{} } delivery.BackoffPolicy = channel.Spec.Delivery.BackoffPolicy delivery.Retry = channel.Spec.Delivery.Retry @@ -602,7 +496,7 @@ func deliverySpec(sub *v1.Subscription, channel *eventingduckv1alpha1.Channelabl // 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 { - delivery = &eventingduckv1beta1.DeliverySpec{ + delivery = &eventingduckv1.DeliverySpec{ DeadLetterSink: &duckv1.Destination{ URI: sub.Status.PhysicalSubscription.DeadLetterSinkURI, }, @@ -610,9 +504,9 @@ func deliverySpec(sub *v1.Subscription, channel *eventingduckv1alpha1.Channelabl } if sub.Spec.Delivery != nil && (sub.Spec.Delivery.BackoffDelay != nil || sub.Spec.Delivery.Retry != nil || sub.Spec.Delivery.BackoffPolicy != nil) { if delivery == nil { - delivery = &eventingduckv1beta1.DeliverySpec{} + delivery = &eventingduckv1.DeliverySpec{} } - delivery.BackoffPolicy = (*eventingduckv1beta1.BackoffPolicyType)(sub.Spec.Delivery.BackoffPolicy) + delivery.BackoffPolicy = (*eventingduckv1.BackoffPolicyType)(sub.Spec.Delivery.BackoffPolicy) delivery.Retry = sub.Spec.Delivery.Retry delivery.BackoffDelay = sub.Spec.Delivery.BackoffDelay } diff --git a/pkg/reconciler/subscription/subscription_test.go b/pkg/reconciler/subscription/subscription_test.go index 45dea38368b..b1b96425b54 100644 --- a/pkg/reconciler/subscription/subscription_test.go +++ b/pkg/reconciler/subscription/subscription_test.go @@ -28,6 +28,7 @@ import ( eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" eventingclient "knative.dev/eventing/pkg/client/injection/client" + "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable" corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -46,10 +47,7 @@ import ( "knative.dev/pkg/resolver" eventingduck "knative.dev/eventing/pkg/apis/duck/v1" - eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" 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/v1/subscription" "knative.dev/eventing/pkg/duck" @@ -137,7 +135,6 @@ func init() { // Add types to scheme _ = eventingv1.AddToScheme(scheme.Scheme) _ = duckv1alpha1.AddToScheme(scheme.Scheme) - _ = eventingduckv1alpha1.AddToScheme(scheme.Scheme) _ = apiextensionsv1.AddToScheme(scheme.Scheme) _ = messagingv1.AddToScheme(scheme.Scheme) } @@ -1374,13 +1371,12 @@ func TestAllCases(t *testing.T) { logger := logtesting.TestLogger(t) table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { ctx = channelable.WithDuck(ctx) - ctx = channelablecombined.WithDuck(ctx) ctx = addressable.WithDuck(ctx) r := &Reconciler{ dynamicClientSet: dynamicclient.Get(ctx), subscriptionLister: listers.GetSubscriptionLister(), channelLister: listers.GetMessagingChannelLister(), - channelableTracker: duck.NewListableTracker(ctx, channelablecombined.Get, func(types.NamespacedName) {}, 0), + channelableTracker: duck.NewListableTracker(ctx, channelable.Get, func(types.NamespacedName) {}, 0), destinationResolver: resolver.NewURIResolver(ctx, func(types.NamespacedName) {}), tracker: &FakeTracker{}, } From 615616464fa3bfcfcb33e1256c54e6b7c46f7e87 Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Tue, 2 Mar 2021 15:06:02 -0800 Subject: [PATCH 4/9] remove v1alpha1/ChannelableCombined from Channel --- pkg/reconciler/channel/channel.go | 45 ++--------------------- pkg/reconciler/channel/channel_test.go | 25 +++++-------- pkg/reconciler/channel/controller.go | 4 +- pkg/reconciler/channel/controller_test.go | 2 +- 4 files changed, 17 insertions(+), 59 deletions(-) diff --git a/pkg/reconciler/channel/channel.go b/pkg/reconciler/channel/channel.go index 8f798b95b28..c0107743592 100644 --- a/pkg/reconciler/channel/channel.go +++ b/pkg/reconciler/channel/channel.go @@ -33,8 +33,6 @@ import ( pkgreconciler "knative.dev/pkg/reconciler" eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - "knative.dev/eventing/pkg/apis/messaging" 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" @@ -85,48 +83,13 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, c *v1.Channel) pkgreconc } c.Status.Channel = &backingChannelObjRef - bCS := r.getChannelableStatus(ctx, &backingChannel.Status, backingChannel.Annotations) - c.Status.PropagateStatuses(bCS) + c.Status.PropagateStatuses(&backingChannel.Status) return nil } -func (r *Reconciler) getChannelableStatus(ctx context.Context, bc *duckv1alpha1.ChannelableCombinedStatus, cAnnotations map[string]string) *eventingduckv1.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] == "v1" || cAnnotations[messaging.SubscribableDuckVersionAnnotation] == "v1beta1" { - 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 - } - } 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, - } - } - } - } - return channelableStatus -} - // reconcileBackingChannel reconciles Channel's 'c' underlying CRD channel. -func (r *Reconciler) reconcileBackingChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, c *v1.Channel, backingChannelObjRef duckv1.KReference) (*duckv1alpha1.ChannelableCombined, error) { +func (r *Reconciler) reconcileBackingChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, c *v1.Channel, backingChannelObjRef duckv1.KReference) (*eventingduckv1.Channelable, error) { logger := logging.FromContext(ctx) lister, err := r.channelableTracker.ListerForKReference(backingChannelObjRef) if err != nil { @@ -160,7 +123,7 @@ func (r *Reconciler) reconcileBackingChannel(ctx context.Context, channelResourc return nil, err } logger.Debug("Created backing Channel", zap.Any("backingChannel", newBackingChannel)) - channelable := &duckv1alpha1.ChannelableCombined{} + channelable := &eventingduckv1.Channelable{} err = duckapis.FromUnstructured(created, channelable) if err != nil { logger.Errorw("Failed to convert to Channelable Object", zap.Any("backingChannel", backingChannelObjRef), zap.Any("createdChannel", created), zap.Error(err)) @@ -173,7 +136,7 @@ func (r *Reconciler) reconcileBackingChannel(ctx context.Context, channelResourc return nil, err } logger.Debugw("Found backing Channel", zap.Any("backingChannel", backingChannelObjRef)) - channelable, ok := backingChannel.(*duckv1alpha1.ChannelableCombined) + channelable, ok := backingChannel.(*eventingduckv1.Channelable) if !ok { return nil, fmt.Errorf("Failed to convert to Channelable Object %+v", backingChannel) } diff --git a/pkg/reconciler/channel/channel_test.go b/pkg/reconciler/channel/channel_test.go index 36e9b34690a..98e322cbdd3 100644 --- a/pkg/reconciler/channel/channel_test.go +++ b/pkg/reconciler/channel/channel_test.go @@ -26,6 +26,14 @@ import ( "k8s.io/client-go/kubernetes/scheme" clientgotesting "k8s.io/client-go/testing" "k8s.io/utils/pointer" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" + 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/v1/channelable" + channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/channel" + "knative.dev/eventing/pkg/duck" + . "knative.dev/eventing/pkg/reconciler/testing/v1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/configmap" @@ -34,17 +42,6 @@ import ( logtesting "knative.dev/pkg/logging/testing" "knative.dev/pkg/network" . "knative.dev/pkg/reconciler/testing" - - eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" - v1 "knative.dev/eventing/pkg/apis/duck/v1" - v1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - 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/v1/channel" - "knative.dev/eventing/pkg/duck" - . "knative.dev/eventing/pkg/reconciler/testing/v1" ) const ( @@ -67,8 +64,6 @@ func init() { // 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) } @@ -296,11 +291,11 @@ func TestReconcile(t *testing.T) { logger := logtesting.TestLogger(t) table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { - ctx = channelablecombined.WithDuck(ctx) + ctx = channelable.WithDuck(ctx) r := &Reconciler{ dynamicClientSet: fakedynamicclient.Get(ctx), channelLister: listers.GetMessagingChannelLister(), - channelableTracker: duck.NewListableTracker(ctx, channelablecombined.Get, func(types.NamespacedName) {}, 0), + channelableTracker: duck.NewListableTracker(ctx, channelable.Get, func(types.NamespacedName) {}, 0), } return channelreconciler.NewReconciler(ctx, logger, fakeeventingclient.Get(ctx), listers.GetMessagingChannelLister(), diff --git a/pkg/reconciler/channel/controller.go b/pkg/reconciler/channel/controller.go index 07511f841fa..1cbe9b483b8 100644 --- a/pkg/reconciler/channel/controller.go +++ b/pkg/reconciler/channel/controller.go @@ -24,7 +24,7 @@ import ( "knative.dev/pkg/injection/clients/dynamicclient" "knative.dev/pkg/logging" - "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined" + "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable" 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" @@ -44,7 +44,7 @@ func NewController( } impl := channelreconciler.NewImpl(ctx, r) - r.channelableTracker = duck.NewListableTracker(ctx, channelablecombined.Get, impl.EnqueueKey, controller.GetTrackerLease(ctx)) + r.channelableTracker = duck.NewListableTracker(ctx, channelable.Get, impl.EnqueueKey, controller.GetTrackerLease(ctx)) logging.FromContext(ctx).Info("Setting up event handlers") diff --git a/pkg/reconciler/channel/controller_test.go b/pkg/reconciler/channel/controller_test.go index 3126685a3ee..f33ad1f8f8a 100644 --- a/pkg/reconciler/channel/controller_test.go +++ b/pkg/reconciler/channel/controller_test.go @@ -24,7 +24,7 @@ import ( . "knative.dev/pkg/reconciler/testing" // Fake injection informers - _ "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined/fake" + _ "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable/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" From c0c769e19255d449beb67881802e9e137e1572bb Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Tue, 2 Mar 2021 15:31:18 -0800 Subject: [PATCH 5/9] e2e/conformance tests compile --- hack/update-codegen.sh | 4 +- test/conformance/helpers/channel.go | 19 +---- .../helpers/channel_spec_test_helper.go | 52 ++++--------- .../channel_status_subscriber_test_helper.go | 76 +++++-------------- .../helpers/channel_status_test_helper.go | 55 +++++--------- .../helpers/channel_defaulter_test_helper.go | 6 +- 6 files changed, 57 insertions(+), 155 deletions(-) diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index a97fa5ae8c9..014efe8dd3c 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -51,7 +51,7 @@ ${GOPATH}/bin/deepcopy-gen \ # Only deepcopy the Duck types, as they are not real resources. ${CODEGEN_PKG}/generate-groups.sh "deepcopy" \ knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \ - "duck:v1alpha1 duck:v1beta1 duck:v1" \ + "duck:v1beta1 duck:v1" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt group "Knative Codegen" @@ -59,7 +59,7 @@ group "Knative Codegen" # Knative Injection ${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \ knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \ - "eventing:v1beta1 eventing:v1 messaging:v1beta1 messaging:v1 flows:v1beta1 flows:v1 sources:v1alpha1 sources:v1alpha2 sources:v1beta1 sources:v1beta2 sources:v1 duck:v1alpha1 duck:v1beta1 duck:v1 configs:v1alpha1" \ + "eventing:v1beta1 eventing:v1 messaging:v1beta1 messaging:v1 flows:v1beta1 flows:v1 sources:v1alpha1 sources:v1alpha2 sources:v1beta1 sources:v1beta2 sources:v1 duck:v1beta1 duck:v1 configs:v1alpha1" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt group "Update deps post-codegen" diff --git a/test/conformance/helpers/channel.go b/test/conformance/helpers/channel.go index ec1166a867f..2f0be5eb6be 100644 --- a/test/conformance/helpers/channel.go +++ b/test/conformance/helpers/channel.go @@ -24,7 +24,6 @@ import ( 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" "knative.dev/eventing/pkg/apis/messaging" @@ -50,11 +49,11 @@ var ( func getChannelDuckTypeSupportVersion(channelName string, client *testlib.Client, channel *metav1.TypeMeta) (string, error) { metaResource := resources.NewMetaResource(channelName, client.Namespace, channel) - obj, err := duck.GetGenericObject(client.Dynamic, metaResource, &eventingduckv1beta1.Channelable{}) + obj, err := duck.GetGenericObject(client.Dynamic, metaResource, &eventingduckv1.Channelable{}) if err != nil { return "", errors.Wrapf(err, "Unable to GET the channel %v", metaResource) } - channelable, ok := obj.(*eventingduckv1beta1.Channelable) + channelable, ok := obj.(*eventingduckv1.Channelable) if !ok { return "", errors.Wrapf(err, "Unable to cast the channel %v", metaResource) } @@ -88,17 +87,3 @@ func getChannelAsV1Beta1Channelable(channelName string, client *testlib.Client, return channelable, nil } - -func getChannelAsV1Alpha1Channelable(channelName string, client *testlib.Client, channel metav1.TypeMeta) (*eventingduckv1alpha1.Channelable, error) { - metaResource := resources.NewMetaResource(channelName, client.Namespace, &channel) - obj, err := duck.GetGenericObject(client.Dynamic, metaResource, &eventingduckv1alpha1.Channelable{}) - if err != nil { - return nil, errors.Wrapf(err, "Unable to get the channel as v1alpha1 Channel duck type: %q", channel) - } - channelable, ok := obj.(*eventingduckv1alpha1.Channelable) - if !ok { - return nil, errors.Errorf("Unable to cast channel %q to v1alpha1 duck type", channel) - } - - return channelable, nil -} diff --git a/test/conformance/helpers/channel_spec_test_helper.go b/test/conformance/helpers/channel_spec_test_helper.go index 2c13d15eaf6..f7e19c69a51 100644 --- a/test/conformance/helpers/channel_spec_test_helper.go +++ b/test/conformance/helpers/channel_spec_test_helper.go @@ -28,7 +28,6 @@ import ( "k8s.io/apiserver/pkg/storage/names" "k8s.io/client-go/util/retry" - eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" testlib "knative.dev/eventing/test/lib" "knative.dev/pkg/apis" @@ -61,7 +60,9 @@ func channelSpecAllowsSubscribersArray(st *testing.T, client *testlib.Client, ch if err != nil { st.Fatalf("Unable to check Channel duck type support version for %s: %s", channel, err) } - + if dtsv != "v1" && dtsv != "v1beta1" { + st.Fatalf("Unexpected duck type version, wanted [v1, v1beta] got: %s", dtsv) + } channelName := names.SimpleNameGenerator.GenerateName("channel-spec-subscribers-") client.T.Logf("Creating channel %+v-%s", channel, channelName) client.CreateChannelOrFail(channelName, &channel) @@ -72,44 +73,21 @@ func channelSpecAllowsSubscribersArray(st *testing.T, client *testlib.Client, ch var ch interface{} - if dtsv == "" || dtsv == "v1alpha1" { - // treat missing annotation value as v1alpha1, as written in the spec - channelable, err := getChannelAsV1Alpha1Channelable(channelName, client, channel) - if err != nil { - st.Fatalf("Unable to get channel %s to v1alpha1 duck type: %s", channel, err) - } - - // SPEC: each channel CRD MUST contain an array of subscribers: spec.subscribable.subscribers - channelable.Spec.Subscribable = &eventingduckv1alpha1.Subscribable{ - Subscribers: []eventingduckv1alpha1.SubscriberSpec{ - { - UID: "1234", - ReplyURI: sampleUrl, - }, - }, - } - - ch = channelable - - } else if dtsv == "v1beta1" || dtsv == "v1" { - channelable, err := getChannelAsV1Beta1Channelable(channelName, client, channel) - if err != nil { - st.Fatalf("Unable to get channel %s to v1beta1 duck type: %s", channel, err) - } - - // SPEC: each channel CRD MUST contain an array of subscribers: spec.subscribers - channelable.Spec.Subscribers = []eventingduckv1beta1.SubscriberSpec{ - { - UID: "1234", - ReplyURI: sampleUrl, - }, - } + channelable, err := getChannelAsV1Beta1Channelable(channelName, client, channel) + if err != nil { + st.Fatalf("Unable to get channel %s to v1beta1 duck type: %s", channel, err) + } - ch = channelable - } else { - st.Fatalf("Channel doesn't support v1alpha1 nor v1beta1 Channel duck types: %s", channel) + // SPEC: each channel CRD MUST contain an array of subscribers: spec.subscribers + channelable.Spec.Subscribers = []eventingduckv1beta1.SubscriberSpec{ + { + UID: "1234", + ReplyURI: sampleUrl, + }, } + ch = channelable + raw, err := json.Marshal(ch) if err != nil { st.Fatalf("Error marshaling %s: %s", channel, err) diff --git a/test/conformance/helpers/channel_status_subscriber_test_helper.go b/test/conformance/helpers/channel_status_subscriber_test_helper.go index 4a0c2e79834..e9592f2d8ab 100644 --- a/test/conformance/helpers/channel_status_subscriber_test_helper.go +++ b/test/conformance/helpers/channel_status_subscriber_test_helper.go @@ -76,67 +76,27 @@ func channelHasRequiredSubscriberStatus(ctx context.Context, st *testing.T, clie if err != nil { st.Fatalf("Unable to check Channel duck type support version for %q: %q", channel, err) } + if dtsv != "v1" && dtsv != "v1beta1" { + st.Fatalf("Unexpected duck type version, wanted [v1, v1beta] got: %s", dtsv) + } - if dtsv == "" || dtsv == "v1alpha1" { - // treat missing annotation value as v1alpha1, as written in the spec - channelable, err := getChannelAsV1Alpha1Channelable(channelName, client, channel) - if err != nil { - st.Fatalf("Unable to get channel %q to v1alpha1 duck type: %q", channel, err) - } - - // SPEC: Each subscription to a channel is added to the channel status.subscribableStatus.subscribers automatically. - if channelable.Status.SubscribableStatus == nil || channelable.Status.SubscribableStatus.Subscribers == nil { - st.Fatalf("%q does not have status.subscribers", channel) - } - ss := findSubscriberStatusV1Beta1(channelable.Status.SubscribableStatus.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 == "v1beta1" { - channelable, err := getChannelAsV1Beta1Channelable(channelName, client, channel) - if err != nil { - st.Fatalf("Unable to get channel %q to v1beta1 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 := 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) - } + 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) - } + // 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) + } - // 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 { - st.Fatalf("Channel doesn't support v1alpha1, v1beta1 or v1 Channel duck types: %v", channel) + // 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) } } diff --git a/test/conformance/helpers/channel_status_test_helper.go b/test/conformance/helpers/channel_status_test_helper.go index d3d0bea1130..fe293d82849 100644 --- a/test/conformance/helpers/channel_status_test_helper.go +++ b/test/conformance/helpers/channel_status_test_helper.go @@ -55,44 +55,23 @@ func channelHasRequiredStatus(st *testing.T, client *testlib.Client, channel met if err != nil { st.Fatalf("Unable to check Channel duck type support version for %q: %q", channel, err) } + if dtsv != "v1" && dtsv != "v1beta1" { + st.Fatalf("Unexpected duck type version, wanted [v1, v1beta] got: %s", dtsv) + } + + channelable, err := getChannelAsV1Beta1Channelable(channelName, client, channel) + if err != nil { + st.Fatalf("Unable to get channel %q to v1beta1 duck type: %q", channel, err) + } + + // SPEC: Channel CRD MUST have a status subresource which contains address + if channelable.Status.AddressStatus.Address == nil { + st.Fatalf("%q does not have status.address", channel) + } - if dtsv == "" || dtsv == "v1alpha1" { - // treat missing annotation value as v1alpha1, as written in the spec - channelable, err := getChannelAsV1Alpha1Channelable(channelName, client, channel) - if err != nil { - st.Fatalf("Unable to get channel %q to v1alpha1 duck type: %q", channel, err) - } - - // SPEC: Channel CRD MUST have a status subresource which contains address - if channelable.Status.AddressStatus.Address == nil { - st.Fatalf("%q does not have status.address", channel) - } - - // SPEC: When the channel instance is ready to receive events status.address.hostname and - // status.address.url MUST be populated - if channelable.Status.AddressStatus.Address.Hostname == "" { - st.Fatalf("No hostname found for %q", channel) - } - if channelable.Status.AddressStatus.Address.URL.IsEmpty() { - st.Fatalf("No hostname found for %q", channel) - } - } else if dtsv == "v1beta1" || dtsv == "v1" { - channelable, err := getChannelAsV1Beta1Channelable(channelName, client, channel) - if err != nil { - st.Fatalf("Unable to get channel %q to v1beta1 duck type: %q", channel, err) - } - - // SPEC: Channel CRD MUST have a status subresource which contains address - if channelable.Status.AddressStatus.Address == nil { - st.Fatalf("%q does not have status.address", channel) - } - - // SPEC: When the channel instance is ready to receive events status.address.hostname and - // status.address.url MUST be populated - if channelable.Status.Address.URL.IsEmpty() { - st.Fatalf("No hostname found for %q", channel) - } - } else { - st.Fatalf("Channel doesn't support v1alpha1 nor v1beta1 Channel duck types: %q", channel) + // SPEC: When the channel instance is ready to receive events status.address.hostname and + // status.address.url MUST be populated + if channelable.Status.Address.URL.IsEmpty() { + st.Fatalf("No hostname found for %q", channel) } } diff --git a/test/e2e/helpers/channel_defaulter_test_helper.go b/test/e2e/helpers/channel_defaulter_test_helper.go index 2be4870b36a..abc51b21fbf 100644 --- a/test/e2e/helpers/channel_defaulter_test_helper.go +++ b/test/e2e/helpers/channel_defaulter_test_helper.go @@ -33,7 +33,7 @@ import ( reconciler "knative.dev/pkg/reconciler" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" "knative.dev/eventing/pkg/apis/messaging/config" eventingtesting "knative.dev/eventing/pkg/reconciler/testing/v1beta1" testlib "knative.dev/eventing/test/lib" @@ -119,7 +119,7 @@ func defaultChannelTestHelper(ctx context.Context, t *testing.T, client *testlib // check if the defaultchannel creates exactly one underlying channel given the spec metaResourceList := resources.NewMetaResourceList(client.Namespace, &expectedChannel) - objs, err := duck.GetGenericObjectList(client.Dynamic, metaResourceList, &eventingduck.SubscribableType{}) + objs, err := duck.GetGenericObjectList(client.Dynamic, metaResourceList, &eventingduckv1.Subscribable{}) if err != nil { t.Fatal("Failed to list the underlying channels:", err) } @@ -130,7 +130,7 @@ func defaultChannelTestHelper(ctx context.Context, t *testing.T, client *testlib // So, filter out the broker channel from the list before checking that there's only one. filteredObjs := make([]runtime.Object, 0) for _, o := range objs { - if o.(*eventingduck.SubscribableType).Name != "default-kne-trigger" { + if o.(*eventingduckv1.Subscribable).Name != "default-kne-trigger" { filteredObjs = append(filteredObjs, o) } } From 439424811efb8c1433ac8bf3a5718b99d3dd0ca4 Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Tue, 2 Mar 2021 15:40:51 -0800 Subject: [PATCH 6/9] forgot these --- pkg/reconciler/testing/v1beta1/channelable.go | 49 +++++++------------ pkg/reconciler/testing/v1beta1/listers.go | 2 - 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/pkg/reconciler/testing/v1beta1/channelable.go b/pkg/reconciler/testing/v1beta1/channelable.go index 3eda0f675f4..e4e1858e872 100644 --- a/pkg/reconciler/testing/v1beta1/channelable.go +++ b/pkg/reconciler/testing/v1beta1/channelable.go @@ -20,28 +20,25 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + duckv1 "knative.dev/eventing/pkg/apis/duck/v1" "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 testing that implements a v1alpha1.Channelable type. // ChannelableOption enables further configuration of a v1alpha1.Channelable. -type ChannelableOption func(*v1alpha1.Channelable) +type ChannelableOption func(*duckv1.Channelable) // NewChannelable creates an Channelable with ChannelableOptions. -func NewChannelable(name, namespace string, imcopt ...ChannelableOption) *v1alpha1.Channelable { - c := &v1alpha1.Channelable{ +func NewChannelable(name, namespace string, imcopt ...ChannelableOption) *duckv1.Channelable { + c := &duckv1.Channelable{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, Annotations: map[string]string{messaging.SubscribableDuckVersionAnnotation: "v1alpha1"}, }, - Spec: v1alpha1.ChannelableSpec{}, + Spec: duckv1.ChannelableSpec{}, } for _, opt := range imcopt { opt(c) @@ -50,25 +47,25 @@ func NewChannelable(name, namespace string, imcopt ...ChannelableOption) *v1alph } func WithChannelableGeneration(gen int64) ChannelableOption { - return func(s *v1alpha1.Channelable) { + return func(s *duckv1.Channelable) { s.Generation = gen } } func WithChannelableStatusObservedGeneration(gen int64) ChannelableOption { - return func(s *v1alpha1.Channelable) { + return func(s *duckv1.Channelable) { s.Status.ObservedGeneration = gen } } -func WithChannelableDeleted(imc *v1alpha1.Channelable) { +func WithChannelableDeleted(imc *duckv1.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 WithChannelableSubscribers(subscribers []duckv1.SubscriberSpec) ChannelableOption { + return func(c *duckv1.Channelable) { + c.Spec.Subscribers = append(c.Spec.Subscribers, subscribers...) } } @@ -77,11 +74,8 @@ func WithChannelableReadySubscriber(uid string) ChannelableOption { } 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(duckv1beta1.SubscriberStatus{ + return func(c *duckv1.Channelable) { + c.Status.SubscribableStatus.Subscribers = append(c.Status.SubscribableStatus.Subscribers, duckv1.SubscriberStatus{ UID: types.UID(uid), ObservedGeneration: observedGeneration, Ready: corev1.ConditionTrue, @@ -89,25 +83,20 @@ func WithChannelableReadySubscriberAndGeneration(uid string, observedGeneration } } -func WithChannelableStatusSubscribers(subscriberStatuses []duckv1beta1.SubscriberStatus) ChannelableOption { - return func(c *v1alpha1.Channelable) { - c.Status.SetSubscribableTypeStatus(v1alpha1.SubscribableStatus{ - Subscribers: subscriberStatuses}) +func WithChannelableStatusSubscribers(subscriberStatuses []duckv1.SubscriberStatus) ChannelableOption { + return func(c *duckv1.Channelable) { + c.Status.Subscribers = append(c.Status.Subscribers, subscriberStatuses...) } } func WithChannelableReady() ChannelableOption { - return func(c *v1alpha1.Channelable) { + return func(c *duckv1.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), - }, - } + return func(c *duckv1.Channelable) { + c.Status.AddressStatus.Address.URL = apis.HTTP(a) } } diff --git a/pkg/reconciler/testing/v1beta1/listers.go b/pkg/reconciler/testing/v1beta1/listers.go index da0b0cea48d..978d77af585 100644 --- a/pkg/reconciler/testing/v1beta1/listers.go +++ b/pkg/reconciler/testing/v1beta1/listers.go @@ -32,7 +32,6 @@ import ( rbacv1listers "k8s.io/client-go/listers/rbac/v1" "k8s.io/client-go/tools/cache" configsv1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1" - eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" @@ -67,7 +66,6 @@ var clientSetSchemes = []func(*runtime.Scheme) error{ fakeapiextensionsclientset.AddToScheme, subscriberAddToScheme, sourceAddToScheme, - eventingduckv1alpha1.AddToScheme, } type Listers struct { From 53f6ff847e4c96ec2ae6b8194cd1b3d6734a75dc Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Wed, 3 Mar 2021 08:51:02 -0800 Subject: [PATCH 7/9] remove trailing whitespace --- docs/spec/channel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/spec/channel.md b/docs/spec/channel.md index 20446d841ff..55255d5eab1 100644 --- a/docs/spec/channel.md +++ b/docs/spec/channel.md @@ -382,4 +382,4 @@ following attributes: promoted from `v1alpha1`to `v1beta1`. Add requirement for labeling Custom Objects to indicate which duck type they support as well as document differences. -- `0.22.x release`: Drop support for v1alpha1 channelable. +- `0.22.x release`: Drop support for v1alpha1 channelable. From 61742bcb652248682829c21a99ed8843e6f0a5c1 Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Wed, 3 Mar 2021 15:44:31 -0800 Subject: [PATCH 8/9] address lint errors --- pkg/reconciler/subscription/subscription.go | 4 ++-- .../helpers/channel_status_subscriber_test_helper.go | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/pkg/reconciler/subscription/subscription.go b/pkg/reconciler/subscription/subscription.go index 95e55bd26b0..a657c2207cc 100644 --- a/pkg/reconciler/subscription/subscription.go +++ b/pkg/reconciler/subscription/subscription.go @@ -130,7 +130,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, subscription *v1.Subscrip } func (r Reconciler) checkChannelStatusForSubscription(ctx context.Context, channel *eventingduckv1.Channelable, sub *v1.Subscription) pkgreconciler.Event { - ss, err := r.getSubStatus(ctx, sub, channel) + ss, err := r.getSubStatus(sub, channel) if err != nil { logging.FromContext(ctx).Warnw("Failed to get subscription status.", zap.Error(err)) sub.Status.MarkChannelUnknown(subscriptionNotMarkedReadyByChannel, "Failed to get subscription status: %s", err) @@ -278,7 +278,7 @@ func (r *Reconciler) resolveDeadLetterSink(ctx context.Context, deadLetterSink * return nil } -func (r *Reconciler) getSubStatus(ctx context.Context, subscription *v1.Subscription, channel *eventingduckv1.Channelable) (eventingduckv1.SubscriberStatus, error) { +func (r *Reconciler) getSubStatus(subscription *v1.Subscription, channel *eventingduckv1.Channelable) (eventingduckv1.SubscriberStatus, error) { for _, sub := range channel.Status.Subscribers { if sub.UID == subscription.GetUID() && sub.ObservedGeneration == subscription.GetGeneration() { diff --git a/test/conformance/helpers/channel_status_subscriber_test_helper.go b/test/conformance/helpers/channel_status_subscriber_test_helper.go index e9592f2d8ab..db1f3467094 100644 --- a/test/conformance/helpers/channel_status_subscriber_test_helper.go +++ b/test/conformance/helpers/channel_status_subscriber_test_helper.go @@ -21,7 +21,6 @@ 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" "knative.dev/eventing/test/lib/recordevents" @@ -100,15 +99,6 @@ func channelHasRequiredSubscriberStatus(ctx context.Context, st *testing.T, clie } } -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 { From 829467fb3882088d2915c119a8d5833fa2640678 Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Wed, 3 Mar 2021 21:09:44 -0800 Subject: [PATCH 9/9] fix the unnecessary conversion --- pkg/reconciler/subscription/subscription.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/reconciler/subscription/subscription.go b/pkg/reconciler/subscription/subscription.go index a657c2207cc..3c2a8c018f3 100644 --- a/pkg/reconciler/subscription/subscription.go +++ b/pkg/reconciler/subscription/subscription.go @@ -506,7 +506,7 @@ func deliverySpec(sub *v1.Subscription, channel *eventingduckv1.Channelable) (de if delivery == nil { delivery = &eventingduckv1.DeliverySpec{} } - delivery.BackoffPolicy = (*eventingduckv1.BackoffPolicyType)(sub.Spec.Delivery.BackoffPolicy) + delivery.BackoffPolicy = sub.Spec.Delivery.BackoffPolicy delivery.Retry = sub.Spec.Delivery.Retry delivery.BackoffDelay = sub.Spec.Delivery.BackoffDelay }