diff --git a/go.mod b/go.mod index f5340424006..4f5f0ee2fbf 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( k8s.io/apimachinery v0.16.5-beta.1 k8s.io/apiserver v0.16.4 k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible - k8s.io/kubernetes v1.14.7 + k8s.io/kubernetes v1.14.7 // indirect k8s.io/utils v0.0.0-20191010214722-8d271d903fe4 knative.dev/pkg v0.0.0-20200501005942-d980c0865972 knative.dev/test-infra v0.0.0-20200430225942-f7c1fafc1cde diff --git a/pkg/apis/flows/v1alpha1/parallel_types.go b/pkg/apis/flows/v1alpha1/parallel_types.go index dc00c3cc75c..b5c50349a6c 100644 --- a/pkg/apis/flows/v1alpha1/parallel_types.go +++ b/pkg/apis/flows/v1alpha1/parallel_types.go @@ -29,7 +29,6 @@ import ( ) // +genclient -// +genreconciler // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // Parallel defines conditional branches that will be wired in // series through Channels and Subscriptions. diff --git a/pkg/apis/flows/v1alpha1/sequence_types.go b/pkg/apis/flows/v1alpha1/sequence_types.go index 0f797cf9d95..2b100ce285f 100644 --- a/pkg/apis/flows/v1alpha1/sequence_types.go +++ b/pkg/apis/flows/v1alpha1/sequence_types.go @@ -30,7 +30,6 @@ import ( ) // +genclient -// +genreconciler // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // Sequence defines a sequence of Subscribers that will be wired in // series through Channels and Subscriptions. diff --git a/pkg/apis/flows/v1beta1/parallel_types.go b/pkg/apis/flows/v1beta1/parallel_types.go index 510a2397d37..0c818c84e40 100644 --- a/pkg/apis/flows/v1beta1/parallel_types.go +++ b/pkg/apis/flows/v1beta1/parallel_types.go @@ -28,6 +28,7 @@ import ( ) // +genclient +// +genreconciler // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // Parallel defines conditional branches that will be wired in // series through Channels and Subscriptions. diff --git a/pkg/apis/flows/v1beta1/sequence_lifecycle.go b/pkg/apis/flows/v1beta1/sequence_lifecycle.go index 9c0a9010614..4c9beb7f270 100644 --- a/pkg/apis/flows/v1beta1/sequence_lifecycle.go +++ b/pkg/apis/flows/v1beta1/sequence_lifecycle.go @@ -19,10 +19,10 @@ package v1beta1 import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime/schema" - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/pkg/apis" - pkgduckv1 "knative.dev/pkg/apis/duck/v1" + duckv1 "knative.dev/pkg/apis/duck/v1" ) var pCondSet = apis.NewLivingConditionSet(SequenceConditionReady, SequenceConditionChannelsReady, SequenceConditionSubscriptionsReady, SequenceConditionAddressable) @@ -108,7 +108,7 @@ func (ss *SequenceStatus) PropagateSubscriptionStatuses(subscriptions []*messagi // PropagateChannelStatuses sets the ChannelStatuses and SequenceConditionChannelsReady based on the // status of the incoming channels. -func (ss *SequenceStatus) PropagateChannelStatuses(channels []*duckv1beta1.Channelable) { +func (ss *SequenceStatus) PropagateChannelStatuses(channels []*eventingduckv1beta1.Channelable) { ss.ChannelStatuses = make([]SequenceChannelStatus, len(channels)) allReady := true // If there are no channels, treat that as a False case. Could go either way, but this seems right. @@ -159,11 +159,11 @@ func (ss *SequenceStatus) MarkAddressableNotReady(reason, messageFormat string, pCondSet.Manage(ss).MarkFalse(SequenceConditionAddressable, reason, messageFormat, messageA...) } -func (ss *SequenceStatus) setAddress(address *pkgduckv1.Addressable) { - ss.Address = address - if address == nil { +func (ss *SequenceStatus) setAddress(address *duckv1.Addressable) { + if address == nil || address.URL == nil { pCondSet.Manage(ss).MarkFalse(SequenceConditionAddressable, "emptyAddress", "addressable is nil") } else { + ss.AddressStatus.Address = &duckv1.Addressable{URL: address.URL} pCondSet.Manage(ss).MarkTrue(SequenceConditionAddressable) } } diff --git a/pkg/apis/flows/v1beta1/sequence_lifecycle_test.go b/pkg/apis/flows/v1beta1/sequence_lifecycle_test.go new file mode 100644 index 00000000000..f23e489a7fa --- /dev/null +++ b/pkg/apis/flows/v1beta1/sequence_lifecycle_test.go @@ -0,0 +1,396 @@ +/* +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 v1beta1 + +import ( + "testing" + + "knative.dev/pkg/apis" + + "github.com/google/go-cmp/cmp" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" + duckv1 "knative.dev/pkg/apis/duck/v1" + pkgduckv1 "knative.dev/pkg/apis/duck/v1" + + eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" +) + +var sequenceConditionReady = apis.Condition{ + Type: SequenceConditionReady, + Status: corev1.ConditionTrue, +} + +func getSubscription(name string, ready bool) *messagingv1beta1.Subscription { + s := messagingv1beta1.Subscription{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "eventing.knative.dev/v1alpha1", + Kind: "Subscription", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: "testns", + }, + Status: messagingv1beta1.SubscriptionStatus{}, + } + if ready { + s.Status.MarkChannelReady() + s.Status.MarkReferencesResolved() + s.Status.MarkAddedToChannel() + } else { + s.Status.MarkChannelFailed("testInducedFailure", "Test Induced failure") + s.Status.MarkReferencesNotResolved("testInducedFailure", "Test Induced failure") + s.Status.MarkNotAddedToChannel("testInducedfailure", "Test Induced failure") + } + return &s +} + +func getChannelable(ready bool) *eventingduckv1beta1.Channelable { + URL, _ := apis.ParseURL("http://example.com") + c := eventingduckv1beta1.Channelable{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "messaging.knative.dev/v1alpha1", + Kind: "InMemoryChannel", + }, + ObjectMeta: metav1.ObjectMeta{}, + Status: eventingduckv1beta1.ChannelableStatus{}, + } + + if ready { + c.Status.Address = &duckv1.Addressable{URL: URL} + } + + return &c +} + +func TestSequenceGetCondition(t *testing.T) { + tests := []struct { + name string + ss *SequenceStatus + condQuery apis.ConditionType + want *apis.Condition + }{{ + name: "single condition", + ss: &SequenceStatus{ + Status: duckv1.Status{ + Conditions: []apis.Condition{ + sequenceConditionReady, + }, + }, + }, + condQuery: apis.ConditionReady, + want: &sequenceConditionReady, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.ss.GetCondition(test.condQuery) + if diff := cmp.Diff(test.want, got); diff != "" { + t.Errorf("unexpected condition (-want, +got) = %v", diff) + } + }) + } +} + +func TestSequenceInitializeConditions(t *testing.T) { + tests := []struct { + name string + ts *SequenceStatus + want *SequenceStatus + }{{ + name: "empty", + ts: &SequenceStatus{}, + want: &SequenceStatus{ + Status: duckv1.Status{ + Conditions: []apis.Condition{{ + Type: SequenceConditionAddressable, + Status: corev1.ConditionUnknown, + }, { + Type: SequenceConditionChannelsReady, + Status: corev1.ConditionUnknown, + }, { + Type: SequenceConditionReady, + Status: corev1.ConditionUnknown, + }, { + Type: SequenceConditionSubscriptionsReady, + Status: corev1.ConditionUnknown, + }}, + }, + }, + }, { + name: "one false", + ts: &SequenceStatus{ + Status: duckv1.Status{ + Conditions: []apis.Condition{{ + Type: SequenceConditionChannelsReady, + Status: corev1.ConditionFalse, + }}, + }, + }, + want: &SequenceStatus{ + Status: duckv1.Status{ + Conditions: []apis.Condition{{ + Type: SequenceConditionAddressable, + Status: corev1.ConditionUnknown, + }, { + Type: SequenceConditionChannelsReady, + Status: corev1.ConditionFalse, + }, { + Type: SequenceConditionReady, + Status: corev1.ConditionUnknown, + }, { + Type: SequenceConditionSubscriptionsReady, + Status: corev1.ConditionUnknown, + }}, + }, + }, + }, { + name: "one true", + ts: &SequenceStatus{ + Status: duckv1.Status{ + Conditions: []apis.Condition{{ + Type: SequenceConditionSubscriptionsReady, + Status: corev1.ConditionTrue, + }}, + }, + }, + want: &SequenceStatus{ + Status: duckv1.Status{ + Conditions: []apis.Condition{{ + Type: SequenceConditionAddressable, + Status: corev1.ConditionUnknown, + }, { + Type: SequenceConditionChannelsReady, + Status: corev1.ConditionUnknown, + }, { + Type: SequenceConditionReady, + Status: corev1.ConditionUnknown, + }, { + Type: SequenceConditionSubscriptionsReady, + Status: corev1.ConditionTrue, + }}, + }, + }, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + test.ts.InitializeConditions() + if diff := cmp.Diff(test.want, test.ts, ignoreAllButTypeAndStatus); diff != "" { + t.Errorf("unexpected conditions (-want, +got) = %v", diff) + } + }) + } +} + +func TestSequencePropagateSubscriptionStatuses(t *testing.T) { + tests := []struct { + name string + subs []*messagingv1beta1.Subscription + want corev1.ConditionStatus + }{{ + name: "empty", + subs: []*messagingv1beta1.Subscription{}, + want: corev1.ConditionFalse, + }, { + name: "empty status", + subs: []*messagingv1beta1.Subscription{{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "eventing.knative.dev/v1alpha1", + Kind: "Subscription", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "sub", + Namespace: "testns", + }, + Status: messagingv1beta1.SubscriptionStatus{}, + }, + }, + want: corev1.ConditionFalse, + }, { + name: "one subscription not ready", + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", false)}, + want: corev1.ConditionFalse, + }, { + name: "one subscription ready", + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", true)}, + want: corev1.ConditionTrue, + }, { + name: "one subscription ready, one not", + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", true), getSubscription("sub1", false)}, + want: corev1.ConditionFalse, + }, { + name: "two subscriptions ready", + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", true), getSubscription("sub1", true)}, + want: corev1.ConditionTrue, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + ps := SequenceStatus{} + ps.PropagateSubscriptionStatuses(test.subs) + got := ps.GetCondition(SequenceConditionSubscriptionsReady).Status + want := test.want + if want != got { + t.Errorf("unexpected conditions (-want, +got) = %v %v", want, got) + } + }) + } +} + +func TestSequencePropagateChannelStatuses(t *testing.T) { + tests := []struct { + name string + channels []*eventingduckv1beta1.Channelable + want corev1.ConditionStatus + }{{ + name: "empty", + channels: []*eventingduckv1beta1.Channelable{}, + want: corev1.ConditionFalse, + }, { + name: "one channelable not ready", + channels: []*eventingduckv1beta1.Channelable{getChannelable(false)}, + want: corev1.ConditionFalse, + }, { + name: "one channelable ready", + channels: []*eventingduckv1beta1.Channelable{getChannelable(true)}, + want: corev1.ConditionTrue, + }, { + name: "one channelable ready, one not", + channels: []*eventingduckv1beta1.Channelable{getChannelable(true), getChannelable(false)}, + want: corev1.ConditionFalse, + }, { + name: "two channelables ready", + channels: []*eventingduckv1beta1.Channelable{getChannelable(true), getChannelable(true)}, + want: corev1.ConditionTrue, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + ps := SequenceStatus{} + ps.PropagateChannelStatuses(test.channels) + got := ps.GetCondition(SequenceConditionChannelsReady).Status + want := test.want + if want != got { + t.Errorf("unexpected conditions (-want, +got) = %v %v", want, got) + } + }) + } +} + +func TestSequenceReady(t *testing.T) { + tests := []struct { + name string + subs []*messagingv1beta1.Subscription + channels []*eventingduckv1beta1.Channelable + want bool + }{{ + name: "empty", + subs: []*messagingv1beta1.Subscription{}, + channels: []*eventingduckv1beta1.Channelable{}, + want: false, + }, { + name: "one channelable not ready, one subscription ready", + channels: []*eventingduckv1beta1.Channelable{getChannelable(false)}, + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", true)}, + want: false, + }, { + name: "one channelable ready, one subscription not ready", + channels: []*eventingduckv1beta1.Channelable{getChannelable(true)}, + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", false)}, + want: false, + }, { + name: "one channelable ready, one subscription ready", + channels: []*eventingduckv1beta1.Channelable{getChannelable(true)}, + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", true)}, + want: true, + }, { + name: "one channelable ready, one not, two subsriptions ready", + channels: []*eventingduckv1beta1.Channelable{getChannelable(true), getChannelable(false)}, + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", true), getSubscription("sub1", true)}, + want: false, + }, { + name: "two channelables ready, one subscription ready, one not", + channels: []*eventingduckv1beta1.Channelable{getChannelable(true), getChannelable(true)}, + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", true), getSubscription("sub1", false)}, + want: false, + }, { + name: "two channelables ready, two subscriptions ready", + channels: []*eventingduckv1beta1.Channelable{getChannelable(true), getChannelable(true)}, + subs: []*messagingv1beta1.Subscription{getSubscription("sub0", true), getSubscription("sub1", true)}, + want: true, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + ps := SequenceStatus{} + ps.PropagateChannelStatuses(test.channels) + ps.PropagateSubscriptionStatuses(test.subs) + got := ps.IsReady() + want := test.want + if want != got { + t.Errorf("unexpected conditions (-want, +got) = %v %v", want, got) + } + }) + } +} + +func TestSequencePropagateSetAddress(t *testing.T) { + URL, _ := apis.ParseURL("http://example.com") + tests := []struct { + name string + address *duckv1.Addressable + want *pkgduckv1.Addressable + wantStatus corev1.ConditionStatus + }{{ + name: "nil", + address: nil, + want: nil, + wantStatus: corev1.ConditionFalse, + }, { + name: "empty", + address: &duckv1.Addressable{}, + want: nil, + wantStatus: corev1.ConditionFalse, + }, { + name: "URL", + address: &duckv1.Addressable{URL: URL}, + want: &pkgduckv1.Addressable{URL: URL}, + wantStatus: corev1.ConditionTrue, + }, { + name: "nil", + address: &duckv1.Addressable{URL: nil}, + want: nil, + wantStatus: corev1.ConditionFalse, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + ps := SequenceStatus{} + ps.setAddress(test.address) + got := ps.Address + if diff := cmp.Diff(test.want, got, ignoreAllButTypeAndStatus); diff != "" { + t.Errorf("unexpected address (-want, +got) = %v", diff) + } + gotStatus := ps.GetCondition(SequenceConditionAddressable).Status + if test.wantStatus != gotStatus { + t.Errorf("unexpected conditions (-want, +got) = %v %v", test.wantStatus, gotStatus) + } + }) + } +} diff --git a/pkg/apis/flows/v1beta1/sequence_types.go b/pkg/apis/flows/v1beta1/sequence_types.go index 75e52f193a0..ebec9dce675 100644 --- a/pkg/apis/flows/v1beta1/sequence_types.go +++ b/pkg/apis/flows/v1beta1/sequence_types.go @@ -29,6 +29,7 @@ import ( ) // +genclient +// +genreconciler // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // Sequence defines a sequence of Subscribers that will be wired in // series through Channels and Subscriptions. diff --git a/pkg/apis/flows/v1beta1/test_helpers.go b/pkg/apis/flows/v1beta1/test_helpers.go index b33871177e5..1021566e2d9 100644 --- a/pkg/apis/flows/v1beta1/test_helpers.go +++ b/pkg/apis/flows/v1beta1/test_helpers.go @@ -17,9 +17,11 @@ package v1beta1 import ( + "github.com/google/go-cmp/cmp/cmpopts" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" + "knative.dev/pkg/apis" ) var ( @@ -29,4 +31,7 @@ var ( Kind: "InMemoryChannel", }, } + ignoreAllButTypeAndStatus = cmpopts.IgnoreFields( + apis.Condition{}, + "LastTransitionTime", "Message", "Reason", "Severity") ) diff --git a/pkg/client/injection/reconciler/flows/v1alpha1/parallel/controller.go b/pkg/client/injection/reconciler/flows/v1beta1/parallel/controller.go similarity index 99% rename from pkg/client/injection/reconciler/flows/v1alpha1/parallel/controller.go rename to pkg/client/injection/reconciler/flows/v1beta1/parallel/controller.go index d4d0b749dc9..a016daebe26 100644 --- a/pkg/client/injection/reconciler/flows/v1alpha1/parallel/controller.go +++ b/pkg/client/injection/reconciler/flows/v1beta1/parallel/controller.go @@ -31,7 +31,7 @@ import ( record "k8s.io/client-go/tools/record" versionedscheme "knative.dev/eventing/pkg/client/clientset/versioned/scheme" injectionclient "knative.dev/eventing/pkg/client/injection/client" - parallel "knative.dev/eventing/pkg/client/injection/informers/flows/v1alpha1/parallel" + parallel "knative.dev/eventing/pkg/client/injection/informers/flows/v1beta1/parallel" client "knative.dev/pkg/client/injection/kube/client" controller "knative.dev/pkg/controller" logging "knative.dev/pkg/logging" diff --git a/pkg/client/injection/reconciler/flows/v1alpha1/parallel/reconciler.go b/pkg/client/injection/reconciler/flows/v1beta1/parallel/reconciler.go similarity index 88% rename from pkg/client/injection/reconciler/flows/v1alpha1/parallel/reconciler.go rename to pkg/client/injection/reconciler/flows/v1beta1/parallel/reconciler.go index 405a576053b..7a7c6f7329f 100644 --- a/pkg/client/injection/reconciler/flows/v1alpha1/parallel/reconciler.go +++ b/pkg/client/injection/reconciler/flows/v1beta1/parallel/reconciler.go @@ -32,44 +32,44 @@ import ( sets "k8s.io/apimachinery/pkg/util/sets" cache "k8s.io/client-go/tools/cache" record "k8s.io/client-go/tools/record" - v1alpha1 "knative.dev/eventing/pkg/apis/flows/v1alpha1" + v1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" versioned "knative.dev/eventing/pkg/client/clientset/versioned" - flowsv1alpha1 "knative.dev/eventing/pkg/client/listers/flows/v1alpha1" + flowsv1beta1 "knative.dev/eventing/pkg/client/listers/flows/v1beta1" controller "knative.dev/pkg/controller" logging "knative.dev/pkg/logging" reconciler "knative.dev/pkg/reconciler" ) // Interface defines the strongly typed interfaces to be implemented by a -// controller reconciling v1alpha1.Parallel. +// controller reconciling v1beta1.Parallel. type Interface interface { - // ReconcileKind implements custom logic to reconcile v1alpha1.Parallel. Any changes + // ReconcileKind implements custom logic to reconcile v1beta1.Parallel. Any changes // to the objects .Status or .Finalizers will be propagated to the stored // object. It is recommended that implementors do not call any update calls // for the Kind inside of ReconcileKind, it is the responsibility of the calling // controller to propagate those properties. The resource passed to ReconcileKind // will always have an empty deletion timestamp. - ReconcileKind(ctx context.Context, o *v1alpha1.Parallel) reconciler.Event + ReconcileKind(ctx context.Context, o *v1beta1.Parallel) reconciler.Event } // Finalizer defines the strongly typed interfaces to be implemented by a -// controller finalizing v1alpha1.Parallel. +// controller finalizing v1beta1.Parallel. type Finalizer interface { - // FinalizeKind implements custom logic to finalize v1alpha1.Parallel. Any changes + // FinalizeKind implements custom logic to finalize v1beta1.Parallel. Any changes // to the objects .Status or .Finalizers will be ignored. Returning a nil or // Normal type reconciler.Event will allow the finalizer to be deleted on // the resource. The resource passed to FinalizeKind will always have a set // deletion timestamp. - FinalizeKind(ctx context.Context, o *v1alpha1.Parallel) reconciler.Event + FinalizeKind(ctx context.Context, o *v1beta1.Parallel) reconciler.Event } -// reconcilerImpl implements controller.Reconciler for v1alpha1.Parallel resources. +// reconcilerImpl implements controller.Reconciler for v1beta1.Parallel resources. type reconcilerImpl struct { // Client is used to write back status updates. Client versioned.Interface // Listers index properties about resources - Lister flowsv1alpha1.ParallelLister + Lister flowsv1beta1.ParallelLister // Recorder is an event recorder for recording Event resources to the // Kubernetes API. @@ -89,7 +89,7 @@ type reconcilerImpl struct { // Check that our Reconciler implements controller.Reconciler var _ controller.Reconciler = (*reconcilerImpl)(nil) -func NewReconciler(ctx context.Context, logger *zap.SugaredLogger, client versioned.Interface, lister flowsv1alpha1.ParallelLister, recorder record.EventRecorder, r Interface, options ...controller.Options) controller.Reconciler { +func NewReconciler(ctx context.Context, logger *zap.SugaredLogger, client versioned.Interface, lister flowsv1beta1.ParallelLister, recorder record.EventRecorder, r Interface, options ...controller.Options) controller.Reconciler { // Check the options function input. It should be 0 or 1. if len(options) > 1 { logger.Fatalf("up to one options struct is supported, found %d", len(options)) @@ -208,13 +208,13 @@ func (r *reconcilerImpl) Reconcile(ctx context.Context, key string) error { return nil } -func (r *reconcilerImpl) updateStatus(existing *v1alpha1.Parallel, desired *v1alpha1.Parallel) error { +func (r *reconcilerImpl) updateStatus(existing *v1beta1.Parallel, desired *v1beta1.Parallel) error { existing = existing.DeepCopy() return reconciler.RetryUpdateConflicts(func(attempts int) (err error) { // The first iteration tries to use the injectionInformer's state, subsequent attempts fetch the latest state via API. if attempts > 0 { - getter := r.Client.FlowsV1alpha1().Parallels(desired.Namespace) + getter := r.Client.FlowsV1beta1().Parallels(desired.Namespace) existing, err = getter.Get(desired.Name, metav1.GetOptions{}) if err != nil { @@ -229,7 +229,7 @@ func (r *reconcilerImpl) updateStatus(existing *v1alpha1.Parallel, desired *v1al existing.Status = desired.Status - updater := r.Client.FlowsV1alpha1().Parallels(existing.Namespace) + updater := r.Client.FlowsV1beta1().Parallels(existing.Namespace) _, err = updater.UpdateStatus(existing) return err @@ -239,7 +239,7 @@ func (r *reconcilerImpl) updateStatus(existing *v1alpha1.Parallel, desired *v1al // updateFinalizersFiltered will update the Finalizers of the resource. // TODO: this method could be generic and sync all finalizers. For now it only // updates defaultFinalizerName or its override. -func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource *v1alpha1.Parallel) (*v1alpha1.Parallel, error) { +func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource *v1beta1.Parallel) (*v1beta1.Parallel, error) { getter := r.Lister.Parallels(resource.Namespace) @@ -286,7 +286,7 @@ func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource return resource, err } - patcher := r.Client.FlowsV1alpha1().Parallels(resource.Namespace) + patcher := r.Client.FlowsV1beta1().Parallels(resource.Namespace) resource, err = patcher.Patch(resource.Name, types.MergePatchType, patch) if err != nil { @@ -299,7 +299,7 @@ func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource return resource, err } -func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource *v1alpha1.Parallel) (*v1alpha1.Parallel, error) { +func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource *v1beta1.Parallel) (*v1beta1.Parallel, error) { if _, ok := r.reconciler.(Finalizer); !ok { return resource, nil } @@ -317,7 +317,7 @@ func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource * return r.updateFinalizersFiltered(ctx, resource) } -func (r *reconcilerImpl) clearFinalizer(ctx context.Context, resource *v1alpha1.Parallel, reconcileEvent reconciler.Event) (*v1alpha1.Parallel, error) { +func (r *reconcilerImpl) clearFinalizer(ctx context.Context, resource *v1beta1.Parallel, reconcileEvent reconciler.Event) (*v1beta1.Parallel, error) { if _, ok := r.reconciler.(Finalizer); !ok { return resource, nil } diff --git a/pkg/client/injection/reconciler/flows/v1alpha1/parallel/stub/controller.go b/pkg/client/injection/reconciler/flows/v1beta1/parallel/stub/controller.go similarity index 89% rename from pkg/client/injection/reconciler/flows/v1alpha1/parallel/stub/controller.go rename to pkg/client/injection/reconciler/flows/v1beta1/parallel/stub/controller.go index a11bfd5909a..ec7832db8ff 100644 --- a/pkg/client/injection/reconciler/flows/v1alpha1/parallel/stub/controller.go +++ b/pkg/client/injection/reconciler/flows/v1beta1/parallel/stub/controller.go @@ -21,8 +21,8 @@ package parallel import ( context "context" - parallel "knative.dev/eventing/pkg/client/injection/informers/flows/v1alpha1/parallel" - v1alpha1parallel "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/parallel" + parallel "knative.dev/eventing/pkg/client/injection/informers/flows/v1beta1/parallel" + v1beta1parallel "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/parallel" configmap "knative.dev/pkg/configmap" controller "knative.dev/pkg/controller" logging "knative.dev/pkg/logging" @@ -42,7 +42,7 @@ func NewController( // TODO: setup additional informers here. r := &Reconciler{} - impl := v1alpha1parallel.NewImpl(ctx, r) + impl := v1beta1parallel.NewImpl(ctx, r) logger.Info("Setting up event handlers.") diff --git a/pkg/client/injection/reconciler/flows/v1alpha1/parallel/stub/reconciler.go b/pkg/client/injection/reconciler/flows/v1beta1/parallel/stub/reconciler.go similarity index 88% rename from pkg/client/injection/reconciler/flows/v1alpha1/parallel/stub/reconciler.go rename to pkg/client/injection/reconciler/flows/v1beta1/parallel/stub/reconciler.go index cb69fd01888..7610b7ef32a 100644 --- a/pkg/client/injection/reconciler/flows/v1alpha1/parallel/stub/reconciler.go +++ b/pkg/client/injection/reconciler/flows/v1beta1/parallel/stub/reconciler.go @@ -22,8 +22,8 @@ import ( context "context" v1 "k8s.io/api/core/v1" - v1alpha1 "knative.dev/eventing/pkg/apis/flows/v1alpha1" - parallel "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/parallel" + v1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" + parallel "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/parallel" reconciler "knative.dev/pkg/reconciler" ) @@ -47,7 +47,7 @@ var _ parallel.Interface = (*Reconciler)(nil) //var _ parallel.Finalizer = (*Reconciler)(nil) // ReconcileKind implements Interface.ReconcileKind. -func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1alpha1.Parallel) reconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1beta1.Parallel) reconciler.Event { // TODO: use this if the resource implements InitializeConditions. // o.Status.InitializeConditions() @@ -60,7 +60,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1alpha1.Parallel) re // Optionally, use FinalizeKind to add finalizers. FinalizeKind will be called // when the resource is deleted. -//func (r *Reconciler) FinalizeKind(ctx context.Context, o *v1alpha1.Parallel) reconciler.Event { +//func (r *Reconciler) FinalizeKind(ctx context.Context, o *v1beta1.Parallel) reconciler.Event { // // TODO: add custom finalization logic here. // return nil //} diff --git a/pkg/client/injection/reconciler/flows/v1alpha1/sequence/controller.go b/pkg/client/injection/reconciler/flows/v1beta1/sequence/controller.go similarity index 99% rename from pkg/client/injection/reconciler/flows/v1alpha1/sequence/controller.go rename to pkg/client/injection/reconciler/flows/v1beta1/sequence/controller.go index 9bde006098f..58e890035ac 100644 --- a/pkg/client/injection/reconciler/flows/v1alpha1/sequence/controller.go +++ b/pkg/client/injection/reconciler/flows/v1beta1/sequence/controller.go @@ -31,7 +31,7 @@ import ( record "k8s.io/client-go/tools/record" versionedscheme "knative.dev/eventing/pkg/client/clientset/versioned/scheme" injectionclient "knative.dev/eventing/pkg/client/injection/client" - sequence "knative.dev/eventing/pkg/client/injection/informers/flows/v1alpha1/sequence" + sequence "knative.dev/eventing/pkg/client/injection/informers/flows/v1beta1/sequence" client "knative.dev/pkg/client/injection/kube/client" controller "knative.dev/pkg/controller" logging "knative.dev/pkg/logging" diff --git a/pkg/client/injection/reconciler/flows/v1alpha1/sequence/reconciler.go b/pkg/client/injection/reconciler/flows/v1beta1/sequence/reconciler.go similarity index 88% rename from pkg/client/injection/reconciler/flows/v1alpha1/sequence/reconciler.go rename to pkg/client/injection/reconciler/flows/v1beta1/sequence/reconciler.go index b05883475b0..6e24dba7d8a 100644 --- a/pkg/client/injection/reconciler/flows/v1alpha1/sequence/reconciler.go +++ b/pkg/client/injection/reconciler/flows/v1beta1/sequence/reconciler.go @@ -32,44 +32,44 @@ import ( sets "k8s.io/apimachinery/pkg/util/sets" cache "k8s.io/client-go/tools/cache" record "k8s.io/client-go/tools/record" - v1alpha1 "knative.dev/eventing/pkg/apis/flows/v1alpha1" + v1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" versioned "knative.dev/eventing/pkg/client/clientset/versioned" - flowsv1alpha1 "knative.dev/eventing/pkg/client/listers/flows/v1alpha1" + flowsv1beta1 "knative.dev/eventing/pkg/client/listers/flows/v1beta1" controller "knative.dev/pkg/controller" logging "knative.dev/pkg/logging" reconciler "knative.dev/pkg/reconciler" ) // Interface defines the strongly typed interfaces to be implemented by a -// controller reconciling v1alpha1.Sequence. +// controller reconciling v1beta1.Sequence. type Interface interface { - // ReconcileKind implements custom logic to reconcile v1alpha1.Sequence. Any changes + // ReconcileKind implements custom logic to reconcile v1beta1.Sequence. Any changes // to the objects .Status or .Finalizers will be propagated to the stored // object. It is recommended that implementors do not call any update calls // for the Kind inside of ReconcileKind, it is the responsibility of the calling // controller to propagate those properties. The resource passed to ReconcileKind // will always have an empty deletion timestamp. - ReconcileKind(ctx context.Context, o *v1alpha1.Sequence) reconciler.Event + ReconcileKind(ctx context.Context, o *v1beta1.Sequence) reconciler.Event } // Finalizer defines the strongly typed interfaces to be implemented by a -// controller finalizing v1alpha1.Sequence. +// controller finalizing v1beta1.Sequence. type Finalizer interface { - // FinalizeKind implements custom logic to finalize v1alpha1.Sequence. Any changes + // FinalizeKind implements custom logic to finalize v1beta1.Sequence. Any changes // to the objects .Status or .Finalizers will be ignored. Returning a nil or // Normal type reconciler.Event will allow the finalizer to be deleted on // the resource. The resource passed to FinalizeKind will always have a set // deletion timestamp. - FinalizeKind(ctx context.Context, o *v1alpha1.Sequence) reconciler.Event + FinalizeKind(ctx context.Context, o *v1beta1.Sequence) reconciler.Event } -// reconcilerImpl implements controller.Reconciler for v1alpha1.Sequence resources. +// reconcilerImpl implements controller.Reconciler for v1beta1.Sequence resources. type reconcilerImpl struct { // Client is used to write back status updates. Client versioned.Interface // Listers index properties about resources - Lister flowsv1alpha1.SequenceLister + Lister flowsv1beta1.SequenceLister // Recorder is an event recorder for recording Event resources to the // Kubernetes API. @@ -89,7 +89,7 @@ type reconcilerImpl struct { // Check that our Reconciler implements controller.Reconciler var _ controller.Reconciler = (*reconcilerImpl)(nil) -func NewReconciler(ctx context.Context, logger *zap.SugaredLogger, client versioned.Interface, lister flowsv1alpha1.SequenceLister, recorder record.EventRecorder, r Interface, options ...controller.Options) controller.Reconciler { +func NewReconciler(ctx context.Context, logger *zap.SugaredLogger, client versioned.Interface, lister flowsv1beta1.SequenceLister, recorder record.EventRecorder, r Interface, options ...controller.Options) controller.Reconciler { // Check the options function input. It should be 0 or 1. if len(options) > 1 { logger.Fatalf("up to one options struct is supported, found %d", len(options)) @@ -208,13 +208,13 @@ func (r *reconcilerImpl) Reconcile(ctx context.Context, key string) error { return nil } -func (r *reconcilerImpl) updateStatus(existing *v1alpha1.Sequence, desired *v1alpha1.Sequence) error { +func (r *reconcilerImpl) updateStatus(existing *v1beta1.Sequence, desired *v1beta1.Sequence) error { existing = existing.DeepCopy() return reconciler.RetryUpdateConflicts(func(attempts int) (err error) { // The first iteration tries to use the injectionInformer's state, subsequent attempts fetch the latest state via API. if attempts > 0 { - getter := r.Client.FlowsV1alpha1().Sequences(desired.Namespace) + getter := r.Client.FlowsV1beta1().Sequences(desired.Namespace) existing, err = getter.Get(desired.Name, metav1.GetOptions{}) if err != nil { @@ -229,7 +229,7 @@ func (r *reconcilerImpl) updateStatus(existing *v1alpha1.Sequence, desired *v1al existing.Status = desired.Status - updater := r.Client.FlowsV1alpha1().Sequences(existing.Namespace) + updater := r.Client.FlowsV1beta1().Sequences(existing.Namespace) _, err = updater.UpdateStatus(existing) return err @@ -239,7 +239,7 @@ func (r *reconcilerImpl) updateStatus(existing *v1alpha1.Sequence, desired *v1al // updateFinalizersFiltered will update the Finalizers of the resource. // TODO: this method could be generic and sync all finalizers. For now it only // updates defaultFinalizerName or its override. -func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource *v1alpha1.Sequence) (*v1alpha1.Sequence, error) { +func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource *v1beta1.Sequence) (*v1beta1.Sequence, error) { getter := r.Lister.Sequences(resource.Namespace) @@ -286,7 +286,7 @@ func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource return resource, err } - patcher := r.Client.FlowsV1alpha1().Sequences(resource.Namespace) + patcher := r.Client.FlowsV1beta1().Sequences(resource.Namespace) resource, err = patcher.Patch(resource.Name, types.MergePatchType, patch) if err != nil { @@ -299,7 +299,7 @@ func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource return resource, err } -func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource *v1alpha1.Sequence) (*v1alpha1.Sequence, error) { +func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource *v1beta1.Sequence) (*v1beta1.Sequence, error) { if _, ok := r.reconciler.(Finalizer); !ok { return resource, nil } @@ -317,7 +317,7 @@ func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource * return r.updateFinalizersFiltered(ctx, resource) } -func (r *reconcilerImpl) clearFinalizer(ctx context.Context, resource *v1alpha1.Sequence, reconcileEvent reconciler.Event) (*v1alpha1.Sequence, error) { +func (r *reconcilerImpl) clearFinalizer(ctx context.Context, resource *v1beta1.Sequence, reconcileEvent reconciler.Event) (*v1beta1.Sequence, error) { if _, ok := r.reconciler.(Finalizer); !ok { return resource, nil } diff --git a/pkg/client/injection/reconciler/flows/v1alpha1/sequence/stub/controller.go b/pkg/client/injection/reconciler/flows/v1beta1/sequence/stub/controller.go similarity index 89% rename from pkg/client/injection/reconciler/flows/v1alpha1/sequence/stub/controller.go rename to pkg/client/injection/reconciler/flows/v1beta1/sequence/stub/controller.go index df6cff27699..09e5afe192b 100644 --- a/pkg/client/injection/reconciler/flows/v1alpha1/sequence/stub/controller.go +++ b/pkg/client/injection/reconciler/flows/v1beta1/sequence/stub/controller.go @@ -21,8 +21,8 @@ package sequence import ( context "context" - sequence "knative.dev/eventing/pkg/client/injection/informers/flows/v1alpha1/sequence" - v1alpha1sequence "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/sequence" + sequence "knative.dev/eventing/pkg/client/injection/informers/flows/v1beta1/sequence" + v1beta1sequence "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/sequence" configmap "knative.dev/pkg/configmap" controller "knative.dev/pkg/controller" logging "knative.dev/pkg/logging" @@ -42,7 +42,7 @@ func NewController( // TODO: setup additional informers here. r := &Reconciler{} - impl := v1alpha1sequence.NewImpl(ctx, r) + impl := v1beta1sequence.NewImpl(ctx, r) logger.Info("Setting up event handlers.") diff --git a/pkg/client/injection/reconciler/flows/v1alpha1/sequence/stub/reconciler.go b/pkg/client/injection/reconciler/flows/v1beta1/sequence/stub/reconciler.go similarity index 88% rename from pkg/client/injection/reconciler/flows/v1alpha1/sequence/stub/reconciler.go rename to pkg/client/injection/reconciler/flows/v1beta1/sequence/stub/reconciler.go index 0c5907e3efb..a3254730b4c 100644 --- a/pkg/client/injection/reconciler/flows/v1alpha1/sequence/stub/reconciler.go +++ b/pkg/client/injection/reconciler/flows/v1beta1/sequence/stub/reconciler.go @@ -22,8 +22,8 @@ import ( context "context" v1 "k8s.io/api/core/v1" - v1alpha1 "knative.dev/eventing/pkg/apis/flows/v1alpha1" - sequence "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/sequence" + v1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" + sequence "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/sequence" reconciler "knative.dev/pkg/reconciler" ) @@ -47,7 +47,7 @@ var _ sequence.Interface = (*Reconciler)(nil) //var _ sequence.Finalizer = (*Reconciler)(nil) // ReconcileKind implements Interface.ReconcileKind. -func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1alpha1.Sequence) reconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1beta1.Sequence) reconciler.Event { // TODO: use this if the resource implements InitializeConditions. // o.Status.InitializeConditions() @@ -60,7 +60,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1alpha1.Sequence) re // Optionally, use FinalizeKind to add finalizers. FinalizeKind will be called // when the resource is deleted. -//func (r *Reconciler) FinalizeKind(ctx context.Context, o *v1alpha1.Sequence) reconciler.Event { +//func (r *Reconciler) FinalizeKind(ctx context.Context, o *v1beta1.Sequence) reconciler.Event { // // TODO: add custom finalization logic here. // return nil //} diff --git a/pkg/reconciler/parallel/controller.go b/pkg/reconciler/parallel/controller.go index b9ee66da35a..278c5e5a34b 100644 --- a/pkg/reconciler/parallel/controller.go +++ b/pkg/reconciler/parallel/controller.go @@ -20,7 +20,7 @@ import ( "context" "k8s.io/client-go/tools/cache" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" "knative.dev/eventing/pkg/duck" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" @@ -28,10 +28,10 @@ import ( "knative.dev/pkg/logging" eventingclient "knative.dev/eventing/pkg/client/injection/client" - "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelable" - "knative.dev/eventing/pkg/client/injection/informers/flows/v1alpha1/parallel" - "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/subscription" - parallelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/parallel" + "knative.dev/eventing/pkg/client/injection/ducks/duck/v1beta1/channelable" + "knative.dev/eventing/pkg/client/injection/informers/flows/v1beta1/parallel" + "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/subscription" + parallelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/parallel" ) // NewController initializes the controller and is called by the generated code @@ -60,7 +60,7 @@ func NewController( // Register handler for Subscriptions that are owned by Parallel, so that // we get notified if they change. subscriptionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupKind(v1alpha1.Kind("Parallel")), + FilterFunc: controller.FilterGroupKind(v1beta1.Kind("Parallel")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/parallel/controller_test.go b/pkg/reconciler/parallel/controller_test.go index 09957f6c473..5e507355571 100644 --- a/pkg/reconciler/parallel/controller_test.go +++ b/pkg/reconciler/parallel/controller_test.go @@ -23,9 +23,9 @@ 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/informers/flows/v1alpha1/parallel/fake" - _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/subscription/fake" + _ "knative.dev/eventing/pkg/client/injection/ducks/duck/v1beta1/channelable/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/flows/v1beta1/parallel/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/subscription/fake" ) func TestNew(t *testing.T) { diff --git a/pkg/reconciler/parallel/parallel.go b/pkg/reconciler/parallel/parallel.go index 8ea4370deb3..dd0e75dd11a 100644 --- a/pkg/reconciler/parallel/parallel.go +++ b/pkg/reconciler/parallel/parallel.go @@ -26,17 +26,18 @@ import ( apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/dynamic" duckapis "knative.dev/pkg/apis/duck" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - messaginglisters "knative.dev/eventing/pkg/client/listers/messaging/v1alpha1" + duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" + messaginglisters "knative.dev/eventing/pkg/client/listers/messaging/v1beta1" clientset "knative.dev/eventing/pkg/client/clientset/versioned" - parallelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/parallel" - listers "knative.dev/eventing/pkg/client/listers/flows/v1alpha1" + parallelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/parallel" + listers "knative.dev/eventing/pkg/client/listers/flows/v1beta1" "knative.dev/eventing/pkg/duck" "knative.dev/eventing/pkg/logging" "knative.dev/eventing/pkg/reconciler/parallel/resources" @@ -65,7 +66,7 @@ type Reconciler struct { // Check that our Reconciler implements parallelreconciler.Interface var _ parallelreconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, p *v1alpha1.Parallel) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, p *v1beta1.Parallel) pkgreconciler.Event { p.Status.InitializeConditions() p.Status.ObservedGeneration = p.Generation @@ -87,11 +88,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, p *v1alpha1.Parallel) pk return fmt.Errorf("unable to create dynamic client for: %+v", p.Spec.ChannelTemplate) } - // Tell tracker to reconcile this Parallel whenever my channels change. - track := r.channelableTracker.TrackInNamespace(p) - - var ingressChannel *duckv1alpha1.Channelable - channels := make([]*duckv1alpha1.Channelable, 0, len(p.Spec.Branches)) + var ingressChannel *duckv1beta1.Channelable + channels := make([]*duckv1beta1.Channelable, 0, len(p.Spec.Branches)) for i := -1; i < len(p.Spec.Branches); i++ { var channelName string if i == -1 { @@ -107,11 +105,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, p *v1alpha1.Parallel) pk Namespace: p.Namespace, } - // Track channels and enqueue parallel when they change. - if err := track(channelObjRef); err != nil { - return fmt.Errorf("unable to track changes to Channel: %v", err) - } - channelable, err := r.reconcileChannel(ctx, channelResourceInterface, p, channelObjRef) if err != nil { logging.FromContext(ctx).Error(fmt.Sprintf("Failed to reconcile Channel Object: %s/%s", p.Namespace, channelName), zap.Error(err)) @@ -127,8 +120,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, p *v1alpha1.Parallel) pk } p.Status.PropagateChannelStatuses(ingressChannel, channels) - filterSubs := make([]*messagingv1alpha1.Subscription, 0, len(p.Spec.Branches)) - subs := make([]*messagingv1alpha1.Subscription, 0, len(p.Spec.Branches)) + filterSubs := make([]*messagingv1beta1.Subscription, 0, len(p.Spec.Branches)) + subs := make([]*messagingv1beta1.Subscription, 0, len(p.Spec.Branches)) for i := 0; i < len(p.Spec.Branches); i++ { filterSub, sub, err := r.reconcileBranch(ctx, i, p) if err != nil { @@ -143,13 +136,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, p *v1alpha1.Parallel) pk return newReconciledNormal(p.Namespace, p.Name) } -func (r *Reconciler) reconcileChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, p *v1alpha1.Parallel, channelObjRef corev1.ObjectReference) (*duckv1alpha1.Channelable, error) { - lister, err := r.channelableTracker.ListerFor(channelObjRef) - if err != nil { - logging.FromContext(ctx).Error("Error getting lister for Channel", zap.Any("channel", channelObjRef), zap.Error(err)) - return nil, err - } - c, err := lister.ByNamespace(channelObjRef.Namespace).Get(channelObjRef.Name) +func (r *Reconciler) reconcileChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, p *v1beta1.Parallel, channelObjRef corev1.ObjectReference) (*duckv1beta1.Channelable, error) { + c, err := r.trackAndFetchChannel(ctx, p, channelObjRef) if err != nil { if apierrs.IsNotFound(err) { newChannel, err := resources.NewChannel(channelObjRef.Name, p) @@ -165,10 +153,10 @@ func (r *Reconciler) reconcileChannel(ctx context.Context, channelResourceInterf } logging.FromContext(ctx).Debug("Created Channel", zap.Any("channel", newChannel)) // Convert to Channel duck so that we can treat all Channels the same. - channelable := &duckv1alpha1.Channelable{} + channelable := &duckv1beta1.Channelable{} err = duckapis.FromUnstructured(created, channelable) if err != nil { - logging.FromContext(ctx).Error("Failed to convert to Channelable Object", zap.Any("channel", channelObjRef), zap.Error(err)) + logging.FromContext(ctx).Error("Failed to convert to Channelable Object", zap.Any("channel", created), zap.Error(err)) return nil, err } return channelable, nil @@ -177,15 +165,15 @@ func (r *Reconciler) reconcileChannel(ctx context.Context, channelResourceInterf return nil, err } logging.FromContext(ctx).Debug("Found Channel", zap.Any("channel", channelObjRef)) - channelable, ok := c.(*duckv1alpha1.Channelable) + channelable, ok := c.(*duckv1beta1.Channelable) if !ok { logging.FromContext(ctx).Error("Failed to convert to Channelable Object", zap.Any("channel", channelObjRef), zap.Error(err)) - return nil, err + return nil, fmt.Errorf("Failed to convert to Channelable Object: %+v", c) } return channelable, nil } -func (r *Reconciler) reconcileBranch(ctx context.Context, branchNumber int, p *v1alpha1.Parallel) (*messagingv1alpha1.Subscription, *messagingv1alpha1.Subscription, error) { +func (r *Reconciler) reconcileBranch(ctx context.Context, branchNumber int, p *v1beta1.Parallel) (*messagingv1beta1.Subscription, *messagingv1beta1.Subscription, error) { filterExpected := resources.NewFilterSubscription(branchNumber, p) filterSubName := resources.ParallelFilterSubscriptionName(p.Name, branchNumber) @@ -205,14 +193,14 @@ func (r *Reconciler) reconcileBranch(ctx context.Context, branchNumber int, p *v return filterSub, sub, nil } -func (r *Reconciler) reconcileSubscription(ctx context.Context, branchNumber int, expected *messagingv1alpha1.Subscription, subName, ns string) (*messagingv1alpha1.Subscription, error) { +func (r *Reconciler) reconcileSubscription(ctx context.Context, branchNumber int, expected *messagingv1beta1.Subscription, subName, ns string) (*messagingv1beta1.Subscription, error) { sub, err := r.subscriptionLister.Subscriptions(ns).Get(subName) // If the resource doesn't exist, we'll create it. if apierrs.IsNotFound(err) { sub = expected logging.FromContext(ctx).Info(fmt.Sprintf("Creating subscription: %+v", sub)) - newSub, err := r.eventingClientSet.MessagingV1alpha1().Subscriptions(sub.Namespace).Create(sub) + newSub, err := r.eventingClientSet.MessagingV1beta1().Subscriptions(sub.Namespace).Create(sub) if err != nil { // TODO: Send events here, or elsewhere? //r.Recorder.Eventf(p, corev1.EventTypeWarning, subscriptionCreateFailed, "Create Parallel's subscription failed: %v", err) @@ -227,12 +215,12 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, branchNumber int } else if !equality.Semantic.DeepDerivative(expected.Spec, sub.Spec) { // Given that spec.channel is immutable, we cannot just update the subscription. We delete // it instead, and re-create it. - err = r.eventingClientSet.MessagingV1alpha1().Subscriptions(sub.Namespace).Delete(sub.Name, &metav1.DeleteOptions{}) + err = r.eventingClientSet.MessagingV1beta1().Subscriptions(sub.Namespace).Delete(sub.Name, &metav1.DeleteOptions{}) if err != nil { logging.FromContext(ctx).Info("Cannot delete subscription", zap.Error(err)) return nil, err } - newSub, err := r.eventingClientSet.MessagingV1alpha1().Subscriptions(sub.Namespace).Create(expected) + newSub, err := r.eventingClientSet.MessagingV1beta1().Subscriptions(sub.Namespace).Create(expected) if err != nil { logging.FromContext(ctx).Info("Cannot create subscription", zap.Error(err)) return nil, err @@ -241,3 +229,24 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, branchNumber int } return sub, nil } + +func (r *Reconciler) trackAndFetchChannel(ctx context.Context, p *v1beta1.Parallel, ref corev1.ObjectReference) (runtime.Object, pkgreconciler.Event) { + // Track the channel using the channelableTracker. + // We don't need the explicitly set a channelInformer, as this will dynamically generate one for us. + // This code needs to be called before checking the existence of the `channel`, in order to make sure the + // subscription controller will reconcile upon a `channel` change. + if err := r.channelableTracker.TrackInNamespace(p)(ref); err != nil { + return nil, pkgreconciler.NewEvent(corev1.EventTypeWarning, "TrackerFailed", "unable to track changes to channel %+v : %v", ref, err) + } + chLister, err := r.channelableTracker.ListerFor(ref) + if err != nil { + logging.FromContext(ctx).Error("Error getting lister for Channel", zap.Any("channel", ref), zap.Error(err)) + return nil, err + } + obj, err := chLister.ByNamespace(p.Namespace).Get(ref.Name) + if err != nil { + logging.FromContext(ctx).Error("Error getting channel from lister", zap.Any("channel", ref), zap.Error(err)) + return nil, err + } + return obj, err +} diff --git a/pkg/reconciler/parallel/parallel_test.go b/pkg/reconciler/parallel/parallel_test.go index 8ee42c2573e..e3ed4a5089c 100644 --- a/pkg/reconciler/parallel/parallel_test.go +++ b/pkg/reconciler/parallel/parallel_test.go @@ -24,7 +24,7 @@ import ( fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" fakedynamicclient "knative.dev/pkg/injection/clients/dynamicclient/fake" - "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/parallel" + "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/parallel" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -33,22 +33,23 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" clientgotesting "k8s.io/client-go/testing" - "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelable" + "knative.dev/eventing/pkg/client/injection/ducks/duck/v1beta1/channelable" "knative.dev/eventing/pkg/duck" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" + duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" "knative.dev/pkg/logging" logtesting "knative.dev/pkg/logging/testing" . "knative.dev/pkg/reconciler/testing" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/eventing/pkg/reconciler/parallel/resources" - . "knative.dev/eventing/pkg/reconciler/testing" - reconciletesting "knative.dev/eventing/pkg/reconciler/testing" + rt "knative.dev/eventing/pkg/reconciler/testing/v1beta1" + + . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" ) const ( @@ -60,8 +61,8 @@ const ( func init() { // Add types to scheme - _ = v1alpha1.AddToScheme(scheme.Scheme) - _ = duckv1alpha1.AddToScheme(scheme.Scheme) + _ = v1beta1.AddToScheme(scheme.Scheme) + _ = duckv1beta1.AddToScheme(scheme.Scheme) _ = duckv1.AddToScheme(scheme.Scheme) } @@ -69,8 +70,8 @@ func TestAllBranches(t *testing.T) { pKey := testNS + "/" + parallelName imc := &messagingv1beta1.ChannelTemplateSpec{ TypeMeta: metav1.TypeMeta{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", }, Spec: &runtime.RawExtension{Raw: []byte("{}")}, } @@ -87,7 +88,7 @@ func TestAllBranches(t *testing.T) { }, { // TODO: there is a bug in the controller, it will query for "" // Name: "trigger key not found ", // Objects: []runtime.Object{ - // reconciletesting.NewTrigger(triggerName, testNS), + // rt.NewTrigger(triggerName, testNS), // }, // Key: "foo/incomplete", // WantErr: true, @@ -98,19 +99,19 @@ func TestAllBranches(t *testing.T) { Name: "deleting", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelDeleted)}, + rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelDeleted)}, WantErr: false, }, { Name: "single branch, no filter", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelGeneration(parallelGeneration), - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelGeneration(parallelGeneration), + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, }))}, WantErr: false, @@ -120,25 +121,25 @@ func TestAllBranches(t *testing.T) { WantCreates: []runtime.Object{ createChannel(parallelName), createBranchChannel(parallelName, 0), - resources.NewFilterSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewFilterSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, }))), - resources.NewSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, }))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelGeneration(parallelGeneration), - reconciletesting.WithFlowsParallelStatusObservedGeneration(parallelGeneration), - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{{Subscriber: createSubscriber(0)}}), - reconciletesting.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), - reconciletesting.WithFlowsParallelBranchStatuses([]v1alpha1.ParallelBranchStatus{{ + Object: rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelGeneration(parallelGeneration), + rt.WithFlowsParallelStatusObservedGeneration(parallelGeneration), + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{{Subscriber: createSubscriber(0)}}), + rt.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), + rt.WithFlowsParallelBranchStatuses([]v1beta1.ParallelBranchStatus{{ FilterSubscriptionStatus: createParallelFilterSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), FilterChannelStatus: createParallelBranchChannelStatus(parallelName, 0, corev1.ConditionFalse), SubscriptionStatus: createParallelSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), @@ -148,10 +149,10 @@ func TestAllBranches(t *testing.T) { Name: "single branch, with filter", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Filter: createFilter(0), Subscriber: createSubscriber(0)}, }))}, WantErr: false, @@ -161,23 +162,23 @@ func TestAllBranches(t *testing.T) { WantCreates: []runtime.Object{ createChannel(parallelName), createBranchChannel(parallelName, 0), - resources.NewFilterSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewFilterSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Filter: createFilter(0), Subscriber: createSubscriber(0)}, }))), - resources.NewSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Filter: createFilter(0), Subscriber: createSubscriber(0)}, }))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{{Filter: createFilter(0), Subscriber: createSubscriber(0)}}), - reconciletesting.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), - reconciletesting.WithFlowsParallelBranchStatuses([]v1alpha1.ParallelBranchStatus{{ + Object: rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{{Filter: createFilter(0), Subscriber: createSubscriber(0)}}), + rt.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), + rt.WithFlowsParallelBranchStatuses([]v1beta1.ParallelBranchStatus{{ FilterSubscriptionStatus: createParallelFilterSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), FilterChannelStatus: createParallelBranchChannelStatus(parallelName, 0, corev1.ConditionFalse), SubscriptionStatus: createParallelSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), @@ -187,11 +188,11 @@ func TestAllBranches(t *testing.T) { Name: "single branch, no filter, with global reply", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, }))}, WantErr: false, @@ -201,26 +202,26 @@ func TestAllBranches(t *testing.T) { WantCreates: []runtime.Object{ createChannel(parallelName), createBranchChannel(parallelName, 0), - resources.NewFilterSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewFilterSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, }))), - resources.NewSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, - }), reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)))), + }), rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + Object: rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, }), - reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), - reconciletesting.WithFlowsParallelBranchStatuses([]v1alpha1.ParallelBranchStatus{{ + rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)), + rt.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), + rt.WithFlowsParallelBranchStatuses([]v1beta1.ParallelBranchStatus{{ FilterSubscriptionStatus: createParallelFilterSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), FilterChannelStatus: createParallelBranchChannelStatus(parallelName, 0, corev1.ConditionFalse), SubscriptionStatus: createParallelSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), @@ -230,11 +231,11 @@ func TestAllBranches(t *testing.T) { Name: "single branch with reply, no filter, with case and global reply", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0), Reply: createBranchReplyChannel(0)}, }))}, WantErr: false, @@ -244,26 +245,26 @@ func TestAllBranches(t *testing.T) { WantCreates: []runtime.Object{ createChannel(parallelName), createBranchChannel(parallelName, 0), - resources.NewFilterSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewFilterSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, }))), - resources.NewSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0), Reply: createBranchReplyChannel(0)}, - }), reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)))), + }), rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + Object: rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0), Reply: createBranchReplyChannel(0)}, }), - reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), - reconciletesting.WithFlowsParallelBranchStatuses([]v1alpha1.ParallelBranchStatus{{ + rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)), + rt.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), + rt.WithFlowsParallelBranchStatuses([]v1beta1.ParallelBranchStatus{{ FilterSubscriptionStatus: createParallelFilterSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), FilterChannelStatus: createParallelBranchChannelStatus(parallelName, 0, corev1.ConditionFalse), SubscriptionStatus: createParallelSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), @@ -273,10 +274,10 @@ func TestAllBranches(t *testing.T) { Name: "two branches, no filters", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }))}, @@ -288,35 +289,35 @@ func TestAllBranches(t *testing.T) { createChannel(parallelName), createBranchChannel(parallelName, 0), createBranchChannel(parallelName, 1), - resources.NewFilterSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewFilterSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }))), - resources.NewSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }))), - resources.NewFilterSubscription(1, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewFilterSubscription(1, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }))), - resources.NewSubscription(1, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(1, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, })))}, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + Object: rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }), - reconciletesting.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), - reconciletesting.WithFlowsParallelBranchStatuses([]v1alpha1.ParallelBranchStatus{ + rt.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), + rt.WithFlowsParallelBranchStatuses([]v1beta1.ParallelBranchStatus{ { FilterSubscriptionStatus: createParallelFilterSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), FilterChannelStatus: createParallelBranchChannelStatus(parallelName, 0, corev1.ConditionFalse), @@ -332,11 +333,11 @@ func TestAllBranches(t *testing.T) { Name: "two branches with global reply", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }))}, @@ -348,37 +349,37 @@ func TestAllBranches(t *testing.T) { createChannel(parallelName), createBranchChannel(parallelName, 0), createBranchChannel(parallelName, 1), - resources.NewFilterSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewFilterSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }))), - resources.NewSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, - }), reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)))), - resources.NewFilterSubscription(1, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + }), rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)))), + resources.NewFilterSubscription(1, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }))), - resources.NewSubscription(1, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(1, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, - }), reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)))), + }), rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + Object: rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelReply(createReplyChannel(replyChannelName)), + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, {Subscriber: createSubscriber(1)}, }), - reconciletesting.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), - reconciletesting.WithFlowsParallelBranchStatuses([]v1alpha1.ParallelBranchStatus{ + rt.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), + rt.WithFlowsParallelBranchStatuses([]v1beta1.ParallelBranchStatus{ { FilterSubscriptionStatus: createParallelFilterSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), FilterChannelStatus: createParallelBranchChannelStatus(parallelName, 0, corev1.ConditionFalse), @@ -395,15 +396,15 @@ func TestAllBranches(t *testing.T) { Name: "single branch, no filter, update subscription", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(1)}, })), - resources.NewSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(0, rt.NewFlowsParallel(parallelName, testNS, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(0)}, })))}, WantErr: false, @@ -416,23 +417,23 @@ func TestAllBranches(t *testing.T) { WantCreates: []runtime.Object{ createChannel(parallelName), createBranchChannel(parallelName, 0), - resources.NewFilterSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewFilterSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(1)}, }))), - resources.NewSubscription(0, reconciletesting.NewFlowsParallel(parallelName, testNS, reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{ + resources.NewSubscription(0, rt.NewFlowsParallel(parallelName, testNS, rt.WithFlowsParallelChannelTemplateSpec(imc), rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{ {Subscriber: createSubscriber(1)}, }))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsParallel(parallelName, testNS, - reconciletesting.WithInitFlowsParallelConditions, - reconciletesting.WithFlowsParallelChannelTemplateSpec(imc), - reconciletesting.WithFlowsParallelBranches([]v1alpha1.ParallelBranch{{Subscriber: createSubscriber(1)}}), - reconciletesting.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), - reconciletesting.WithFlowsParallelBranchStatuses([]v1alpha1.ParallelBranchStatus{{ + Object: rt.NewFlowsParallel(parallelName, testNS, + rt.WithInitFlowsParallelConditions, + rt.WithFlowsParallelChannelTemplateSpec(imc), + rt.WithFlowsParallelBranches([]v1beta1.ParallelBranch{{Subscriber: createSubscriber(1)}}), + rt.WithFlowsParallelChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithFlowsParallelAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithFlowsParallelSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithFlowsParallelIngressChannelStatus(createParallelChannelStatus(parallelName, corev1.ConditionFalse)), + rt.WithFlowsParallelBranchStatuses([]v1beta1.ParallelBranchStatus{{ FilterSubscriptionStatus: createParallelFilterSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), FilterChannelStatus: createParallelBranchChannelStatus(parallelName, 0, corev1.ConditionFalse), SubscriptionStatus: createParallelSubscriptionStatus(parallelName, 0, corev1.ConditionFalse), @@ -445,14 +446,14 @@ func TestAllBranches(t *testing.T) { table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { ctx = channelable.WithDuck(ctx) r := &Reconciler{ - parallelLister: listers.GetFlowsParallelLister(), + parallelLister: listers.GetParallelLister(), channelableTracker: duck.NewListableTracker(ctx, channelable.Get, func(types.NamespacedName) {}, 0), subscriptionLister: listers.GetSubscriptionLister(), eventingClientSet: fakeeventingclient.Get(ctx), dynamicClientSet: fakedynamicclient.Get(ctx), } return parallel.NewReconciler(ctx, logging.FromContext(ctx), - fakeeventingclient.Get(ctx), listers.GetFlowsParallelLister(), + fakeeventingclient.Get(ctx), listers.GetParallelLister(), controller.GetEventRecorder(ctx), r) }, false, logger)) } @@ -460,8 +461,8 @@ func TestAllBranches(t *testing.T) { func createBranchReplyChannel(caseNumber int) *duckv1.Destination { return &duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: fmt.Sprintf("%s-case-%d", replyChannelName, caseNumber), Namespace: testNS, }, @@ -471,8 +472,8 @@ func createBranchReplyChannel(caseNumber int) *duckv1.Destination { func createReplyChannel(channelName string) *duckv1.Destination { return &duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: channelName, Namespace: testNS, }, @@ -482,15 +483,15 @@ func createReplyChannel(channelName string) *duckv1.Destination { func createChannel(parallelName string) *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1alpha1", - "kind": "inmemorychannel", + "apiVersion": "messaging.knative.dev/v1beta1", + "kind": "InMemoryChannel", "metadata": map[string]interface{}{ "creationTimestamp": nil, "namespace": testNS, "name": resources.ParallelChannelName(parallelName), "ownerReferences": []interface{}{ map[string]interface{}{ - "apiVersion": "flows.knative.dev/v1alpha1", + "apiVersion": "flows.knative.dev/v1beta1", "blockOwnerDeletion": true, "controller": true, "kind": "Parallel", @@ -507,15 +508,15 @@ func createChannel(parallelName string) *unstructured.Unstructured { func createBranchChannel(parallelName string, caseNumber int) *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1alpha1", - "kind": "inmemorychannel", + "apiVersion": "messaging.knative.dev/v1beta1", + "kind": "InMemoryChannel", "metadata": map[string]interface{}{ "creationTimestamp": nil, "namespace": testNS, "name": resources.ParallelBranchChannelName(parallelName, caseNumber), "ownerReferences": []interface{}{ map[string]interface{}{ - "apiVersion": "flows.knative.dev/v1alpha1", + "apiVersion": "flows.knative.dev/v1beta1", "blockOwnerDeletion": true, "controller": true, "kind": "Parallel", @@ -529,11 +530,11 @@ func createBranchChannel(parallelName string, caseNumber int) *unstructured.Unst } } -func createParallelBranchChannelStatus(parallelName string, caseNumber int, status corev1.ConditionStatus) v1alpha1.ParallelChannelStatus { - return v1alpha1.ParallelChannelStatus{ +func createParallelBranchChannelStatus(parallelName string, caseNumber int, status corev1.ConditionStatus) v1beta1.ParallelChannelStatus { + return v1beta1.ParallelChannelStatus{ Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.ParallelBranchChannelName(parallelName, caseNumber), Namespace: testNS, }, @@ -546,11 +547,11 @@ func createParallelBranchChannelStatus(parallelName string, caseNumber int, stat } } -func createParallelChannelStatus(parallelName string, status corev1.ConditionStatus) v1alpha1.ParallelChannelStatus { - return v1alpha1.ParallelChannelStatus{ +func createParallelChannelStatus(parallelName string, status corev1.ConditionStatus) v1beta1.ParallelChannelStatus { + return v1beta1.ParallelChannelStatus{ Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.ParallelChannelName(parallelName), Namespace: testNS, }, @@ -563,10 +564,10 @@ func createParallelChannelStatus(parallelName string, status corev1.ConditionSta } } -func createParallelFilterSubscriptionStatus(parallelName string, caseNumber int, status corev1.ConditionStatus) v1alpha1.ParallelSubscriptionStatus { - return v1alpha1.ParallelSubscriptionStatus{ +func createParallelFilterSubscriptionStatus(parallelName string, caseNumber int, status corev1.ConditionStatus) v1beta1.ParallelSubscriptionStatus { + return v1beta1.ParallelSubscriptionStatus{ Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.ParallelFilterSubscriptionName(parallelName, caseNumber), Namespace: testNS, @@ -574,10 +575,10 @@ func createParallelFilterSubscriptionStatus(parallelName string, caseNumber int, } } -func createParallelSubscriptionStatus(parallelName string, caseNumber int, status corev1.ConditionStatus) v1alpha1.ParallelSubscriptionStatus { - return v1alpha1.ParallelSubscriptionStatus{ +func createParallelSubscriptionStatus(parallelName string, caseNumber int, status corev1.ConditionStatus) v1beta1.ParallelSubscriptionStatus { + return v1beta1.ParallelSubscriptionStatus{ Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.ParallelSubscriptionName(parallelName, caseNumber), Namespace: testNS, diff --git a/pkg/reconciler/parallel/resources/channel.go b/pkg/reconciler/parallel/resources/channel.go index 43e46262ef5..49d019af790 100644 --- a/pkg/reconciler/parallel/resources/channel.go +++ b/pkg/reconciler/parallel/resources/channel.go @@ -24,7 +24,7 @@ import ( "knative.dev/pkg/kmeta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" ) @@ -40,7 +40,7 @@ func ParallelBranchChannelName(parallelName string, branchNumber int) string { // NewChannel returns an unstructured.Unstructured based on the ChannelTemplateSpec // for a given parallel. -func NewChannel(name string, p *v1alpha1.Parallel) (*unstructured.Unstructured, error) { +func NewChannel(name string, p *v1beta1.Parallel) (*unstructured.Unstructured, error) { // Set the name of the resource we're creating as well as the namespace, etc. template := messagingv1beta1.ChannelTemplateSpecInternal{ TypeMeta: metav1.TypeMeta{ diff --git a/pkg/reconciler/parallel/resources/subscription.go b/pkg/reconciler/parallel/resources/subscription.go index 97af44b8dba..b458c888ae4 100644 --- a/pkg/reconciler/parallel/resources/subscription.go +++ b/pkg/reconciler/parallel/resources/subscription.go @@ -24,8 +24,8 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" ) func ParallelFilterSubscriptionName(parallelName string, branchNumber int) string { @@ -36,11 +36,11 @@ func ParallelSubscriptionName(parallelName string, branchNumber int) string { return fmt.Sprintf("%s-kn-parallel-%d", parallelName, branchNumber) } -func NewFilterSubscription(branchNumber int, p *v1alpha1.Parallel) *messagingv1alpha1.Subscription { - r := &messagingv1alpha1.Subscription{ +func NewFilterSubscription(branchNumber int, p *v1beta1.Parallel) *messagingv1beta1.Subscription { + r := &messagingv1beta1.Subscription{ TypeMeta: metav1.TypeMeta{ Kind: "Subscription", - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", }, ObjectMeta: metav1.ObjectMeta{ Namespace: p.Namespace, @@ -50,7 +50,7 @@ func NewFilterSubscription(branchNumber int, p *v1alpha1.Parallel) *messagingv1a *kmeta.NewControllerRef(p), }, }, - Spec: messagingv1alpha1.SubscriptionSpec{ + Spec: messagingv1beta1.SubscriptionSpec{ Channel: corev1.ObjectReference{ APIVersion: p.Spec.ChannelTemplate.APIVersion, Kind: p.Spec.ChannelTemplate.Kind, @@ -75,11 +75,11 @@ func NewFilterSubscription(branchNumber int, p *v1alpha1.Parallel) *messagingv1a return r } -func NewSubscription(branchNumber int, p *v1alpha1.Parallel) *messagingv1alpha1.Subscription { - r := &messagingv1alpha1.Subscription{ +func NewSubscription(branchNumber int, p *v1beta1.Parallel) *messagingv1beta1.Subscription { + r := &messagingv1beta1.Subscription{ TypeMeta: metav1.TypeMeta{ Kind: "Subscription", - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", }, ObjectMeta: metav1.ObjectMeta{ Namespace: p.Namespace, @@ -89,7 +89,7 @@ func NewSubscription(branchNumber int, p *v1alpha1.Parallel) *messagingv1alpha1. *kmeta.NewControllerRef(p), }, }, - Spec: messagingv1alpha1.SubscriptionSpec{ + Spec: messagingv1beta1.SubscriptionSpec{ Channel: corev1.ObjectReference{ APIVersion: p.Spec.ChannelTemplate.APIVersion, Kind: p.Spec.ChannelTemplate.Kind, diff --git a/pkg/reconciler/sequence/controller.go b/pkg/reconciler/sequence/controller.go index 43d32164f51..32ce8c76f8f 100644 --- a/pkg/reconciler/sequence/controller.go +++ b/pkg/reconciler/sequence/controller.go @@ -22,16 +22,16 @@ import ( "knative.dev/pkg/logging" "k8s.io/client-go/tools/cache" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" "knative.dev/eventing/pkg/duck" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" eventingclient "knative.dev/eventing/pkg/client/injection/client" - "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelable" - "knative.dev/eventing/pkg/client/injection/informers/flows/v1alpha1/sequence" - "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/subscription" - sequencereconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/sequence" + "knative.dev/eventing/pkg/client/injection/ducks/duck/v1beta1/channelable" + "knative.dev/eventing/pkg/client/injection/informers/flows/v1beta1/sequence" + "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/subscription" + sequencereconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/sequence" "knative.dev/pkg/injection/clients/dynamicclient" ) @@ -61,7 +61,7 @@ func NewController( // Register handler for Subscriptions that are owned by Sequence, so that // we get notified if they change. subscriptionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupKind(v1alpha1.Kind("Sequence")), + FilterFunc: controller.FilterGroupKind(v1beta1.Kind("Sequence")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/sequence/controller_test.go b/pkg/reconciler/sequence/controller_test.go index d4523795f95..04189a9f431 100644 --- a/pkg/reconciler/sequence/controller_test.go +++ b/pkg/reconciler/sequence/controller_test.go @@ -23,9 +23,9 @@ 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/informers/flows/v1alpha1/sequence/fake" - _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/subscription/fake" + _ "knative.dev/eventing/pkg/client/injection/ducks/duck/v1beta1/channelable/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/flows/v1beta1/sequence/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/subscription/fake" ) func TestNew(t *testing.T) { diff --git a/pkg/reconciler/sequence/resources/channel.go b/pkg/reconciler/sequence/resources/channel.go index 960cb318245..9caf435d3db 100644 --- a/pkg/reconciler/sequence/resources/channel.go +++ b/pkg/reconciler/sequence/resources/channel.go @@ -24,7 +24,7 @@ import ( "knative.dev/pkg/kmeta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1alpha1 "knative.dev/eventing/pkg/apis/flows/v1alpha1" + v1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" ) @@ -35,7 +35,7 @@ func SequenceChannelName(sequenceName string, step int) string { // NewChannel returns an unstructured.Unstructured based on the ChannelTemplateSpec // for a given sequence. -func NewChannel(name string, p *v1alpha1.Sequence) (*unstructured.Unstructured, error) { +func NewChannel(name string, p *v1beta1.Sequence) (*unstructured.Unstructured, error) { // Set the name of the resource we're creating as well as the namespace, etc. template := messagingv1beta1.ChannelTemplateSpecInternal{ TypeMeta: metav1.TypeMeta{ diff --git a/pkg/reconciler/sequence/resources/subscription.go b/pkg/reconciler/sequence/resources/subscription.go index 884d1224931..96ce2fdc381 100644 --- a/pkg/reconciler/sequence/resources/subscription.go +++ b/pkg/reconciler/sequence/resources/subscription.go @@ -23,8 +23,8 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" duckv1 "knative.dev/pkg/apis/duck/v1" ) @@ -32,11 +32,11 @@ func SequenceSubscriptionName(sequenceName string, step int) string { return fmt.Sprintf("%s-kn-sequence-%d", sequenceName, step) } -func NewSubscription(stepNumber int, s *v1alpha1.Sequence) *messagingv1alpha1.Subscription { - r := &messagingv1alpha1.Subscription{ +func NewSubscription(stepNumber int, s *v1beta1.Sequence) *messagingv1beta1.Subscription { + r := &messagingv1beta1.Subscription{ TypeMeta: metav1.TypeMeta{ Kind: "Subscription", - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", }, ObjectMeta: metav1.ObjectMeta{ Namespace: s.Namespace, @@ -46,7 +46,7 @@ func NewSubscription(stepNumber int, s *v1alpha1.Sequence) *messagingv1alpha1.Su *kmeta.NewControllerRef(s), }, }, - Spec: messagingv1alpha1.SubscriptionSpec{ + Spec: messagingv1beta1.SubscriptionSpec{ Channel: corev1.ObjectReference{ APIVersion: s.Spec.ChannelTemplate.APIVersion, Kind: s.Spec.ChannelTemplate.Kind, diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 0124fb2b066..cad6fb455e0 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -26,19 +26,20 @@ import ( apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/dynamic" - duckapis "knative.dev/pkg/apis/duck" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" + eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" clientset "knative.dev/eventing/pkg/client/clientset/versioned" - sequencereconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/sequence" - listers "knative.dev/eventing/pkg/client/listers/flows/v1alpha1" - messaginglisters "knative.dev/eventing/pkg/client/listers/messaging/v1alpha1" + sequencereconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/sequence" + listers "knative.dev/eventing/pkg/client/listers/flows/v1beta1" + messaginglisters "knative.dev/eventing/pkg/client/listers/messaging/v1beta1" "knative.dev/eventing/pkg/duck" "knative.dev/eventing/pkg/logging" "knative.dev/eventing/pkg/reconciler/sequence/resources" + duckapis "knative.dev/pkg/apis/duck" pkgreconciler "knative.dev/pkg/reconciler" ) @@ -63,7 +64,7 @@ type Reconciler struct { var _ sequencereconciler.Interface = (*Reconciler)(nil) // ReconcileKind implements Interface.ReconcileKind. -func (r *Reconciler) ReconcileKind(ctx context.Context, s *v1alpha1.Sequence) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, s *v1beta1.Sequence) pkgreconciler.Event { s.Status.InitializeConditions() s.Status.ObservedGeneration = s.Generation @@ -82,10 +83,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, s *v1alpha1.Sequence) pk return fmt.Errorf("unable to create dynamic client for: %+v", s.Spec.ChannelTemplate) } - // Tell tracker to reconcile this Sequence whenever my channels change. - track := r.channelableTracker.TrackInNamespace(s) - - channels := make([]*duckv1alpha1.Channelable, 0, len(s.Spec.Steps)) + channels := make([]*eventingduckv1beta1.Channelable, 0, len(s.Spec.Steps)) for i := 0; i < len(s.Spec.Steps); i++ { ingressChannelName := resources.SequenceChannelName(s.Name, i) @@ -95,10 +93,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, s *v1alpha1.Sequence) pk Name: ingressChannelName, Namespace: s.Namespace, } - // Track channels and enqueue sequence when they change. - if err := track(channelObjRef); err != nil { - return fmt.Errorf("unable to track changes to Channel: %v", err) - } channelable, err := r.reconcileChannel(ctx, channelResourceInterface, s, channelObjRef) if err != nil { @@ -111,7 +105,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, s *v1alpha1.Sequence) pk } s.Status.PropagateChannelStatuses(channels) - subs := make([]*messagingv1alpha1.Subscription, 0, len(s.Spec.Steps)) + subs := make([]*messagingv1beta1.Subscription, 0, len(s.Spec.Steps)) for i := 0; i < len(s.Spec.Steps); i++ { sub, err := r.reconcileSubscription(ctx, i, s) if err != nil { @@ -125,17 +119,12 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, s *v1alpha1.Sequence) pk return newReconciledNormal(s.Namespace, s.Name) } -func (r *Reconciler) reconcileChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, s *v1alpha1.Sequence, channelObjRef corev1.ObjectReference) (*duckv1alpha1.Channelable, error) { - lister, err := r.channelableTracker.ListerFor(channelObjRef) - if err != nil { - logging.FromContext(ctx).Error("Error getting lister for Channel", zap.Any("channel", channelObjRef), zap.Error(err)) - return nil, err - } - c, err := lister.ByNamespace(channelObjRef.Namespace).Get(channelObjRef.Name) +func (r *Reconciler) reconcileChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, s *v1beta1.Sequence, channelObjRef corev1.ObjectReference) (*eventingduckv1beta1.Channelable, error) { + c, err := r.trackAndFetchChannel(ctx, s, channelObjRef) if err != nil { if apierrs.IsNotFound(err) { newChannel, err := resources.NewChannel(channelObjRef.Name, s) - logging.FromContext(ctx).Error(fmt.Sprintf("Creating Channel Object: %+v", newChannel)) + logging.FromContext(ctx).Info(fmt.Sprintf("Creating Channel Object: %+v", newChannel)) if err != nil { logging.FromContext(ctx).Error("Failed to create Channel resource object", zap.Any("channel", channelObjRef), zap.Error(err)) return nil, err @@ -146,12 +135,12 @@ func (r *Reconciler) reconcileChannel(ctx context.Context, channelResourceInterf return nil, err } logging.FromContext(ctx).Debug("Created Channel", zap.Any("channel", newChannel)) - // Convert to Channel duck so that we can treat all Channels the same. - channelable := &duckv1alpha1.Channelable{} + + channelable := &eventingduckv1beta1.Channelable{} err = duckapis.FromUnstructured(created, channelable) if err != nil { - logging.FromContext(ctx).Error("Failed to convert to Channelable Object", zap.Any("channel", channelObjRef), zap.Error(err)) - return nil, err + logging.FromContext(ctx).Error("Failed to convert to channelable", zap.Any("channel", created), zap.Error(err)) + return nil, fmt.Errorf("Failed to convert created channel to channelable: %s", err) } return channelable, nil } @@ -159,15 +148,15 @@ func (r *Reconciler) reconcileChannel(ctx context.Context, channelResourceInterf return nil, err } logging.FromContext(ctx).Debug("Found Channel", zap.Any("channel", channelObjRef)) - channelable, ok := c.(*duckv1alpha1.Channelable) + channelable, ok := c.(*eventingduckv1beta1.Channelable) if !ok { - logging.FromContext(ctx).Error("Failed to convert to Channelable Object", zap.Any("channel", channelObjRef), zap.Error(err)) - return nil, err + logging.FromContext(ctx).Error("Failed to convert to Channelable Object", zap.Any("channel", c), zap.Error(err)) + return nil, fmt.Errorf("Failed to convert to Channelable Object: %+v", c) } return channelable, nil } -func (r *Reconciler) reconcileSubscription(ctx context.Context, step int, p *v1alpha1.Sequence) (*messagingv1alpha1.Subscription, error) { +func (r *Reconciler) reconcileSubscription(ctx context.Context, step int, p *v1beta1.Sequence) (*messagingv1beta1.Subscription, error) { expected := resources.NewSubscription(step, p) subName := resources.SequenceSubscriptionName(p.Name, step) @@ -177,7 +166,7 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, step int, p *v1a if apierrs.IsNotFound(err) { sub = expected logging.FromContext(ctx).Info(fmt.Sprintf("Creating subscription: %+v", sub)) - newSub, err := r.eventingClientSet.MessagingV1alpha1().Subscriptions(sub.Namespace).Create(sub) + newSub, err := r.eventingClientSet.MessagingV1beta1().Subscriptions(sub.Namespace).Create(sub) if err != nil { // TODO: Send events here, or elsewhere? //r.Recorder.Eventf(p, corev1.EventTypeWarning, subscriptionCreateFailed, "Create Sequence's subscription failed: %v", err) @@ -192,12 +181,12 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, step int, p *v1a } else if !equality.Semantic.DeepDerivative(expected.Spec, sub.Spec) { // Given that spec.channel is immutable, we cannot just update the subscription. We delete // it instead, and re-create it. - err = r.eventingClientSet.MessagingV1alpha1().Subscriptions(sub.Namespace).Delete(sub.Name, &metav1.DeleteOptions{}) + err = r.eventingClientSet.MessagingV1beta1().Subscriptions(sub.Namespace).Delete(sub.Name, &metav1.DeleteOptions{}) if err != nil { logging.FromContext(ctx).Info("Cannot delete subscription", zap.Error(err)) return nil, err } - newSub, err := r.eventingClientSet.MessagingV1alpha1().Subscriptions(sub.Namespace).Create(expected) + newSub, err := r.eventingClientSet.MessagingV1beta1().Subscriptions(sub.Namespace).Create(expected) if err != nil { logging.FromContext(ctx).Info("Cannot create subscription", zap.Error(err)) return nil, err @@ -206,3 +195,24 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, step int, p *v1a } return sub, nil } + +func (r *Reconciler) trackAndFetchChannel(ctx context.Context, seq *v1beta1.Sequence, ref corev1.ObjectReference) (runtime.Object, pkgreconciler.Event) { + // Track the channel using the channelableTracker. + // We don't need the explicitly set a channelInformer, as this will dynamically generate one for us. + // This code needs to be called before checking the existence of the `channel`, in order to make sure the + // subscription controller will reconcile upon a `channel` change. + if err := r.channelableTracker.TrackInNamespace(seq)(ref); err != nil { + return nil, pkgreconciler.NewEvent(corev1.EventTypeWarning, "TrackerFailed", "unable to track changes to channel %+v : %v", ref, err) + } + chLister, err := r.channelableTracker.ListerFor(ref) + if err != nil { + logging.FromContext(ctx).Error("Error getting lister for Channel", zap.Any("channel", ref), zap.Error(err)) + return nil, err + } + obj, err := chLister.ByNamespace(seq.Namespace).Get(ref.Name) + if err != nil { + logging.FromContext(ctx).Error("Error getting channel from lister", zap.Any("channel", ref), zap.Error(err)) + return nil, err + } + return obj, err +} diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index b2919dee5e1..b1e1e3268d0 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -28,24 +28,25 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" clientgotesting "k8s.io/client-go/testing" - "knative.dev/eventing/pkg/apis/flows/v1alpha1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" 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/channelable" - "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1alpha1/sequence" + + "knative.dev/eventing/pkg/client/injection/ducks/duck/v1beta1/channelable" + "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1beta1/sequence" "knative.dev/eventing/pkg/duck" "knative.dev/eventing/pkg/reconciler/sequence/resources" - reconciletesting "knative.dev/eventing/pkg/reconciler/testing" + rt "knative.dev/eventing/pkg/reconciler/testing/v1beta1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" + duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" fakedynamicclient "knative.dev/pkg/injection/clients/dynamicclient/fake" "knative.dev/pkg/logging" logtesting "knative.dev/pkg/logging/testing" - . "knative.dev/eventing/pkg/reconciler/testing" + . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" . "knative.dev/pkg/reconciler/testing" ) @@ -58,15 +59,16 @@ const ( func init() { // Add types to scheme - _ = v1alpha1.AddToScheme(scheme.Scheme) - _ = duckv1alpha1.AddToScheme(scheme.Scheme) + _ = v1beta1.AddToScheme(scheme.Scheme) + _ = duckv1beta1.AddToScheme(scheme.Scheme) + _ = duckv1.AddToScheme(scheme.Scheme) } func createReplyChannel(channelName string) *duckv1.Destination { return &duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: channelName, Namespace: testNS, }, @@ -76,15 +78,15 @@ func createReplyChannel(channelName string) *duckv1.Destination { func createChannel(sequenceName string, stepNumber int) *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "messaging.knative.dev/v1alpha1", - "kind": "inmemorychannel", + "apiVersion": "messaging.knative.dev/v1beta1", + "kind": "InMemoryChannel", "metadata": map[string]interface{}{ "creationTimestamp": nil, "namespace": testNS, "name": resources.SequenceChannelName(sequenceName, stepNumber), "ownerReferences": []interface{}{ map[string]interface{}{ - "apiVersion": "flows.knative.dev/v1alpha1", + "apiVersion": "flows.knative.dev/v1beta1", "blockOwnerDeletion": true, "controller": true, "kind": "Sequence", @@ -111,8 +113,8 @@ func TestAllCases(t *testing.T) { pKey := testNS + "/" + sequenceName imc := &messagingv1beta1.ChannelTemplateSpec{ TypeMeta: metav1.TypeMeta{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", }, Spec: &runtime.RawExtension{Raw: []byte("{}")}, } @@ -129,18 +131,18 @@ func TestAllCases(t *testing.T) { Name: "deleting", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceDeleted)}, + rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceDeleted)}, WantErr: false, }, { Name: "singlestep", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(0)}}))}, + rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(0)}}))}, WantErr: false, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "SequenceReconciled", `Sequence reconciled: "test-namespace/test-sequence"`), @@ -148,23 +150,23 @@ func TestAllCases(t *testing.T) { WantCreates: []runtime.Object{ createChannel(sequenceName, 0), resources.NewSubscription(0, - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(0)}}))), + rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(0)}}))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(0)}}), - reconciletesting.WithFlowsSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceChannelStatuses([]v1alpha1.SequenceChannelStatus{ + Object: rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(0)}}), + rt.WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithSequenceChannelStatuses([]v1beta1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 0), Namespace: testNS, }, @@ -176,10 +178,10 @@ func TestAllCases(t *testing.T) { }, }, }), - reconciletesting.WithFlowsSequenceSubscriptionStatuses([]v1alpha1.SequenceSubscriptionStatus{ + rt.WithSequenceSubscriptionStatuses([]v1beta1.SequenceSubscriptionStatus{ { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 0), Namespace: testNS, @@ -191,36 +193,36 @@ func TestAllCases(t *testing.T) { Name: "singlestepwithreply", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(0)}}))}, + rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceReply(createReplyChannel(replyChannelName)), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(0)}}))}, WantErr: false, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "SequenceReconciled", `Sequence reconciled: "test-namespace/test-sequence"`), }, WantCreates: []runtime.Object{ createChannel(sequenceName, 0), - resources.NewSubscription(0, reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(0)}}))), + resources.NewSubscription(0, rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceReply(createReplyChannel(replyChannelName)), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(0)}}))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(0)}}), - reconciletesting.WithFlowsSequenceReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceChannelStatuses([]v1alpha1.SequenceChannelStatus{ + Object: rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(0)}}), + rt.WithSequenceReply(createReplyChannel(replyChannelName)), + rt.WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithSequenceChannelStatuses([]v1beta1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 0), Namespace: testNS, }, @@ -232,10 +234,10 @@ func TestAllCases(t *testing.T) { }, }, }), - reconciletesting.WithFlowsSequenceSubscriptionStatuses([]v1alpha1.SequenceSubscriptionStatus{ + rt.WithSequenceSubscriptionStatuses([]v1beta1.SequenceSubscriptionStatus{ { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 0), Namespace: testNS, @@ -247,11 +249,11 @@ func TestAllCases(t *testing.T) { Name: "threestep", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceGeneration(sequenceGeneration), - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceGeneration(sequenceGeneration), + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))}, @@ -264,40 +266,40 @@ func TestAllCases(t *testing.T) { createChannel(sequenceName, 1), createChannel(sequenceName, 2), resources.NewSubscription(0, - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), resources.NewSubscription(1, - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), resources.NewSubscription(2, - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}})))}, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceGeneration(sequenceGeneration), - reconciletesting.WithFlowsSequenceStatusObservedGeneration(sequenceGeneration), - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + Object: rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceGeneration(sequenceGeneration), + rt.WithSequenceStatusObservedGeneration(sequenceGeneration), + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}), - reconciletesting.WithFlowsSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceChannelStatuses([]v1alpha1.SequenceChannelStatus{ + rt.WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithSequenceChannelStatuses([]v1beta1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 0), Namespace: testNS, }, @@ -310,8 +312,8 @@ func TestAllCases(t *testing.T) { }, { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 1), Namespace: testNS, }, @@ -324,8 +326,8 @@ func TestAllCases(t *testing.T) { }, { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 2), Namespace: testNS, }, @@ -337,10 +339,10 @@ func TestAllCases(t *testing.T) { }, }, }), - reconciletesting.WithFlowsSequenceSubscriptionStatuses([]v1alpha1.SequenceSubscriptionStatus{ + rt.WithSequenceSubscriptionStatuses([]v1beta1.SequenceSubscriptionStatus{ { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 0), Namespace: testNS, @@ -348,7 +350,7 @@ func TestAllCases(t *testing.T) { }, { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 1), Namespace: testNS, @@ -356,7 +358,7 @@ func TestAllCases(t *testing.T) { }, { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 2), Namespace: testNS, @@ -368,11 +370,11 @@ func TestAllCases(t *testing.T) { Name: "threestepwithreply", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceReply(createReplyChannel(replyChannelName)), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))}, @@ -384,44 +386,44 @@ func TestAllCases(t *testing.T) { createChannel(sequenceName, 0), createChannel(sequenceName, 1), createChannel(sequenceName, 2), - resources.NewSubscription(0, reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + resources.NewSubscription(0, rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceReply(createReplyChannel(replyChannelName)), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), - resources.NewSubscription(1, reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + resources.NewSubscription(1, rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceReply(createReplyChannel(replyChannelName)), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), - resources.NewSubscription(2, reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + resources.NewSubscription(2, rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceReply(createReplyChannel(replyChannelName)), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}})))}, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceReply(createReplyChannel(replyChannelName)), - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{ + Object: rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceReply(createReplyChannel(replyChannelName)), + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}), - reconciletesting.WithFlowsSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceChannelStatuses([]v1alpha1.SequenceChannelStatus{ + rt.WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithSequenceChannelStatuses([]v1beta1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 0), Namespace: testNS, }, @@ -434,8 +436,8 @@ func TestAllCases(t *testing.T) { }, { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 1), Namespace: testNS, }, @@ -448,8 +450,8 @@ func TestAllCases(t *testing.T) { }, { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 2), Namespace: testNS, }, @@ -461,10 +463,10 @@ func TestAllCases(t *testing.T) { }, }, }), - reconciletesting.WithFlowsSequenceSubscriptionStatuses([]v1alpha1.SequenceSubscriptionStatus{ + rt.WithSequenceSubscriptionStatuses([]v1beta1.SequenceSubscriptionStatus{ { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 0), Namespace: testNS, @@ -472,7 +474,7 @@ func TestAllCases(t *testing.T) { }, { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 1), Namespace: testNS, @@ -480,7 +482,7 @@ func TestAllCases(t *testing.T) { }, { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 2), Namespace: testNS, @@ -493,14 +495,14 @@ func TestAllCases(t *testing.T) { Name: "sequenceupdatesubscription", Key: pKey, Objects: []runtime.Object{ - reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(1)}})), + rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(1)}})), createChannel(sequenceName, 0), - resources.NewSubscription(0, reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(0)}}))), + resources.NewSubscription(0, rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(0)}}))), }, WantErr: false, WantEvents: []string{ @@ -510,23 +512,23 @@ func TestAllCases(t *testing.T) { {Name: resources.SequenceChannelName(sequenceName, 0)}, }, WantCreates: []runtime.Object{ - resources.NewSubscription(0, reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(1)}}))), + resources.NewSubscription(0, rt.NewSequence(sequenceName, testNS, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(1)}}))), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewFlowsSequence(sequenceName, testNS, - reconciletesting.WithInitFlowsSequenceConditions, - reconciletesting.WithFlowsSequenceChannelTemplateSpec(imc), - reconciletesting.WithFlowsSequenceSteps([]v1alpha1.SequenceStep{{Destination: createDestination(1)}}), - reconciletesting.WithFlowsSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - reconciletesting.WithFlowsSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - reconciletesting.WithFlowsSequenceChannelStatuses([]v1alpha1.SequenceChannelStatus{ + Object: rt.NewSequence(sequenceName, testNS, + rt.WithInitSequenceConditions, + rt.WithSequenceChannelTemplateSpec(imc), + rt.WithSequenceSteps([]v1beta1.SequenceStep{{Destination: createDestination(1)}}), + rt.WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + rt.WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + rt.WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + rt.WithSequenceChannelStatuses([]v1beta1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "inmemorychannel", + APIVersion: "messaging.knative.dev/v1beta1", + Kind: "InMemoryChannel", Name: resources.SequenceChannelName(sequenceName, 0), Namespace: testNS, }, @@ -538,10 +540,10 @@ func TestAllCases(t *testing.T) { }, }, }), - reconciletesting.WithFlowsSequenceSubscriptionStatuses([]v1alpha1.SequenceSubscriptionStatus{ + rt.WithSequenceSubscriptionStatuses([]v1beta1.SequenceSubscriptionStatus{ { Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Subscription", Name: resources.SequenceSubscriptionName(sequenceName, 0), Namespace: testNS, @@ -556,14 +558,14 @@ func TestAllCases(t *testing.T) { table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { ctx = channelable.WithDuck(ctx) r := &Reconciler{ - sequenceLister: listers.GetFlowsSequenceLister(), + sequenceLister: listers.GetSequenceLister(), channelableTracker: duck.NewListableTracker(ctx, channelable.Get, func(types.NamespacedName) {}, 0), subscriptionLister: listers.GetSubscriptionLister(), eventingClientSet: fakeeventingclient.Get(ctx), dynamicClientSet: fakedynamicclient.Get(ctx), } return sequence.NewReconciler(ctx, logging.FromContext(ctx), - fakeeventingclient.Get(ctx), listers.GetFlowsSequenceLister(), + fakeeventingclient.Get(ctx), listers.GetSequenceLister(), controller.GetEventRecorder(ctx), r) }, false, logger)) } diff --git a/pkg/reconciler/testing/v1beta1/listers.go b/pkg/reconciler/testing/v1beta1/listers.go index 977e28b653a..32eb918a048 100644 --- a/pkg/reconciler/testing/v1beta1/listers.go +++ b/pkg/reconciler/testing/v1beta1/listers.go @@ -34,7 +34,7 @@ import ( configsv1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1" eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" - flowsv1alpha1 "knative.dev/eventing/pkg/apis/flows/v1alpha1" + flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" @@ -42,7 +42,7 @@ import ( configslisters "knative.dev/eventing/pkg/client/listers/configs/v1alpha1" eventinglisters "knative.dev/eventing/pkg/client/listers/eventing/v1alpha1" eventingv1beta1listers "knative.dev/eventing/pkg/client/listers/eventing/v1beta1" - flowslisters "knative.dev/eventing/pkg/client/listers/flows/v1alpha1" + flowslisters "knative.dev/eventing/pkg/client/listers/flows/v1beta1" messaginglistersv1beta1 "knative.dev/eventing/pkg/client/listers/messaging/v1beta1" sourcelisters "knative.dev/eventing/pkg/client/listers/sources/v1alpha1" sourcev1alpha2listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2" @@ -124,8 +124,8 @@ func (l *Listers) GetSubscriptionLister() messaginglistersv1beta1.SubscriptionLi return messaginglistersv1beta1.NewSubscriptionLister(l.indexerFor(&messagingv1beta1.Subscription{})) } -func (l *Listers) GetFlowsSequenceLister() flowslisters.SequenceLister { - return flowslisters.NewSequenceLister(l.indexerFor(&flowsv1alpha1.Sequence{})) +func (l *Listers) GetSequenceLister() flowslisters.SequenceLister { + return flowslisters.NewSequenceLister(l.indexerFor(&flowsv1beta1.Sequence{})) } func (l *Listers) GetTriggerLister() eventinglisters.TriggerLister { @@ -152,8 +152,8 @@ func (l *Listers) GetMessagingChannelLister() messaginglistersv1beta1.ChannelLis return messaginglistersv1beta1.NewChannelLister(l.indexerFor(&messagingv1beta1.Channel{})) } -func (l *Listers) GetFlowsParallelLister() flowslisters.ParallelLister { - return flowslisters.NewParallelLister(l.indexerFor(&flowsv1alpha1.Parallel{})) +func (l *Listers) GetParallelLister() flowslisters.ParallelLister { + return flowslisters.NewParallelLister(l.indexerFor(&flowsv1beta1.Parallel{})) } func (l *Listers) GetApiServerSourceLister() sourcelisters.ApiServerSourceLister { diff --git a/pkg/reconciler/testing/v1beta1/parallel.go b/pkg/reconciler/testing/v1beta1/parallel.go new file mode 100644 index 00000000000..d9d7853b5e3 --- /dev/null +++ b/pkg/reconciler/testing/v1beta1/parallel.go @@ -0,0 +1,115 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + "context" + "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" + messagingvbeta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +// ParallelOption enables further configuration of a Parallel. +type FlowsParallelOption func(*v1beta1.Parallel) + +// NewFlowsParallel creates an Parallel with ParallelOptions. +func NewFlowsParallel(name, namespace string, popt ...FlowsParallelOption) *v1beta1.Parallel { + p := &v1beta1.Parallel{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: v1beta1.ParallelSpec{}, + } + for _, opt := range popt { + opt(p) + } + p.SetDefaults(context.Background()) + return p +} + +func WithInitFlowsParallelConditions(p *v1beta1.Parallel) { + p.Status.InitializeConditions() +} + +func WithFlowsParallelGeneration(gen int64) FlowsParallelOption { + return func(s *v1beta1.Parallel) { + s.Generation = gen + } +} + +func WithFlowsParallelStatusObservedGeneration(gen int64) FlowsParallelOption { + return func(s *v1beta1.Parallel) { + s.Status.ObservedGeneration = gen + } +} + +func WithFlowsParallelDeleted(p *v1beta1.Parallel) { + deleteTime := metav1.NewTime(time.Unix(1e9, 0)) + p.ObjectMeta.SetDeletionTimestamp(&deleteTime) +} + +func WithFlowsParallelChannelTemplateSpec(cts *messagingvbeta1.ChannelTemplateSpec) FlowsParallelOption { + return func(p *v1beta1.Parallel) { + p.Spec.ChannelTemplate = cts + } +} + +func WithFlowsParallelBranches(branches []v1beta1.ParallelBranch) FlowsParallelOption { + return func(p *v1beta1.Parallel) { + p.Spec.Branches = branches + } +} + +func WithFlowsParallelReply(reply *duckv1.Destination) FlowsParallelOption { + return func(p *v1beta1.Parallel) { + p.Spec.Reply = reply + } +} + +func WithFlowsParallelBranchStatuses(branchStatuses []v1beta1.ParallelBranchStatus) FlowsParallelOption { + return func(p *v1beta1.Parallel) { + p.Status.BranchStatuses = branchStatuses + } +} + +func WithFlowsParallelIngressChannelStatus(status v1beta1.ParallelChannelStatus) FlowsParallelOption { + return func(p *v1beta1.Parallel) { + p.Status.IngressChannelStatus = status + } +} + +func WithFlowsParallelChannelsNotReady(reason, message string) FlowsParallelOption { + return func(p *v1beta1.Parallel) { + p.Status.MarkChannelsNotReady(reason, message) + } +} + +func WithFlowsParallelSubscriptionsNotReady(reason, message string) FlowsParallelOption { + return func(p *v1beta1.Parallel) { + p.Status.MarkSubscriptionsNotReady(reason, message) + } +} + +func WithFlowsParallelAddressableNotReady(reason, message string) FlowsParallelOption { + return func(p *v1beta1.Parallel) { + p.Status.MarkAddressableNotReady(reason, message) + } +} diff --git a/pkg/reconciler/testing/v1beta1/sequence.go b/pkg/reconciler/testing/v1beta1/sequence.go new file mode 100644 index 00000000000..e055851bffb --- /dev/null +++ b/pkg/reconciler/testing/v1beta1/sequence.go @@ -0,0 +1,115 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + "context" + "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/eventing/pkg/apis/flows/v1beta1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +// SequenceOption enables further configuration of a Sequence. +type SequenceOption func(*v1beta1.Sequence) + +// NewSequence creates an Sequence with SequenceOptions. +func NewSequence(name, namespace string, popt ...SequenceOption) *v1beta1.Sequence { + p := &v1beta1.Sequence{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: v1beta1.SequenceSpec{}, + } + for _, opt := range popt { + opt(p) + } + p.SetDefaults(context.Background()) + return p +} + +func WithSequenceGeneration(gen int64) SequenceOption { + return func(s *v1beta1.Sequence) { + s.Generation = gen + } +} + +func WithSequenceStatusObservedGeneration(gen int64) SequenceOption { + return func(s *v1beta1.Sequence) { + s.Status.ObservedGeneration = gen + } +} + +func WithInitSequenceConditions(p *v1beta1.Sequence) { + p.Status.InitializeConditions() +} + +func WithSequenceDeleted(p *v1beta1.Sequence) { + deleteTime := metav1.NewTime(time.Unix(1e9, 0)) + p.ObjectMeta.SetDeletionTimestamp(&deleteTime) +} + +func WithSequenceChannelTemplateSpec(cts *messagingv1beta1.ChannelTemplateSpec) SequenceOption { + return func(p *v1beta1.Sequence) { + p.Spec.ChannelTemplate = cts + } +} + +func WithSequenceSteps(steps []v1beta1.SequenceStep) SequenceOption { + return func(p *v1beta1.Sequence) { + p.Spec.Steps = steps + } +} + +func WithSequenceReply(reply *duckv1.Destination) SequenceOption { + return func(p *v1beta1.Sequence) { + p.Spec.Reply = reply + } +} + +func WithSequenceSubscriptionStatuses(subscriptionStatuses []v1beta1.SequenceSubscriptionStatus) SequenceOption { + return func(p *v1beta1.Sequence) { + p.Status.SubscriptionStatuses = subscriptionStatuses + } +} + +func WithSequenceChannelStatuses(channelStatuses []v1beta1.SequenceChannelStatus) SequenceOption { + return func(p *v1beta1.Sequence) { + p.Status.ChannelStatuses = channelStatuses + } +} + +func WithSequenceChannelsNotReady(reason, message string) SequenceOption { + return func(p *v1beta1.Sequence) { + p.Status.MarkChannelsNotReady(reason, message) + } +} + +func WithSequenceSubscriptionsNotReady(reason, message string) SequenceOption { + return func(p *v1beta1.Sequence) { + p.Status.MarkSubscriptionsNotReady(reason, message) + } +} + +func WithSequenceAddressableNotReady(reason, message string) SequenceOption { + return func(p *v1beta1.Sequence) { + p.Status.MarkAddressableNotReady(reason, message) + } +} diff --git a/test/e2e/helpers/parallel_test_helper.go b/test/e2e/helpers/parallel_test_helper.go new file mode 100644 index 00000000000..4f21eb54283 --- /dev/null +++ b/test/e2e/helpers/parallel_test_helper.go @@ -0,0 +1,141 @@ +/* +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 helpers + +import ( + "encoding/json" + "fmt" + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/uuid" + + "knative.dev/eventing/pkg/apis/flows/v1alpha1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" + eventingtesting "knative.dev/eventing/pkg/reconciler/testing" + "knative.dev/eventing/test/lib" + "knative.dev/eventing/test/lib/cloudevents" + "knative.dev/eventing/test/lib/resources" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +type branchConfig struct { + filter bool +} + +func ParallelTestHelper(t *testing.T, + channelTestRunner lib.ChannelTestRunner, + options ...lib.SetupClientOption) { + const ( + senderPodName = "e2e-parallel" + ) + table := []struct { + name string + branchesConfig []branchConfig + expected string + }{ + { + name: "two-branches-pass-first-branch-only", + branchesConfig: []branchConfig{ + {filter: false}, + {filter: true}, + }, + expected: "parallel-two-branches-pass-first-branch-only-branch-0-sub", + }, + } + channelTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { + client := lib.Setup(st, true, options...) + defer lib.TearDown(client) + + for _, tc := range table { + parallelBranches := make([]v1alpha1.ParallelBranch, len(tc.branchesConfig)) + for branchNumber, cse := range tc.branchesConfig { + // construct filter services + filterPodName := fmt.Sprintf("parallel-%s-branch-%d-filter", tc.name, branchNumber) + filterPod := resources.EventFilteringPod(filterPodName, cse.filter) + client.CreatePodOrFail(filterPod, lib.WithService(filterPodName)) + + // construct branch subscriber + subPodName := fmt.Sprintf("parallel-%s-branch-%d-sub", tc.name, branchNumber) + subPod := resources.SequenceStepperPod(subPodName, subPodName) + client.CreatePodOrFail(subPod, lib.WithService(subPodName)) + + parallelBranches[branchNumber] = v1alpha1.ParallelBranch{ + Filter: &duckv1.Destination{ + Ref: resources.KnativeRefForService(filterPodName, client.Namespace), + }, + Subscriber: duckv1.Destination{ + Ref: resources.KnativeRefForService(subPodName, client.Namespace), + }, + } + } + + channelTemplate := &messagingv1beta1.ChannelTemplateSpec{ + TypeMeta: channel, + } + + // create logger service for global reply + loggerPodName := fmt.Sprintf("%s-logger", tc.name) + loggerPod := resources.EventLoggerPod(loggerPodName) + client.CreatePodOrFail(loggerPod, lib.WithService(loggerPodName)) + + // create channel as reply of the Parallel + // TODO(chizhg): now we'll have to use a channel plus its subscription here, as reply of the Subscription + // must be Addressable. + replyChannelName := fmt.Sprintf("reply-%s", tc.name) + client.CreateChannelOrFail(replyChannelName, &channel) + replySubscriptionName := fmt.Sprintf("reply-%s", tc.name) + client.CreateSubscriptionOrFail( + replySubscriptionName, + replyChannelName, + &channel, + resources.WithSubscriberForSubscription(loggerPodName), + ) + + parallel := eventingtesting.NewFlowsParallel(tc.name, client.Namespace, + eventingtesting.WithFlowsParallelChannelTemplateSpec(channelTemplate), + eventingtesting.WithFlowsParallelBranches(parallelBranches), + eventingtesting.WithFlowsParallelReply(&duckv1.Destination{Ref: &duckv1.KReference{Kind: channel.Kind, APIVersion: channel.APIVersion, Name: replyChannelName, Namespace: client.Namespace}})) + + client.CreateFlowsParallelOrFail(parallel) + + client.WaitForAllTestResourcesReadyOrFail() + + // send fake CloudEvent to the Parallel + msg := fmt.Sprintf("TestFlowParallel %s - ", uuid.NewUUID()) + // NOTE: the eventData format must be BaseData, as it needs to be correctly parsed in the stepper service. + eventData := cloudevents.BaseData{Message: msg} + eventDataBytes, err := json.Marshal(eventData) + if err != nil { + st.Fatalf("Failed to convert %v to json: %v", eventData, err) + } + event := cloudevents.New( + string(eventDataBytes), + cloudevents.WithSource(senderPodName), + ) + client.SendFakeEventToAddressableOrFail( + senderPodName, + tc.name, + lib.FlowsParallelTypeMeta, + event) + + // verify the logger service receives the correct transformed event + if err := client.CheckLog(loggerPodName, lib.CheckerContains(tc.expected)); err != nil { + st.Fatalf("String %q not found in logs of logger pod %q: %v", tc.expected, loggerPodName, err) + } + } + }) +} diff --git a/test/e2e/helpers/sequence_test_helper.go b/test/e2e/helpers/sequence_test_helper.go new file mode 100644 index 00000000000..57e9cd42edd --- /dev/null +++ b/test/e2e/helpers/sequence_test_helper.go @@ -0,0 +1,147 @@ +/* +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 helpers + +import ( + "encoding/json" + "fmt" + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/uuid" + + "knative.dev/eventing/pkg/apis/flows/v1alpha1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" + eventingtesting "knative.dev/eventing/pkg/reconciler/testing" + "knative.dev/eventing/test/lib" + "knative.dev/eventing/test/lib/cloudevents" + "knative.dev/eventing/test/lib/resources" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +func SequenceTestHelper(t *testing.T, + channelTestRunner lib.ChannelTestRunner, + options ...lib.SetupClientOption) { + const ( + sequenceName = "e2e-sequence" + senderPodName = "e2e-sequence-sender-pod" + + channelName = "e2e-sequence-channel" + subscriptionName = "e2e-sequence-subscription" + loggerPodName = "e2e-sequence-logger-pod" + ) + + stepSubscriberConfigs := []struct { + podName string + msgAppender string + }{{ + podName: "e2e-stepper1", + msgAppender: "-step1", + }, { + podName: "e2e-stepper2", + msgAppender: "-step2", + }, { + podName: "e2e-stepper3", + msgAppender: "-step3", + }} + + channelTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { + client := lib.Setup(st, true, options...) + defer lib.TearDown(client) + + // construct steps for the sequence + steps := make([]v1alpha1.SequenceStep, 0) + for _, config := range stepSubscriberConfigs { + // create a stepper Pod with Service + podName := config.podName + msgAppender := config.msgAppender + stepperPod := resources.SequenceStepperPod(podName, msgAppender) + + client.CreatePodOrFail(stepperPod, lib.WithService(podName)) + // create a new step + step := v1alpha1.SequenceStep{ + Destination: duckv1.Destination{ + Ref: resources.KnativeRefForService(podName, client.Namespace), + }} + // add the step into steps + steps = append(steps, step) + } + + // create channelTemplate for the Sequence + channelTemplate := &messagingv1beta1.ChannelTemplateSpec{ + TypeMeta: channel, + } + + // create channel as reply of the Sequence + // TODO(chizhg): now we'll have to use a channel plus its subscription here, as reply of the Sequence + // must be Addressable. In the future if we use Knative Serving in the tests, we can + // make the logger service as a Knative service, and remove the channel and subscription. + client.CreateChannelOrFail(channelName, &channel) + // create logger service as the subscriber + loggerPod := resources.EventLoggerPod(loggerPodName) + client.CreatePodOrFail(loggerPod, lib.WithService(loggerPodName)) + // create subscription to subscribe the channel, and forward the received events to the logger service + client.CreateSubscriptionOrFail( + subscriptionName, + channelName, + &channel, + resources.WithSubscriberForSubscription(loggerPodName), + ) + replyRef := &duckv1.KReference{Kind: channel.Kind, APIVersion: channel.APIVersion, Name: channelName, Namespace: client.Namespace} + + // create the sequence object + sequence := eventingtesting.NewFlowsSequence( + sequenceName, + client.Namespace, + eventingtesting.WithFlowsSequenceSteps(steps), + eventingtesting.WithFlowsSequenceChannelTemplateSpec(channelTemplate), + eventingtesting.WithFlowsSequenceReply(&duckv1.Destination{Ref: replyRef}), + ) + + // create Sequence or fail the test if there is an error + client.CreateFlowsSequenceOrFail(sequence) + + // wait for all test resources to be ready, so that we can start sending events + client.WaitForAllTestResourcesReadyOrFail() + + // send fake CloudEvent to the Sequence + msg := fmt.Sprintf("TestSequence %s", uuid.NewUUID()) + // NOTE: the eventData format must be BaseData, as it needs to be correctly parsed in the stepper service. + eventData := cloudevents.BaseData{Message: msg} + eventDataBytes, err := json.Marshal(eventData) + if err != nil { + st.Fatalf("Failed to convert %v to json: %v", eventData, err) + } + event := cloudevents.New( + string(eventDataBytes), + cloudevents.WithSource(senderPodName), + ) + client.SendFakeEventToAddressableOrFail( + senderPodName, + sequenceName, + lib.FlowsSequenceTypeMeta, + event) + + // verify the logger service receives the correct transformed event + expectedMsg := msg + for _, config := range stepSubscriberConfigs { + expectedMsg += config.msgAppender + } + if err := client.CheckLog(loggerPodName, lib.CheckerContains(expectedMsg)); err != nil { + st.Fatalf("String %q not found in logs of logger pod %q: %v", expectedMsg, loggerPodName, err) + } + }) +} diff --git a/test/e2e/parallel_test.go b/test/e2e/parallel_test.go index a65650fc4d6..a13df4d28f1 100644 --- a/test/e2e/parallel_test.go +++ b/test/e2e/parallel_test.go @@ -18,125 +18,11 @@ limitations under the License. package e2e import ( - "encoding/json" - "fmt" "testing" - "k8s.io/apimachinery/pkg/util/uuid" - duckv1 "knative.dev/pkg/apis/duck/v1" - - "knative.dev/eventing/test/lib" - "knative.dev/eventing/test/lib/cloudevents" - "knative.dev/eventing/test/lib/resources" - - "knative.dev/eventing/pkg/apis/flows/v1alpha1" - messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" - eventingtesting "knative.dev/eventing/pkg/reconciler/testing" + "knative.dev/eventing/test/e2e/helpers" ) -type branchConfig struct { - filter bool -} - -func TestFlowsParallel(t *testing.T) { - const ( - senderPodName = "e2e-parallel" - ) - table := []struct { - name string - branchesConfig []branchConfig - expected string - }{ - { - name: "two-branches-pass-first-branch-only", - branchesConfig: []branchConfig{ - {filter: false}, - {filter: true}, - }, - expected: "parallel-two-branches-pass-first-branch-only-branch-0-sub", - }, - } - channelTypeMeta := &lib.DefaultChannel - - client := setup(t, true) - defer tearDown(client) - - for _, tc := range table { - parallelBranches := make([]v1alpha1.ParallelBranch, len(tc.branchesConfig)) - for branchNumber, cse := range tc.branchesConfig { - // construct filter services - filterPodName := fmt.Sprintf("parallel-%s-branch-%d-filter", tc.name, branchNumber) - filterPod := resources.EventFilteringPod(filterPodName, cse.filter) - client.CreatePodOrFail(filterPod, lib.WithService(filterPodName)) - - // construct branch subscriber - subPodName := fmt.Sprintf("parallel-%s-branch-%d-sub", tc.name, branchNumber) - subPod := resources.SequenceStepperPod(subPodName, subPodName) - client.CreatePodOrFail(subPod, lib.WithService(subPodName)) - - parallelBranches[branchNumber] = v1alpha1.ParallelBranch{ - Filter: &duckv1.Destination{ - Ref: resources.KnativeRefForService(filterPodName, client.Namespace), - }, - Subscriber: duckv1.Destination{ - Ref: resources.KnativeRefForService(subPodName, client.Namespace), - }, - } - } - - channelTemplate := &messagingv1beta1.ChannelTemplateSpec{ - TypeMeta: *(channelTypeMeta), - } - - // create logger service for global reply - loggerPodName := fmt.Sprintf("%s-logger", tc.name) - loggerPod := resources.EventLoggerPod(loggerPodName) - client.CreatePodOrFail(loggerPod, lib.WithService(loggerPodName)) - - // create channel as reply of the Parallel - // TODO(chizhg): now we'll have to use a channel plus its subscription here, as reply of the Subscription - // must be Addressable. - replyChannelName := fmt.Sprintf("reply-%s", tc.name) - client.CreateChannelOrFail(replyChannelName, channelTypeMeta) - replySubscriptionName := fmt.Sprintf("reply-%s", tc.name) - client.CreateSubscriptionOrFail( - replySubscriptionName, - replyChannelName, - channelTypeMeta, - resources.WithSubscriberForSubscription(loggerPodName), - ) - - parallel := eventingtesting.NewFlowsParallel(tc.name, client.Namespace, - eventingtesting.WithFlowsParallelChannelTemplateSpec(channelTemplate), - eventingtesting.WithFlowsParallelBranches(parallelBranches), - eventingtesting.WithFlowsParallelReply(&duckv1.Destination{Ref: &duckv1.KReference{Kind: channelTypeMeta.Kind, APIVersion: channelTypeMeta.APIVersion, Name: replyChannelName, Namespace: client.Namespace}})) - - client.CreateFlowsParallelOrFail(parallel) - - client.WaitForAllTestResourcesReadyOrFail() - - // send fake CloudEvent to the Parallel - msg := fmt.Sprintf("TestFlowParallel %s - ", uuid.NewUUID()) - // NOTE: the eventData format must be BaseData, as it needs to be correctly parsed in the stepper service. - eventData := cloudevents.BaseData{Message: msg} - eventDataBytes, err := json.Marshal(eventData) - if err != nil { - t.Fatalf("Failed to convert %v to json: %v", eventData, err) - } - event := cloudevents.New( - string(eventDataBytes), - cloudevents.WithSource(senderPodName), - ) - client.SendFakeEventToAddressableOrFail( - senderPodName, - tc.name, - lib.FlowsParallelTypeMeta, - event) - - // verify the logger service receives the correct transformed event - if err := client.CheckLog(loggerPodName, lib.CheckerContains(tc.expected)); err != nil { - t.Fatalf("String %q not found in logs of logger pod %q: %v", tc.expected, loggerPodName, err) - } - } - +func TestParallel(t *testing.T) { + helpers.ParallelTestHelper(t, channelTestRunner) } diff --git a/test/e2e/sequence_test.go b/test/e2e/sequence_test.go index 1c26b65dcc5..549dd504876 100644 --- a/test/e2e/sequence_test.go +++ b/test/e2e/sequence_test.go @@ -18,129 +18,11 @@ limitations under the License. package e2e import ( - "encoding/json" - "fmt" "testing" - "k8s.io/apimachinery/pkg/util/uuid" - - "knative.dev/eventing/test/lib" - "knative.dev/eventing/test/lib/cloudevents" - "knative.dev/eventing/test/lib/resources" - - "knative.dev/eventing/pkg/apis/flows/v1alpha1" - messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" - eventingtesting "knative.dev/eventing/pkg/reconciler/testing" - - duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/eventing/test/e2e/helpers" ) -func TestFlowsSequence(t *testing.T) { - const ( - sequenceName = "e2e-sequence" - senderPodName = "e2e-sequence-sender-pod" - - channelName = "e2e-sequence-channel" - subscriptionName = "e2e-sequence-subscription" - loggerPodName = "e2e-sequence-logger-pod" - ) - stepSubscriberConfigs := []struct { - podName string - msgAppender string - }{{ - podName: "e2e-stepper1", - msgAppender: "-step1", - }, { - podName: "e2e-stepper2", - msgAppender: "-step2", - }, { - podName: "e2e-stepper3", - msgAppender: "-step3", - }} - channelTypeMeta := &lib.DefaultChannel - - client := setup(t, true) - defer tearDown(client) - - // construct steps for the sequence - steps := make([]v1alpha1.SequenceStep, 0) - for _, config := range stepSubscriberConfigs { - // create a stepper Pod with Service - podName := config.podName - msgAppender := config.msgAppender - stepperPod := resources.SequenceStepperPod(podName, msgAppender) - - client.CreatePodOrFail(stepperPod, lib.WithService(podName)) - // create a new step - step := v1alpha1.SequenceStep{ - Destination: duckv1.Destination{ - Ref: resources.KnativeRefForService(podName, client.Namespace), - }} - // add the step into steps - steps = append(steps, step) - } - - // create channelTemplate for the Sequence - channelTemplate := &messagingv1beta1.ChannelTemplateSpec{ - TypeMeta: *(channelTypeMeta), - } - - // create channel as reply of the Sequence - // TODO(chizhg): now we'll have to use a channel plus its subscription here, as reply of the Sequence - // must be Addressable. In the future if we use Knative Serving in the tests, we can - // make the logger service as a Knative service, and remove the channel and subscription. - client.CreateChannelOrFail(channelName, channelTypeMeta) - // create logger service as the subscriber - loggerPod := resources.EventLoggerPod(loggerPodName) - client.CreatePodOrFail(loggerPod, lib.WithService(loggerPodName)) - // create subscription to subscribe the channel, and forward the received events to the logger service - client.CreateSubscriptionOrFail( - subscriptionName, - channelName, - channelTypeMeta, - resources.WithSubscriberForSubscription(loggerPodName), - ) - replyRef := &duckv1.KReference{Kind: channelTypeMeta.Kind, APIVersion: channelTypeMeta.APIVersion, Name: channelName, Namespace: client.Namespace} - - // create the sequence object - sequence := eventingtesting.NewFlowsSequence( - sequenceName, - client.Namespace, - eventingtesting.WithFlowsSequenceSteps(steps), - eventingtesting.WithFlowsSequenceChannelTemplateSpec(channelTemplate), - eventingtesting.WithFlowsSequenceReply(&duckv1.Destination{Ref: replyRef}), - ) - - // create Sequence or fail the test if there is an error - client.CreateFlowsSequenceOrFail(sequence) - - // wait for all test resources to be ready, so that we can start sending events - client.WaitForAllTestResourcesReadyOrFail() - - // send fake CloudEvent to the Sequence - msg := fmt.Sprintf("TestSequence %s", uuid.NewUUID()) - // NOTE: the eventData format must be BaseData, as it needs to be correctly parsed in the stepper service. - eventData := cloudevents.BaseData{Message: msg} - eventDataBytes, err := json.Marshal(eventData) - if err != nil { - t.Fatalf("Failed to convert %v to json: %v", eventData, err) - } - event := cloudevents.New( - string(eventDataBytes), - cloudevents.WithSource(senderPodName), - ) - client.SendFakeEventToAddressableOrFail( - senderPodName, - sequenceName, - lib.FlowsSequenceTypeMeta, - event) - - // verify the logger service receives the correct transformed event - expectedMsg := msg - for _, config := range stepSubscriberConfigs { - expectedMsg += config.msgAppender - } - if err := client.CheckLog(loggerPodName, lib.CheckerContains(expectedMsg)); err != nil { - t.Fatalf("String %q not found in logs of logger pod %q: %v", expectedMsg, loggerPodName, err) - } +func TestSequence(t *testing.T) { + helpers.SequenceTestHelper(t, channelTestRunner) } diff --git a/vendor/k8s.io/code-generator/generate-groups.sh b/vendor/k8s.io/code-generator/generate-groups.sh old mode 100644 new mode 100755 diff --git a/vendor/knative.dev/pkg/hack/generate-knative.sh b/vendor/knative.dev/pkg/hack/generate-knative.sh old mode 100644 new mode 100755