From fb45ef6b58f2fcfa1a5b201a4ae8c87d17b7004a Mon Sep 17 00:00:00 2001 From: Leo Li Date: Fri, 19 Jul 2024 16:12:21 -0400 Subject: [PATCH 01/26] feat: initial commit Signed-off-by: Leo Li --- .../sequence/resources/eventpolicy.go | 108 ++ pkg/reconciler/sequence/sequence.go | 149 ++ pkg/reconciler/sequence/sequence_test.go | 1315 +---------------- 3 files changed, 296 insertions(+), 1276 deletions(-) create mode 100644 pkg/reconciler/sequence/resources/eventpolicy.go diff --git a/pkg/reconciler/sequence/resources/eventpolicy.go b/pkg/reconciler/sequence/resources/eventpolicy.go new file mode 100644 index 00000000000..b4330239a3c --- /dev/null +++ b/pkg/reconciler/sequence/resources/eventpolicy.go @@ -0,0 +1,108 @@ +/* +Copyright 2024 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 resources + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" + eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" + flowsv1 "knative.dev/eventing/pkg/apis/flows/v1" + messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" + "knative.dev/pkg/kmeta" +) + +const ( + SequenceChannelEventPolicyLabelPrefix = "flows.knative.dev/" + sequenceKind = "Sequence" +) + +func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduckv1.Channelable, subscription *messagingv1.Subscription) *eventingv1alpha1.EventPolicy { + return &eventingv1alpha1.EventPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: channel.Namespace, + Name: SequenceEventPolicyName(s.Name, channel.Name), + OwnerReferences: []metav1.OwnerReference{ + *kmeta.NewControllerRef(s), + }, + Labels: LabelsForSequenceChannelsEventPolicy(s.Name), + }, + Spec: eventingv1alpha1.EventPolicySpec{ + To: []eventingv1alpha1.EventPolicySpecTo{ + { + Ref: &eventingv1alpha1.EventPolicyToReference{ + APIVersion: channel.APIVersion, + Kind: channel.Kind, + Name: channel.Name, + }, + }, + }, + From: []eventingv1alpha1.EventPolicySpecFrom{ + { + Ref: &eventingv1alpha1.EventPolicyFromReference{ + APIVersion: subscription.APIVersion, + Kind: subscription.Kind, + Name: subscription.Name, + Namespace: subscription.Namespace, + }, + }, + }, + }, + } +} + +func LabelsForSequenceChannelsEventPolicy(sequenceName string) map[string]string { + return map[string]string{ + SequenceChannelEventPolicyLabelPrefix + "sequence-group": flowsv1.SchemeGroupVersion.Group, + SequenceChannelEventPolicyLabelPrefix + "sequence-version": flowsv1.SchemeGroupVersion.Version, + SequenceChannelEventPolicyLabelPrefix + "sequence-kind": sequenceKind, + SequenceChannelEventPolicyLabelPrefix + "sequence-name": sequenceName, + } +} + +func SequenceEventPolicyName(sequenceName, channelName string) string { + return kmeta.ChildName(sequenceName, "-ep-"+channelName) +} + +// MakeEventPolicyForSequenceInputChannel creates an EventPolicy for the input channel of a Sequence +func MakeEventPolicyForSequenceInputChannel(s *flowsv1.Sequence, inputChannel *eventingduckv1.Channelable, sequencePolicy *eventingv1alpha1.EventPolicy) *eventingv1alpha1.EventPolicy { + return &eventingv1alpha1.EventPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: inputChannel.Namespace, + Name: SequenceInputEventPolicyName(s.Name), + OwnerReferences: []metav1.OwnerReference{ + *kmeta.NewControllerRef(s), + }, + Labels: LabelsForSequenceChannelsEventPolicy(s.Name), + }, + Spec: eventingv1alpha1.EventPolicySpec{ + To: []eventingv1alpha1.EventPolicySpecTo{ + { + Ref: &eventingv1alpha1.EventPolicyToReference{ + APIVersion: inputChannel.APIVersion, + Kind: inputChannel.Kind, + Name: inputChannel.Name, + }, + }, + }, + From: sequencePolicy.Spec.From, + }, + } +} + +func SequenceInputEventPolicyName(sequenceName string) string { + return kmeta.ChildName(sequenceName, "-input-ep") +} diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 2bedb0510ca..01b28e5ff55 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -22,12 +22,14 @@ import ( "go.uber.org/zap" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" 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/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/dynamic" + eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" "knative.dev/pkg/kmeta" duckapis "knative.dev/pkg/apis/duck" @@ -129,6 +131,11 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, s *v1.Sequence) pkgrecon return err } + // Handle EventPolicies + if err := r.reconcileEventPolicies(ctx, s, channels, subs, featureFlags); err != nil { + return fmt.Errorf("failed to reconcile EventPolicies: %w", err) + } + err := auth.UpdateStatusWithEventPolicies(featureFlags, &s.Status.AppliedEventPoliciesStatus, &s.Status, r.eventPolicyLister, v1.SchemeGroupVersion.WithKind("Sequence"), s.ObjectMeta) if err != nil { return fmt.Errorf("could not update Sequence status with EventPolicies: %v", err) @@ -331,3 +338,145 @@ func (r *Reconciler) removeUnwantedSubscriptions(ctx context.Context, seq *v1.Se return nil } + +func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, channels []*eventingduckv1.Channelable, subs []*messagingv1.Subscription, featureFlags feature.Flags) error { + if featureFlags.IsOIDCAuthentication() { + // Create or update EventPolicies, and we skip the first channel as it's the input channel! + for i := 1; i < len(channels); i++ { + if err := r.reconcileChannelEventPolicy(ctx, s, channels[i], subs[i-1]); err != nil { + return err + } + r.verifyEventPolicyCreation(ctx, &eventingv1alpha1.EventPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-channel-%s", s.Name, channels[i].Name), + Namespace: s.Namespace, + }, + Spec: eventingv1alpha1.EventPolicySpec{ + To: []eventingv1alpha1.EventPolicySpecTo{ + { + Ref: &eventingv1alpha1.EventPolicyToReference{ + APIVersion: channels[i].APIVersion, + Kind: channels[i].Kind, + Name: channels[i].Name, + }, + }, + }, + From: []eventingv1alpha1.EventPolicySpecFrom{ + { + Ref: &eventingv1alpha1.EventPolicyFromReference{ + Kind: "Subscription", + Namespace: subs[i-1].Namespace, + Name: subs[i-1].Name, + APIVersion: subs[i-1].APIVersion, + }, + }, + }, + }, + }) + } + + // Handle input channel EventPolicy + if err := r.reconcileInputChannelEventPolicy(ctx, s, channels[0]); err != nil { + return err + } + + } else { + // Clean up existing EventPolicies, as the authentication feature flag is disabled + if err := r.cleanupEventPolicies(ctx, s); err != nil { + return err + } + } + + return nil +} + +func (r *Reconciler) reconcileChannelEventPolicy(ctx context.Context, s *v1.Sequence, channel *eventingduckv1.Channelable, subscription *messagingv1.Subscription) error { + expected := resources.MakeEventPolicyForSequenceChannel(s, channel, subscription) + + return r.createOrUpdateEventPolicy(ctx, expected) +} +func (r *Reconciler) createOrUpdateEventPolicy(ctx context.Context, expected *eventingv1alpha1.EventPolicy) error { + existing, err := r.eventPolicyLister.EventPolicies(expected.Namespace).Get(expected.Name) + if apierrs.IsNotFound(err) { + _, err = r.eventingClientSet.EventingV1alpha1().EventPolicies(expected.Namespace).Create(ctx, expected, metav1.CreateOptions{}) + return err + } else if err != nil { + return err + } + + // Update if needed + if !equality.Semantic.DeepEqual(existing.Spec, expected.Spec) { + existing.Spec = expected.Spec + _, err = r.eventingClientSet.EventingV1alpha1().EventPolicies(existing.Namespace).Update(ctx, existing, metav1.UpdateOptions{}) + return err + } + + return nil +} + +func (r *Reconciler) reconcileInputChannelEventPolicy(ctx context.Context, s *v1.Sequence, inputChannel *eventingduckv1.Channelable) error { + // Check if there's an EventPolicy for the Sequence + sequencePolicy, err := r.eventPolicyLister.EventPolicies(s.Namespace).Get(s.Name) + if err != nil { + if apierrs.IsNotFound(err) { + // No EventPolicy for the Sequence, so we don't create one for the input channel + return nil + } + return err + } + + expected := &eventingv1alpha1.EventPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-input-channel", s.Name), + Namespace: s.Namespace, + OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(s)}, + }, + Spec: eventingv1alpha1.EventPolicySpec{ + + To: []eventingv1alpha1.EventPolicySpecTo{ + { + Ref: &eventingv1alpha1.EventPolicyToReference{ + APIVersion: inputChannel.APIVersion, + Kind: inputChannel.Kind, + Name: inputChannel.Name, + }, + }, + }, + From: sequencePolicy.Spec.From, + }, + } + + return r.createOrUpdateEventPolicy(ctx, expected) +} + +func (r *Reconciler) cleanupEventPolicies(ctx context.Context, s *v1.Sequence) error { + policies, err := r.eventPolicyLister.EventPolicies(s.Namespace).List(labels.Everything()) + if err != nil { + return err + } + + for _, policy := range policies { + if metav1.IsControlledBy(policy, s) { + err := r.eventingClientSet.EventingV1alpha1().EventPolicies(policy.Namespace).Delete(ctx, policy.Name, metav1.DeleteOptions{}) + if err != nil && !apierrs.IsNotFound(err) { + return err + } + } + } + + return nil +} + +func (r *Reconciler) verifyEventPolicyCreation(ctx context.Context, expected *eventingv1alpha1.EventPolicy) error { + logging.FromContext(ctx).Infof("Verifying EventPolicy creation: %s", expected.Name) + + // Try to get the EventPolicy using the client directly + policy, err := r.eventingClientSet.EventingV1alpha1().EventPolicies(expected.Namespace).Get(ctx, expected.Name, metav1.GetOptions{}) + if err != nil { + logging.FromContext(ctx).Errorf("Failed to get EventPolicy after creation: %v", err) + return err + } + + logging.FromContext(ctx).Infof("Successfully verified EventPolicy creation: %s", policy.Name) + return nil +} diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index 5232672e4cb..45e57470d4f 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -21,6 +21,9 @@ import ( "fmt" "testing" + eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" + "knative.dev/eventing/pkg/apis/feature" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -73,6 +76,12 @@ var ( Version: "v1", Kind: "Sequence", } + + channelV1GVK = metav1.GroupVersionKind{ + Group: "messaging.knative.dev", + Version: "v1", + Kind: "InMemoryChannel", + } ) func createReplyChannel(channelName string) *duckv1.Destination { @@ -150,330 +159,9 @@ func TestAllCases(t *testing.T) { }, Spec: &runtime.RawExtension{Raw: []byte("{}")}, } - differentIMC := &messagingv1.ChannelTemplateSpec{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "messaging.knative.dev/v1", - Kind: "OtherKindOfChannel", - }, - Spec: &runtime.RawExtension{Raw: []byte("{}")}, - } + table := TableTest{{ - Name: "bad workqueue key", - // Make sure Reconcile handles bad keys. - Key: "too/many/parts", - }, { - Name: "key not found", - // Make sure Reconcile handles good keys that don't exist. - Key: "foo/not-found", - }, { - Name: "deleting", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceDeleted)}, - WantErr: false, - }, { - Name: "singlestep", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "singlestep-channelcreatefails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("create", "inmemorychannels"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile channel test-sequence-kn-sequence-0 at step 0: failed to create channel {InMemoryChannel test-namespace test-sequence-kn-sequence-0 messaging.knative.dev/v1 }: inducing failure for create inmemorychannels"), - }, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "failed to reconcile channel test-sequence-kn-sequence-0 at step 0: failed to create channel {InMemoryChannel test-namespace test-sequence-kn-sequence-0 messaging.knative.dev/v1 }: inducing failure for create inmemorychannels")), - }}, - }, { - Name: "singlestep-subscriptioncreatefails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("create", "subscriptions"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), - }, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "singlestep-subscriptiondeletefails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(differentIMC), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})))}, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("delete", "subscriptions"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for delete subscriptions"), - }, - WantCreates: []runtime.Object{createChannel(sequenceName, 0)}, - WantDeletes: []clientgotesting.DeleteActionImpl{{ - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Name: resources.SequenceChannelName(sequenceName, 0), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for delete subscriptions"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "singlestep-subscriptioncreateafterdeletefails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(differentIMC), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})))}, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("create", "subscriptions"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), - }, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantDeletes: []clientgotesting.DeleteActionImpl{{ - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Name: resources.SequenceChannelName(sequenceName, 0), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "singlestepwithreply", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "threestep", + Name: "threestep with AuthZ enabled", Key: pKey, Objects: []runtime.Object{ NewSequence(sequenceName, testNS, @@ -485,6 +173,10 @@ func TestAllCases(t *testing.T) { {Destination: createDestination(1)}, {Destination: createDestination(2)}}))}, WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), WantCreates: []runtime.Object{ createChannel(sequenceName, 0), createChannel(sequenceName, 1), @@ -505,21 +197,26 @@ func TestAllCases(t *testing.T) { NewSequence(sequenceName, testNS, WithSequenceChannelTemplateSpec(imc), WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}})))}, + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewSequence(sequenceName, testNS, WithInitSequenceConditions, WithSequenceGeneration(sequenceGeneration), WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(), WithSequenceChannelTemplateSpec(imc), WithSequenceSteps([]v1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ @@ -609,957 +306,6 @@ func TestAllCases(t *testing.T) { }, })), }}, - }, { - Name: "threestepwithdeliveryontwo", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceGeneration(sequenceGeneration), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, - {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))), - resources.NewSubscription(1, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, {Destination: createDestination(2)}}))), - resources.NewSubscription(2, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}})))}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceGeneration(sequenceGeneration), - WithSequenceStatusObservedGeneration(sequenceGeneration), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, - {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "threestepwithreply", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))), - resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))), - resources.NewSubscription(2, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}})))}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "sequenceupdatesubscription", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}})), - createChannel(sequenceName, 0), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantErr: false, - WantUpdates: []clientgotesting.UpdateActionImpl{{ - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Object: resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}}))), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "sequenceupdate-remove-step", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}})), - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(2, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - }, - WantErr: false, - WantDeletes: []clientgotesting.DeleteActionImpl{ - { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, - }, - WantUpdates: []clientgotesting.UpdateActionImpl{{ - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}, - ))), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "sequenceupdate-remove-step-subscription-removal-fails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}})), - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(2, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - }, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("delete", "subscriptions"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for delete subscriptions"), - }, - - WantDeletes: []clientgotesting.DeleteActionImpl{ - { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, - }, - WantUpdates: []clientgotesting.UpdateActionImpl{{ - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}, - ))), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "sequenceupdate-remove-step-channel-removal-fails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}})), - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(2, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - }, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("delete", "inmemorychannels"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for delete inmemorychannels"), - }, - WantUpdates: []clientgotesting.UpdateActionImpl{{ - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}, - ))), - }}, - - WantDeletes: []clientgotesting.DeleteActionImpl{ - { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "Should provision applying EventPolicies", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - NewEventPolicy(readyEventPolicyName, testNS, - WithReadyEventPolicyCondition, - WithEventPolicyToRef(sequenceGVK, sequenceName), - ), - }, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - }), - WithSequenceEventPoliciesReady(), - WithSequenceEventPoliciesListed(readyEventPolicyName), - ), - }}, - }, { - Name: "Should mark as NotReady on unready EventPolicies", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - NewEventPolicy(unreadyEventPolicyName, testNS, - WithUnreadyEventPolicyCondition("", ""), - WithEventPolicyToRef(sequenceGVK, sequenceName), - ), - }, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - }), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", unreadyEventPolicyName))), - }}, - }, { - Name: "should list only Ready EventPolicies", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - NewEventPolicy(unreadyEventPolicyName, testNS, - WithUnreadyEventPolicyCondition("", ""), - WithEventPolicyToRef(sequenceGVK, sequenceName), - ), - NewEventPolicy(readyEventPolicyName, testNS, - WithReadyEventPolicyCondition, - WithEventPolicyToRef(sequenceGVK, sequenceName), - ), - }, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - }), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", unreadyEventPolicyName)), - WithSequenceEventPoliciesListed(readyEventPolicyName), - ), - }}, }, } @@ -1579,3 +325,20 @@ func TestAllCases(t *testing.T) { controller.GetEventRecorder(ctx), r) }, false, logger)) } + +func makeEventPolicy(sequenceName, channelName string, step int) *eventingv1alpha1.EventPolicy { + return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, channelName), testNS, + WithEventPolicyToRef(channelV1GVK, channelName), + WithEventPolicyFromSub(resources.SequenceSubscriptionName(sequenceName, step-1)), // Previous step's subscription + WithEventPolicyOwnerReferences([]metav1.OwnerReference{ + { + APIVersion: "flows.knative.dev/v1", + Kind: "Sequence", + Name: sequenceName, + }, + + // FIXME: The testing and expected test result have difference in the OwnerReferences field. + }...), + WithEventPolicyLabels(resources.LabelsForSequenceChannelsEventPolicy(sequenceName)), + ) +} From 043141a1aa49c8aa96d54cab302b8c66648839ab Mon Sep 17 00:00:00 2001 From: Leo Li Date: Mon, 22 Jul 2024 21:28:14 -0400 Subject: [PATCH 02/26] feat: add the test for eventpolicy in sequence reconciler Signed-off-by: Leo Li --- .../sequence/resources/eventpolicy.go | 28 +- pkg/reconciler/sequence/sequence.go | 52 +- pkg/reconciler/sequence/sequence_test.go | 2245 ++++++++++++++++- 3 files changed, 2137 insertions(+), 188 deletions(-) diff --git a/pkg/reconciler/sequence/resources/eventpolicy.go b/pkg/reconciler/sequence/resources/eventpolicy.go index b4330239a3c..38e807015b9 100644 --- a/pkg/reconciler/sequence/resources/eventpolicy.go +++ b/pkg/reconciler/sequence/resources/eventpolicy.go @@ -5,7 +5,7 @@ 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 + 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, @@ -36,7 +36,11 @@ func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduc Namespace: channel.Namespace, Name: SequenceEventPolicyName(s.Name, channel.Name), OwnerReferences: []metav1.OwnerReference{ - *kmeta.NewControllerRef(s), + { + APIVersion: flowsv1.SchemeGroupVersion.String(), + Kind: sequenceKind, + Name: s.Name, + }, }, Labels: LabelsForSequenceChannelsEventPolicy(s.Name), }, @@ -74,7 +78,13 @@ func LabelsForSequenceChannelsEventPolicy(sequenceName string) map[string]string } func SequenceEventPolicyName(sequenceName, channelName string) string { - return kmeta.ChildName(sequenceName, "-ep-"+channelName) + // if channel name is empty, it means the event policy is for the output channel + if channelName == "" { + return kmeta.ChildName(sequenceName, "-ep") // no need to add the channel name + } else { + return kmeta.ChildName(sequenceName, "-ep-"+channelName) + } + } // MakeEventPolicyForSequenceInputChannel creates an EventPolicy for the input channel of a Sequence @@ -82,9 +92,13 @@ func MakeEventPolicyForSequenceInputChannel(s *flowsv1.Sequence, inputChannel *e return &eventingv1alpha1.EventPolicy{ ObjectMeta: metav1.ObjectMeta{ Namespace: inputChannel.Namespace, - Name: SequenceInputEventPolicyName(s.Name), + Name: SequenceEventPolicyName(s.Name, inputChannel.Name), OwnerReferences: []metav1.OwnerReference{ - *kmeta.NewControllerRef(s), + { + APIVersion: flowsv1.SchemeGroupVersion.String(), + Kind: sequenceKind, + Name: s.Name, + }, }, Labels: LabelsForSequenceChannelsEventPolicy(s.Name), }, @@ -102,7 +116,3 @@ func MakeEventPolicyForSequenceInputChannel(s *flowsv1.Sequence, inputChannel *e }, } } - -func SequenceInputEventPolicyName(sequenceName string) string { - return kmeta.ChildName(sequenceName, "-input-ep") -} diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 01b28e5ff55..e8cc6d10aeb 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -193,7 +193,7 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, step int, p *v1. subName := resources.SequenceSubscriptionName(p.Name, step) sub, err := r.subscriptionLister.Subscriptions(p.Namespace).Get(subName) - // If the resource doesn't exist, we'll create it. + // If the resource doesn't exist, we'll create itF. if apierrs.IsNotFound(err) { sub = expected logging.FromContext(ctx).Infof("Creating subscription: %+v", sub) @@ -346,33 +346,6 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, if err := r.reconcileChannelEventPolicy(ctx, s, channels[i], subs[i-1]); err != nil { return err } - r.verifyEventPolicyCreation(ctx, &eventingv1alpha1.EventPolicy{ - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-channel-%s", s.Name, channels[i].Name), - Namespace: s.Namespace, - }, - Spec: eventingv1alpha1.EventPolicySpec{ - To: []eventingv1alpha1.EventPolicySpecTo{ - { - Ref: &eventingv1alpha1.EventPolicyToReference{ - APIVersion: channels[i].APIVersion, - Kind: channels[i].Kind, - Name: channels[i].Name, - }, - }, - }, - From: []eventingv1alpha1.EventPolicySpecFrom{ - { - Ref: &eventingv1alpha1.EventPolicyFromReference{ - Kind: "Subscription", - Namespace: subs[i-1].Namespace, - Name: subs[i-1].Name, - APIVersion: subs[i-1].APIVersion, - }, - }, - }, - }, - }) } // Handle input channel EventPolicy @@ -416,7 +389,7 @@ func (r *Reconciler) createOrUpdateEventPolicy(ctx context.Context, expected *ev func (r *Reconciler) reconcileInputChannelEventPolicy(ctx context.Context, s *v1.Sequence, inputChannel *eventingduckv1.Channelable) error { // Check if there's an EventPolicy for the Sequence - sequencePolicy, err := r.eventPolicyLister.EventPolicies(s.Namespace).Get(s.Name) + sequencePolicy, err := r.eventPolicyLister.EventPolicies(s.Namespace).Get(s.Name + "-ep") if err != nil { if apierrs.IsNotFound(err) { // No EventPolicy for the Sequence, so we don't create one for the input channel @@ -425,26 +398,7 @@ func (r *Reconciler) reconcileInputChannelEventPolicy(ctx context.Context, s *v1 return err } - expected := &eventingv1alpha1.EventPolicy{ - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-input-channel", s.Name), - Namespace: s.Namespace, - OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(s)}, - }, - Spec: eventingv1alpha1.EventPolicySpec{ - - To: []eventingv1alpha1.EventPolicySpecTo{ - { - Ref: &eventingv1alpha1.EventPolicyToReference{ - APIVersion: inputChannel.APIVersion, - Kind: inputChannel.Kind, - Name: inputChannel.Name, - }, - }, - }, - From: sequencePolicy.Spec.From, - }, - } + expected := resources.MakeEventPolicyForSequenceInputChannel(s, inputChannel, sequencePolicy) return r.createOrUpdateEventPolicy(ctx, expected) } diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index 45e57470d4f..d5a92a0fdf8 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -68,7 +68,7 @@ var ( subscriberGVK = metav1.GroupVersionKind{ Group: "messaging.knative.dev", Version: "v1", - Kind: "Subscriber", + Kind: "Subscription", } sequenceGVK = metav1.GroupVersionKind{ @@ -159,154 +159,2111 @@ func TestAllCases(t *testing.T) { }, Spec: &runtime.RawExtension{Raw: []byte("{}")}, } + differentIMC := &messagingv1.ChannelTemplateSpec{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "messaging.knative.dev/v1", + Kind: "OtherKindOfChannel", + }, + Spec: &runtime.RawExtension{Raw: []byte("{}")}, + } - table := TableTest{{ - Name: "threestep with AuthZ enabled", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceGeneration(sequenceGeneration), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))}, - WantErr: false, - Ctx: feature.ToContext(context.Background(), feature.Flags{ - feature.OIDCAuthentication: feature.Enabled, - feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, - }), - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, + table := TableTest{ + { + Name: "bad workqueue key", + // Make sure Reconcile handles bad keys. + Key: "too/many/parts", + }, { + Name: "key not found", + // Make sure Reconcile handles good keys that don't exist. + Key: "foo/not-found", + }, { + Name: "deleting", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceDeleted)}, + WantErr: false, + }, { + Name: "singlestep", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "singlestep-channelcreatefails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("create", "inmemorychannels"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile channel test-sequence-kn-sequence-0 at step 0: failed to create channel {InMemoryChannel test-namespace test-sequence-kn-sequence-0 messaging.knative.dev/v1 }: inducing failure for create inmemorychannels"), + }, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "failed to reconcile channel test-sequence-kn-sequence-0 at step 0: failed to create channel {InMemoryChannel test-namespace test-sequence-kn-sequence-0 messaging.knative.dev/v1 }: inducing failure for create inmemorychannels")), + }}, + }, { + Name: "singlestep-subscriptioncreatefails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("create", "subscriptions"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + }, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "singlestep-subscriptiondeletefails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(differentIMC), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})))}, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("delete", "subscriptions"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for delete subscriptions"), + }, + WantCreates: []runtime.Object{createChannel(sequenceName, 0)}, + WantDeletes: []clientgotesting.DeleteActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Name: resources.SequenceChannelName(sequenceName, 0), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for delete subscriptions"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "singlestep-subscriptioncreateafterdeletefails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(differentIMC), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})))}, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("create", "subscriptions"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + }, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantDeletes: []clientgotesting.DeleteActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Name: resources.SequenceChannelName(sequenceName, 0), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "singlestepwithreply", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "threestep", + Key: pKey, + Objects: []runtime.Object{ NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), WithSequenceChannelTemplateSpec(imc), WithSequenceSteps([]v1.SequenceStep{ {Destination: createDestination(0)}, {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))), - resources.NewSubscription(1, + {Destination: createDestination(2)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(1, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), + resources.NewSubscription(2, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}})))}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "threestepwithdeliveryontwo", + Key: pKey, + Objects: []runtime.Object{ NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), WithSequenceChannelTemplateSpec(imc), WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), - resources.NewSubscription(2, + {Destination: createDestination(0)}, + {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, + {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(1, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, {Destination: createDestination(2)}}))), + resources.NewSubscription(2, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}})))}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, + {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "threestepwithreply", + Key: pKey, + Objects: []runtime.Object{ NewSequence(sequenceName, testNS, + WithInitSequenceConditions, WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), - makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceGeneration(sequenceGeneration), - WithSequenceStatusObservedGeneration(sequenceGeneration), - WithSequenceEventPoliciesReady(), - WithSequenceEventPoliciesListed(), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}), - - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}})))}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "sequenceupdatesubscription", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantErr: false, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}}))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, }, + })), + }}, + }, { + Name: "sequenceupdate-remove-step", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + }, + WantErr: false, + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", + Name: resources.SequenceChannelName(sequenceName, 2), + }, { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), + }, + Name: resources.SequenceChannelName(sequenceName, 2), + }, + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}, + ))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "sequenceupdate-remove-step-subscription-removal-fails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + }, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("delete", "subscriptions"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for delete subscriptions"), + }, + + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", + Name: resources.SequenceChannelName(sequenceName, 2), + }, { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), + }, + Name: resources.SequenceChannelName(sequenceName, 2), + }, + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}, + ))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "sequenceupdate-remove-step-channel-removal-fails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + }, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("delete", "inmemorychannels"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for delete inmemorychannels"), + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}, + ))), + }}, + + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), }, - })), - }}, - }, + Name: resources.SequenceChannelName(sequenceName, 2), + }, + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "Should provision applying EventPolicies", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + NewEventPolicy(readyEventPolicyName, testNS, + WithReadyEventPolicyCondition, + WithEventPolicyToRef(sequenceGVK, sequenceName), + ), + }, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + }), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(readyEventPolicyName), + ), + }}, + }, { + Name: "Should mark as NotReady on unready EventPolicies", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + NewEventPolicy(unreadyEventPolicyName, testNS, + WithUnreadyEventPolicyCondition("", ""), + WithEventPolicyToRef(sequenceGVK, sequenceName), + ), + }, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + }), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", unreadyEventPolicyName))), + }}, + }, { + Name: "should list only Ready EventPolicies", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + NewEventPolicy(unreadyEventPolicyName, testNS, + WithUnreadyEventPolicyCondition("", ""), + WithEventPolicyToRef(sequenceGVK, sequenceName), + ), + NewEventPolicy(readyEventPolicyName, testNS, + WithReadyEventPolicyCondition, + WithEventPolicyToRef(sequenceGVK, sequenceName), + ), + }, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + }), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", unreadyEventPolicyName)), + WithSequenceEventPoliciesListed(readyEventPolicyName), + ), + }}, + }, + + { + Name: "threestep with AuthZ enabled, and sequence doesn't have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))}, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(1, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), + resources.NewSubscription(2, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 2), 2), + // make the eventpolicy for the sequence + + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}), + + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + + { + Name: "threestep with AuthZ enabled, and sequence has event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}})), + makeSequenceEventPolicy(sequenceName), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(1, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), + resources.NewSubscription(2, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), + + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 2), 2), + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0)), + + // make the eventpolicy for the sequence + + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}), + + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + + { + Name: "2 steps with AuthZ enabled, and sequence doesn't have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}))}, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}))), + resources.NewSubscription(1, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}}))), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + // make the eventpolicy for the sequence + + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "2 steps with AuthZ enabled, and sequence has event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + makeSequenceEventPolicy(sequenceName), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}))), + resources.NewSubscription(1, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}}))), + + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0)), + + // make the eventpolicy for the sequence + + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + + { + Name: "1 steps with AuthZ enabled, and sequence doesn't have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}))}, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}), + + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "1 steps with AuthZ enabled, and sequence has event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}})), + makeSequenceEventPolicy(sequenceName), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}))), + + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0)), + + // make the eventpolicy for the sequence + + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}), + + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, } logger := logtesting.TestLogger(t) @@ -329,15 +2286,43 @@ func TestAllCases(t *testing.T) { func makeEventPolicy(sequenceName, channelName string, step int) *eventingv1alpha1.EventPolicy { return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, channelName), testNS, WithEventPolicyToRef(channelV1GVK, channelName), - WithEventPolicyFromSub(resources.SequenceSubscriptionName(sequenceName, step-1)), // Previous step's subscription + // from a subscription + WithEventPolicyFrom(subscriberGVK, resources.SequenceSubscriptionName(sequenceName, step-1), testNS), WithEventPolicyOwnerReferences([]metav1.OwnerReference{ { APIVersion: "flows.knative.dev/v1", Kind: "Sequence", Name: sequenceName, }, + }...), + WithEventPolicyLabels(resources.LabelsForSequenceChannelsEventPolicy(sequenceName)), + ) +} - // FIXME: The testing and expected test result have difference in the OwnerReferences field. +// Write a function to make the event policy for the sequence +func makeSequenceEventPolicy(sequenceName string) *eventingv1alpha1.EventPolicy { + return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, ""), testNS, + // from a subscription + WithEventPolicyOwnerReferences([]metav1.OwnerReference{ + { + APIVersion: "flows.knative.dev/v1", + Kind: "Sequence", + Name: sequenceName, + }, + }...), + ) +} + +func makeInputChannelEventPolicy(sequenceName, channelName string) *eventingv1alpha1.EventPolicy { + return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, channelName), testNS, + WithEventPolicyToRef(channelV1GVK, channelName), + // from a subscription + WithEventPolicyOwnerReferences([]metav1.OwnerReference{ + { + APIVersion: "flows.knative.dev/v1", + Kind: "Sequence", + Name: sequenceName, + }, }...), WithEventPolicyLabels(resources.LabelsForSequenceChannelsEventPolicy(sequenceName)), ) From 2c99a12e2f72d605a773a63dcba5f054c9aeb90c Mon Sep 17 00:00:00 2001 From: Leo Li Date: Mon, 22 Jul 2024 21:38:58 -0400 Subject: [PATCH 03/26] fix: fix the typo and remove the unused helper function Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index e8cc6d10aeb..b15ee87ad56 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -193,7 +193,7 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, step int, p *v1. subName := resources.SequenceSubscriptionName(p.Name, step) sub, err := r.subscriptionLister.Subscriptions(p.Namespace).Get(subName) - // If the resource doesn't exist, we'll create itF. + // If the resource doesn't exist, we'll create it. if apierrs.IsNotFound(err) { sub = expected logging.FromContext(ctx).Infof("Creating subscription: %+v", sub) @@ -420,17 +420,3 @@ func (r *Reconciler) cleanupEventPolicies(ctx context.Context, s *v1.Sequence) e return nil } - -func (r *Reconciler) verifyEventPolicyCreation(ctx context.Context, expected *eventingv1alpha1.EventPolicy) error { - logging.FromContext(ctx).Infof("Verifying EventPolicy creation: %s", expected.Name) - - // Try to get the EventPolicy using the client directly - policy, err := r.eventingClientSet.EventingV1alpha1().EventPolicies(expected.Namespace).Get(ctx, expected.Name, metav1.GetOptions{}) - if err != nil { - logging.FromContext(ctx).Errorf("Failed to get EventPolicy after creation: %v", err) - return err - } - - logging.FromContext(ctx).Infof("Successfully verified EventPolicy creation: %s", policy.Name) - return nil -} From 169676925819c672755b7b9f8447ee7dff4f7fab Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 24 Jul 2024 15:43:52 -0400 Subject: [PATCH 04/26] fix: trying to fix the git diff issue Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index d5a92a0fdf8..a16d3bebc3e 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -166,9 +166,7 @@ func TestAllCases(t *testing.T) { }, Spec: &runtime.RawExtension{Raw: []byte("{}")}, } - - table := TableTest{ - { + table := TableTest{{ Name: "bad workqueue key", // Make sure Reconcile handles bad keys. Key: "too/many/parts", From 0adb907f45e65183dfefbcfba0ff409bd2edf5d2 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 24 Jul 2024 15:45:08 -0400 Subject: [PATCH 05/26] fix: trying to fix the git diff issue Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence_test.go | 2700 +++++++++++----------- 1 file changed, 1350 insertions(+), 1350 deletions(-) diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index a16d3bebc3e..3e5464f15fe 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -167,1409 +167,1409 @@ func TestAllCases(t *testing.T) { Spec: &runtime.RawExtension{Raw: []byte("{}")}, } table := TableTest{{ - Name: "bad workqueue key", - // Make sure Reconcile handles bad keys. - Key: "too/many/parts", - }, { - Name: "key not found", - // Make sure Reconcile handles good keys that don't exist. - Key: "foo/not-found", - }, { - Name: "deleting", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceDeleted)}, - WantErr: false, - }, { - Name: "singlestep", - Key: pKey, - Objects: []runtime.Object{ + Name: "bad workqueue key", + // Make sure Reconcile handles bad keys. + Key: "too/many/parts", + }, { + Name: "key not found", + // Make sure Reconcile handles good keys that don't exist. + Key: "foo/not-found", + }, { + Name: "deleting", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceDeleted)}, + WantErr: false, + }, { + Name: "singlestep", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", }, - })), - }}, - }, { - Name: "singlestep-channelcreatefails", - Key: pKey, - Objects: []runtime.Object{ + }, + })), + }}, + }, { + Name: "singlestep-channelcreatefails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("create", "inmemorychannels"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile channel test-sequence-kn-sequence-0 at step 0: failed to create channel {InMemoryChannel test-namespace test-sequence-kn-sequence-0 messaging.knative.dev/v1 }: inducing failure for create inmemorychannels"), + }, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "failed to reconcile channel test-sequence-kn-sequence-0 at step 0: failed to create channel {InMemoryChannel test-namespace test-sequence-kn-sequence-0 messaging.knative.dev/v1 }: inducing failure for create inmemorychannels")), + }}, + }, { + Name: "singlestep-subscriptioncreatefails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("create", "subscriptions"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + }, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithInitSequenceConditions, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("create", "inmemorychannels"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile channel test-sequence-kn-sequence-0 at step 0: failed to create channel {InMemoryChannel test-namespace test-sequence-kn-sequence-0 messaging.knative.dev/v1 }: inducing failure for create inmemorychannels"), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "singlestep-subscriptiondeletefails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(differentIMC), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})))}, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("delete", "subscriptions"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for delete subscriptions"), + }, + WantCreates: []runtime.Object{createChannel(sequenceName, 0)}, + WantDeletes: []clientgotesting.DeleteActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), + Name: resources.SequenceChannelName(sequenceName, 0), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for delete subscriptions"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "singlestep-subscriptioncreateafterdeletefails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(differentIMC), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})))}, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("create", "subscriptions"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + }, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantDeletes: []clientgotesting.DeleteActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, + Name: resources.SequenceChannelName(sequenceName, 0), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "singlestepwithreply", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "threestep", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, + NewSequence(sequenceName, testNS, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "failed to reconcile channel test-sequence-kn-sequence-0 at step 0: failed to create channel {InMemoryChannel test-namespace test-sequence-kn-sequence-0 messaging.knative.dev/v1 }: inducing failure for create inmemorychannels")), - }}, - }, { - Name: "singlestep-subscriptioncreatefails", - Key: pKey, - Objects: []runtime.Object{ + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithInitSequenceConditions, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("create", "subscriptions"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), - }, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), + resources.NewSubscription(2, + NewSequence(sequenceName, testNS, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}})))}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", }, - })), - }}, - }, { - Name: "singlestep-subscriptiondeletefails", - Key: pKey, - Objects: []runtime.Object{ + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "threestepwithdeliveryontwo", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, + {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithInitSequenceConditions, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(differentIMC), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})))}, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("delete", "subscriptions"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for delete subscriptions"), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(1, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, {Destination: createDestination(2)}}))), + resources.NewSubscription(2, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}})))}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceGeneration(sequenceGeneration), + WithSequenceStatusObservedGeneration(sequenceGeneration), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, + {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "threestepwithreply", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))}, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}})))}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceReply(createReplyChannel(replyChannelName)), + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "sequenceupdatesubscription", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantErr: false, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - WantCreates: []runtime.Object{createChannel(sequenceName, 0)}, - WantDeletes: []clientgotesting.DeleteActionImpl{{ + Object: resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}}))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "sequenceupdate-remove-step", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + }, + WantErr: false, + WantDeletes: []clientgotesting.DeleteActionImpl{ + { ActionImpl: clientgotesting.ActionImpl{ Namespace: testNS, Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - Name: resources.SequenceChannelName(sequenceName, 0), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for delete subscriptions"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "singlestep-subscriptioncreateafterdeletefails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(differentIMC), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})))}, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("create", "subscriptions"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), + Name: resources.SequenceChannelName(sequenceName, 2), + }, { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), + }, + Name: resources.SequenceChannelName(sequenceName, 2), }, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - WantDeletes: []clientgotesting.DeleteActionImpl{{ + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}, + ))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "sequenceupdate-remove-step-subscription-removal-fails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + }, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("delete", "subscriptions"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for delete subscriptions"), + }, + + WantDeletes: []clientgotesting.DeleteActionImpl{ + { ActionImpl: clientgotesting.ActionImpl{ Namespace: testNS, Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - Name: resources.SequenceChannelName(sequenceName, 0), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "failed to reconcile subscription resource for step: 0 : inducing failure for create subscriptions"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "singlestepwithreply", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "threestep", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceGeneration(sequenceGeneration), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))), - resources.NewSubscription(1, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}}))), - resources.NewSubscription(2, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2)}})))}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceGeneration(sequenceGeneration), - WithSequenceStatusObservedGeneration(sequenceGeneration), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "threestepwithdeliveryontwo", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceGeneration(sequenceGeneration), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, - {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))), - resources.NewSubscription(1, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, {Destination: createDestination(2)}}))), - resources.NewSubscription(2, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, {Destination: createDestination(1)}, {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}})))}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceGeneration(sequenceGeneration), - WithSequenceStatusObservedGeneration(sequenceGeneration), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1), Delivery: createDelivery(subscriberGVK, "dlc1", testNS)}, - {Destination: createDestination(2), Delivery: createDelivery(subscriberGVK, "dlc2", testNS)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "threestepwithreply", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))}, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))), - resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}))), - resources.NewSubscription(2, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}})))}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceReply(createReplyChannel(replyChannelName)), - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 2), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "sequenceupdatesubscription", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}})), - createChannel(sequenceName, 0), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantErr: false, - WantUpdates: []clientgotesting.UpdateActionImpl{{ - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Object: resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}}))), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(1)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "sequenceupdate-remove-step", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}})), - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(2, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - }, - WantErr: false, - WantDeletes: []clientgotesting.DeleteActionImpl{ - { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, - }, - WantUpdates: []clientgotesting.UpdateActionImpl{{ + Name: resources.SequenceChannelName(sequenceName, 2), + }, { ActionImpl: clientgotesting.ActionImpl{ Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), }, - Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}, - ))), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - })), - }}, - }, { - Name: "sequenceupdate-remove-step-subscription-removal-fails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}})), - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(2, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - }, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("delete", "subscriptions"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for delete subscriptions"), + Name: resources.SequenceChannelName(sequenceName, 2), }, - - WantDeletes: []clientgotesting.DeleteActionImpl{ - { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), - }, + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - WantUpdates: []clientgotesting.UpdateActionImpl{{ - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}, - ))), - }}, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, - }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, - }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}, + ))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseOIDCDisabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", }, - })), - }}, - }, { - Name: "sequenceupdate-remove-step-channel-removal-fails", - Key: pKey, - Objects: []runtime.Object{ - NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}})), - createChannel(sequenceName, 0), - createChannel(sequenceName, 1), - createChannel(sequenceName, 2), - resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - resources.NewSubscription(2, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}, - {Destination: createDestination(2)}, - }))), - }, - WantErr: true, - WithReactors: []clientgotesting.ReactionFunc{ - InduceFailure("delete", "inmemorychannels"), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for delete inmemorychannels"), + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, { + Name: "sequenceupdate-remove-step-channel-removal-fails", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + }, + WantErr: true, + WithReactors: []clientgotesting.ReactionFunc{ + InduceFailure("delete", "inmemorychannels"), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for delete inmemorychannels"), + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), }, - WantUpdates: []clientgotesting.UpdateActionImpl{{ + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}, + ))), + }}, + + WantDeletes: []clientgotesting.DeleteActionImpl{ + { ActionImpl: clientgotesting.ActionImpl{ Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), - }, - Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}, - ))), - }}, - - WantDeletes: []clientgotesting.DeleteActionImpl{ - { - ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, - Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), - }, - Name: resources.SequenceChannelName(sequenceName, 2), + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), }, + Name: resources.SequenceChannelName(sequenceName, 2), }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{ - {Destination: createDestination(0)}, - {Destination: createDestination(1)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", }, - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", }, - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 1), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", }, - })), - }}, - }, { - Name: "Should provision applying EventPolicies", - Key: pKey, - Objects: []runtime.Object{ + }, + })), + }}, + }, { + Name: "Should provision applying EventPolicies", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + NewEventPolicy(readyEventPolicyName, testNS, + WithReadyEventPolicyCondition, + WithEventPolicyToRef(sequenceGVK, sequenceName), + ), + }, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithInitSequenceConditions, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - NewEventPolicy(readyEventPolicyName, testNS, - WithReadyEventPolicyCondition, - WithEventPolicyToRef(sequenceGVK, sequenceName), - ), - }, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", }, - }), - WithSequenceEventPoliciesReady(), - WithSequenceEventPoliciesListed(readyEventPolicyName), - ), - }}, - }, { - Name: "Should mark as NotReady on unready EventPolicies", - Key: pKey, - Objects: []runtime.Object{ + }, + }), + WithSequenceEventPoliciesReady(), + WithSequenceEventPoliciesListed(readyEventPolicyName), + ), + }}, + }, { + Name: "Should mark as NotReady on unready EventPolicies", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + NewEventPolicy(unreadyEventPolicyName, testNS, + WithUnreadyEventPolicyCondition("", ""), + WithEventPolicyToRef(sequenceGVK, sequenceName), + ), + }, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - NewEventPolicy(unreadyEventPolicyName, testNS, - WithUnreadyEventPolicyCondition("", ""), - WithEventPolicyToRef(sequenceGVK, sequenceName), - ), - }, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", }, - }), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", unreadyEventPolicyName))), - }}, - }, { - Name: "should list only Ready EventPolicies", - Key: pKey, - Objects: []runtime.Object{ + }, + }), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", unreadyEventPolicyName))), + }}, + }, { + Name: "should list only Ready EventPolicies", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), + NewEventPolicy(unreadyEventPolicyName, testNS, + WithUnreadyEventPolicyCondition("", ""), + WithEventPolicyToRef(sequenceGVK, sequenceName), + ), + NewEventPolicy(readyEventPolicyName, testNS, + WithReadyEventPolicyCondition, + WithEventPolicyToRef(sequenceGVK, sequenceName), + ), + }, + WantErr: false, + WantCreates: []runtime.Object{ + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, - WithInitSequenceConditions, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}})), - NewEventPolicy(unreadyEventPolicyName, testNS, - WithUnreadyEventPolicyCondition("", ""), - WithEventPolicyToRef(sequenceGVK, sequenceName), - ), - NewEventPolicy(readyEventPolicyName, testNS, - WithReadyEventPolicyCondition, - WithEventPolicyToRef(sequenceGVK, sequenceName), - ), - }, - WantErr: false, - WantCreates: []runtime.Object{ - createChannel(sequenceName, 0), - resources.NewSubscription(0, - NewSequence(sequenceName, testNS, - WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSequence(sequenceName, testNS, - WithInitSequenceConditions, WithSequenceChannelTemplateSpec(imc), - WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), - WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), - WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ - { - Channel: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", - Name: resources.SequenceChannelName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Channel does not have Ready condition", - }, + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}))), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{{Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", }, - }), - WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ - { - Subscription: corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", - Name: resources.SequenceSubscriptionName(sequenceName, 0), - Namespace: testNS, - }, - ReadyCondition: apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - Reason: "NoReady", - Message: "Subscription does not have Ready condition", - }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", }, - }), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", unreadyEventPolicyName)), - WithSequenceEventPoliciesListed(readyEventPolicyName), - ), - }}, - }, + }, + }), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", unreadyEventPolicyName)), + WithSequenceEventPoliciesListed(readyEventPolicyName), + ), + }}, + }, { Name: "threestep with AuthZ enabled, and sequence doesn't have event policy", From e82a1dba0001cb1874ebc9148796e56564fbff96 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 24 Jul 2024 15:54:38 -0400 Subject: [PATCH 06/26] fix: fix the nit minor comments Signed-off-by: Leo Li --- pkg/reconciler/sequence/resources/eventpolicy.go | 3 --- pkg/reconciler/sequence/sequence.go | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/reconciler/sequence/resources/eventpolicy.go b/pkg/reconciler/sequence/resources/eventpolicy.go index 38e807015b9..b93eb42e691 100644 --- a/pkg/reconciler/sequence/resources/eventpolicy.go +++ b/pkg/reconciler/sequence/resources/eventpolicy.go @@ -70,9 +70,6 @@ func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduc func LabelsForSequenceChannelsEventPolicy(sequenceName string) map[string]string { return map[string]string{ - SequenceChannelEventPolicyLabelPrefix + "sequence-group": flowsv1.SchemeGroupVersion.Group, - SequenceChannelEventPolicyLabelPrefix + "sequence-version": flowsv1.SchemeGroupVersion.Version, - SequenceChannelEventPolicyLabelPrefix + "sequence-kind": sequenceKind, SequenceChannelEventPolicyLabelPrefix + "sequence-name": sequenceName, } } diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index b15ee87ad56..769bc42bd15 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -29,7 +29,6 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/dynamic" - eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" "knative.dev/pkg/kmeta" duckapis "knative.dev/pkg/apis/duck" @@ -37,6 +36,7 @@ import ( pkgreconciler "knative.dev/pkg/reconciler" eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" + eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" "knative.dev/eventing/pkg/apis/feature" v1 "knative.dev/eventing/pkg/apis/flows/v1" messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" From 5e73f536ea7fa9908bc7dec77ee8165bfa3e8818 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 24 Jul 2024 16:29:33 -0400 Subject: [PATCH 07/26] fix: update the reconcilation mechanism Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence.go | 158 ++++++++++++++++++++-------- 1 file changed, 114 insertions(+), 44 deletions(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 769bc42bd15..11966a68055 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -340,29 +340,133 @@ func (r *Reconciler) removeUnwantedSubscriptions(ctx context.Context, seq *v1.Se } func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, channels []*eventingduckv1.Channelable, subs []*messagingv1.Subscription, featureFlags feature.Flags) error { - if featureFlags.IsOIDCAuthentication() { - // Create or update EventPolicies, and we skip the first channel as it's the input channel! - for i := 1; i < len(channels); i++ { - if err := r.reconcileChannelEventPolicy(ctx, s, channels[i], subs[i-1]); err != nil { - return err + if !featureFlags.IsOIDCAuthentication() { + return r.cleanupAllEventPolicies(ctx, s) + } + + // List all existing EventPolicies for this Sequence + existingPolicies, err := r.listEventPoliciesForSequence(ctx, s) + if err != nil { + return fmt.Errorf("failed to list existing EventPolicies: %w", err) + } + + // Prepare maps for lookups + existingPolicyMap := make(map[string]*eventingv1alpha1.EventPolicy) + for _, policy := range existingPolicies { + existingPolicyMap[policy.Name] = policy + } + + // Prepare lists for different actions + var policiesToUpdate, policiesToCreate, policiesToDelete []*eventingv1alpha1.EventPolicy + + // Handle intermediate channel policies (skip the first channel as it's the input channel!) + for i := 1; i < len(channels); i++ { + expectedPolicy := resources.MakeEventPolicyForSequenceChannel(s, channels[i], subs[i-1]) + existingPolicy, exists := existingPolicyMap[expectedPolicy.Name] + + if exists { + if !equality.Semantic.DeepEqual(existingPolicy.Spec, expectedPolicy.Spec) { + policiesToUpdate = append(policiesToUpdate, expectedPolicy) } + delete(existingPolicyMap, expectedPolicy.Name) + } else { + policiesToCreate = append(policiesToCreate, expectedPolicy) + } + } + + // Handle input channel policy + inputPolicy, err := r.prepareInputChannelEventPolicy(ctx, s, channels[0]) + if err != nil { + return fmt.Errorf("failed to prepare input channel EventPolicy: %w", err) + } + if inputPolicy != nil { + // The sequence has the event policy, so we are creating the event policy for the input channel + existingInputPolicy, exists := existingPolicyMap[inputPolicy.Name] + if exists { + if !equality.Semantic.DeepEqual(existingInputPolicy.Spec, inputPolicy.Spec) { + policiesToUpdate = append(policiesToUpdate, inputPolicy) + } + delete(existingPolicyMap, inputPolicy.Name) + } else { + policiesToCreate = append(policiesToCreate, inputPolicy) + } + } + + // Any remaining policies in the map should be deleted + for _, policy := range existingPolicyMap { + policiesToDelete = append(policiesToDelete, policy) + } + + // Perform the actual CRUD operations + if err := r.createEventPolicies(ctx, policiesToCreate); err != nil { + return fmt.Errorf("failed to create EventPolicies: %w", err) + } + if err := r.updateEventPolicies(ctx, policiesToUpdate); err != nil { + return fmt.Errorf("failed to update EventPolicies: %w", err) + } + if err := r.deleteEventPolicies(ctx, policiesToDelete); err != nil { + return fmt.Errorf("failed to delete EventPolicies: %w", err) + } + + return nil +} + +func (r *Reconciler) listEventPoliciesForSequence(ctx context.Context, s *v1.Sequence) ([]*eventingv1alpha1.EventPolicy, error) { + labelSelector := labels.SelectorFromSet(map[string]string{ + resources.SequenceChannelEventPolicyLabelPrefix + "sequence-name": s.Name, + }) + return r.eventPolicyLister.EventPolicies(s.Namespace).List(labelSelector) +} + +func (r *Reconciler) prepareInputChannelEventPolicy(ctx context.Context, s *v1.Sequence, inputChannel *eventingduckv1.Channelable) (*eventingv1alpha1.EventPolicy, error) { + // Trying to see whether the user manually created the eventpolicy for the sequence + sequencePolicy, err := r.eventPolicyLister.EventPolicies(s.Namespace).Get(s.Name + "-ep") + if err != nil { + if apierrs.IsNotFound(err) { + return nil, nil // No EventPolicy for the Sequence, so we don't create one for the input channel } + return nil, err + } + return resources.MakeEventPolicyForSequenceInputChannel(s, inputChannel, sequencePolicy), nil +} - // Handle input channel EventPolicy - if err := r.reconcileInputChannelEventPolicy(ctx, s, channels[0]); err != nil { +func (r *Reconciler) createEventPolicies(ctx context.Context, policies []*eventingv1alpha1.EventPolicy) error { + for _, policy := range policies { + _, err := r.eventingClientSet.EventingV1alpha1().EventPolicies(policy.Namespace).Create(ctx, policy, metav1.CreateOptions{}) + if err != nil { return err } + } + return nil +} - } else { - // Clean up existing EventPolicies, as the authentication feature flag is disabled - if err := r.cleanupEventPolicies(ctx, s); err != nil { +func (r *Reconciler) updateEventPolicies(ctx context.Context, policies []*eventingv1alpha1.EventPolicy) error { + for _, policy := range policies { + _, err := r.eventingClientSet.EventingV1alpha1().EventPolicies(policy.Namespace).Update(ctx, policy, metav1.UpdateOptions{}) + if err != nil { return err } } + return nil +} +func (r *Reconciler) deleteEventPolicies(ctx context.Context, policies []*eventingv1alpha1.EventPolicy) error { + for _, policy := range policies { + err := r.eventingClientSet.EventingV1alpha1().EventPolicies(policy.Namespace).Delete(ctx, policy.Name, metav1.DeleteOptions{}) + if err != nil && !apierrs.IsNotFound(err) { + return err + } + } return nil } +func (r *Reconciler) cleanupAllEventPolicies(ctx context.Context, s *v1.Sequence) error { + policies, err := r.listEventPoliciesForSequence(ctx, s) + if err != nil { + return fmt.Errorf("failed to list EventPolicies for cleanup: %w", err) + } + return r.deleteEventPolicies(ctx, policies) +} func (r *Reconciler) reconcileChannelEventPolicy(ctx context.Context, s *v1.Sequence, channel *eventingduckv1.Channelable, subscription *messagingv1.Subscription) error { expected := resources.MakeEventPolicyForSequenceChannel(s, channel, subscription) @@ -386,37 +490,3 @@ func (r *Reconciler) createOrUpdateEventPolicy(ctx context.Context, expected *ev return nil } - -func (r *Reconciler) reconcileInputChannelEventPolicy(ctx context.Context, s *v1.Sequence, inputChannel *eventingduckv1.Channelable) error { - // Check if there's an EventPolicy for the Sequence - sequencePolicy, err := r.eventPolicyLister.EventPolicies(s.Namespace).Get(s.Name + "-ep") - if err != nil { - if apierrs.IsNotFound(err) { - // No EventPolicy for the Sequence, so we don't create one for the input channel - return nil - } - return err - } - - expected := resources.MakeEventPolicyForSequenceInputChannel(s, inputChannel, sequencePolicy) - - return r.createOrUpdateEventPolicy(ctx, expected) -} - -func (r *Reconciler) cleanupEventPolicies(ctx context.Context, s *v1.Sequence) error { - policies, err := r.eventPolicyLister.EventPolicies(s.Namespace).List(labels.Everything()) - if err != nil { - return err - } - - for _, policy := range policies { - if metav1.IsControlledBy(policy, s) { - err := r.eventingClientSet.EventingV1alpha1().EventPolicies(policy.Namespace).Delete(ctx, policy.Name, metav1.DeleteOptions{}) - if err != nil && !apierrs.IsNotFound(err) { - return err - } - } - } - - return nil -} From 78a8b0a8f2bfb4be60b13cf5619790e88842d86c Mon Sep 17 00:00:00 2001 From: Leo Li Date: Thu, 25 Jul 2024 14:04:13 -0400 Subject: [PATCH 08/26] fix: fix the goimports and remove unused helper functions and input parameters Signed-off-by: Leo Li --- .../sequence/resources/eventpolicy.go | 2 +- pkg/reconciler/sequence/sequence.go | 33 +++---------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/pkg/reconciler/sequence/resources/eventpolicy.go b/pkg/reconciler/sequence/resources/eventpolicy.go index b93eb42e691..13b68ca725d 100644 --- a/pkg/reconciler/sequence/resources/eventpolicy.go +++ b/pkg/reconciler/sequence/resources/eventpolicy.go @@ -70,7 +70,7 @@ func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduc func LabelsForSequenceChannelsEventPolicy(sequenceName string) map[string]string { return map[string]string{ - SequenceChannelEventPolicyLabelPrefix + "sequence-name": sequenceName, + SequenceChannelEventPolicyLabelPrefix + "sequence-name": sequenceName, } } diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 11966a68055..512a5113b6b 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -345,7 +345,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, } // List all existing EventPolicies for this Sequence - existingPolicies, err := r.listEventPoliciesForSequence(ctx, s) + existingPolicies, err := r.listEventPoliciesForSequence(s) if err != nil { return fmt.Errorf("failed to list existing EventPolicies: %w", err) } @@ -375,7 +375,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, } // Handle input channel policy - inputPolicy, err := r.prepareInputChannelEventPolicy(ctx, s, channels[0]) + inputPolicy, err := r.prepareInputChannelEventPolicy(s, channels[0]) if err != nil { return fmt.Errorf("failed to prepare input channel EventPolicy: %w", err) } @@ -411,14 +411,14 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, return nil } -func (r *Reconciler) listEventPoliciesForSequence(ctx context.Context, s *v1.Sequence) ([]*eventingv1alpha1.EventPolicy, error) { +func (r *Reconciler) listEventPoliciesForSequence(s *v1.Sequence) ([]*eventingv1alpha1.EventPolicy, error) { labelSelector := labels.SelectorFromSet(map[string]string{ resources.SequenceChannelEventPolicyLabelPrefix + "sequence-name": s.Name, }) return r.eventPolicyLister.EventPolicies(s.Namespace).List(labelSelector) } -func (r *Reconciler) prepareInputChannelEventPolicy(ctx context.Context, s *v1.Sequence, inputChannel *eventingduckv1.Channelable) (*eventingv1alpha1.EventPolicy, error) { +func (r *Reconciler) prepareInputChannelEventPolicy(s *v1.Sequence, inputChannel *eventingduckv1.Channelable) (*eventingv1alpha1.EventPolicy, error) { // Trying to see whether the user manually created the eventpolicy for the sequence sequencePolicy, err := r.eventPolicyLister.EventPolicies(s.Namespace).Get(s.Name + "-ep") if err != nil { @@ -461,32 +461,9 @@ func (r *Reconciler) deleteEventPolicies(ctx context.Context, policies []*eventi } func (r *Reconciler) cleanupAllEventPolicies(ctx context.Context, s *v1.Sequence) error { - policies, err := r.listEventPoliciesForSequence(ctx, s) + policies, err := r.listEventPoliciesForSequence(s) if err != nil { return fmt.Errorf("failed to list EventPolicies for cleanup: %w", err) } return r.deleteEventPolicies(ctx, policies) } -func (r *Reconciler) reconcileChannelEventPolicy(ctx context.Context, s *v1.Sequence, channel *eventingduckv1.Channelable, subscription *messagingv1.Subscription) error { - expected := resources.MakeEventPolicyForSequenceChannel(s, channel, subscription) - - return r.createOrUpdateEventPolicy(ctx, expected) -} -func (r *Reconciler) createOrUpdateEventPolicy(ctx context.Context, expected *eventingv1alpha1.EventPolicy) error { - existing, err := r.eventPolicyLister.EventPolicies(expected.Namespace).Get(expected.Name) - if apierrs.IsNotFound(err) { - _, err = r.eventingClientSet.EventingV1alpha1().EventPolicies(expected.Namespace).Create(ctx, expected, metav1.CreateOptions{}) - return err - } else if err != nil { - return err - } - - // Update if needed - if !equality.Semantic.DeepEqual(existing.Spec, expected.Spec) { - existing.Spec = expected.Spec - _, err = r.eventingClientSet.EventingV1alpha1().EventPolicies(existing.Namespace).Update(ctx, existing, metav1.UpdateOptions{}) - return err - } - - return nil -} From fe72c3cf5033ab7a41bfac8a0446c1e7b1f16980 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Fri, 26 Jul 2024 11:38:40 -0400 Subject: [PATCH 09/26] fix: add more unit tests to test out remove steps from the sequence Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence_test.go | 296 ++++++++++++++++++++++- 1 file changed, 295 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index 3e5464f15fe..c7d903b6f00 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -21,7 +21,6 @@ import ( "fmt" "testing" - eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" "knative.dev/eventing/pkg/apis/feature" corev1 "k8s.io/api/core/v1" @@ -30,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" clientgotesting "k8s.io/client-go/testing" + eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" v1 "knative.dev/eventing/pkg/apis/flows/v1" messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" @@ -2262,6 +2262,300 @@ func TestAllCases(t *testing.T) { })), }}, }, + { + Name: "sequenceupdate-remove-step with 3 steps with AuthZ enabled, and sequence doesn't have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + // Making the event policy for the sequence: + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 2), 2), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Name: resources.SequenceChannelName(sequenceName, 2), + }, { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), + }, + Name: resources.SequenceChannelName(sequenceName, 2), + }, + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("eventpolicies"), + }, + Name: resources.SequenceEventPolicyName(sequenceName, resources.SequenceChannelName(sequenceName, 2)), + }, + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}, + ))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "sequenceupdate-remove-step with 2 steps with AuthZ enabled, and sequence doesn't have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + })), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + // Making the event policy for the sequence: + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Name: resources.SequenceChannelName(sequenceName, 1), + }, { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), + }, + Name: resources.SequenceChannelName(sequenceName, 1), + }, + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("eventpolicies"), + }, + Name: resources.SequenceEventPolicyName(sequenceName, resources.SequenceChannelName(sequenceName, 1)), + }, + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}, + ))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "sequenceupdate-remove-step with 1 steps with AuthZ enabled, and sequence doesn't have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{})), + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + }))), + }, + WantErr: true, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "UpdateFailed", "Failed to update status for \"test-sequence\": missing field(s): spec.steps"), + }, + + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{}), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{})), + }}, + }, } logger := logtesting.TestLogger(t) From f088cf86844877419dae8ef73336ee4af1c06463 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Fri, 26 Jul 2024 11:46:24 -0400 Subject: [PATCH 10/26] Update pkg/reconciler/sequence/sequence.go Co-authored-by: Pierangelo Di Pilato --- pkg/reconciler/sequence/sequence.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 512a5113b6b..67025fb45c7 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -131,7 +131,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, s *v1.Sequence) pkgrecon return err } - // Handle EventPolicies if err := r.reconcileEventPolicies(ctx, s, channels, subs, featureFlags); err != nil { return fmt.Errorf("failed to reconcile EventPolicies: %w", err) } From 22520ed15ad844ca53ce45e34ae73c25dde2f877 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Fri, 26 Jul 2024 11:46:42 -0400 Subject: [PATCH 11/26] Update pkg/reconciler/sequence/sequence.go Co-authored-by: Pierangelo Di Pilato --- pkg/reconciler/sequence/sequence.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 67025fb45c7..9cb91d1cd64 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -343,7 +343,6 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, return r.cleanupAllEventPolicies(ctx, s) } - // List all existing EventPolicies for this Sequence existingPolicies, err := r.listEventPoliciesForSequence(s) if err != nil { return fmt.Errorf("failed to list existing EventPolicies: %w", err) From f0485591ab319bc2707b68efabc2ac31eeac4077 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Fri, 26 Jul 2024 11:47:34 -0400 Subject: [PATCH 12/26] Apply suggestions from code review Co-authored-by: Pierangelo Di Pilato --- pkg/reconciler/sequence/sequence.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 9cb91d1cd64..f694a88f4c4 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -363,7 +363,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, existingPolicy, exists := existingPolicyMap[expectedPolicy.Name] if exists { - if !equality.Semantic.DeepEqual(existingPolicy.Spec, expectedPolicy.Spec) { + if !equality.Semantic.DeepDerivative(expectedPolicy.Spec, existingPolicy.Spec) { policiesToUpdate = append(policiesToUpdate, expectedPolicy) } delete(existingPolicyMap, expectedPolicy.Name) @@ -381,7 +381,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, // The sequence has the event policy, so we are creating the event policy for the input channel existingInputPolicy, exists := existingPolicyMap[inputPolicy.Name] if exists { - if !equality.Semantic.DeepEqual(existingInputPolicy.Spec, inputPolicy.Spec) { + if !equality.Semantic.DeepDerivative(inputPolicy.Spec, existingInputPolicy.Spec) { policiesToUpdate = append(policiesToUpdate, inputPolicy) } delete(existingPolicyMap, inputPolicy.Name) From 092f87e315e2298e4990b2b230de8ca6d707a5c7 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Fri, 26 Jul 2024 13:02:19 -0400 Subject: [PATCH 13/26] fix: fix the nit review comments from pierdipi and rahul Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index f694a88f4c4..49bf17df618 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -348,14 +348,18 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, return fmt.Errorf("failed to list existing EventPolicies: %w", err) } - // Prepare maps for lookups + // Prepare maps for efficient lookups, updates, and deletions of policies existingPolicyMap := make(map[string]*eventingv1alpha1.EventPolicy) for _, policy := range existingPolicies { existingPolicyMap[policy.Name] = policy } - // Prepare lists for different actions - var policiesToUpdate, policiesToCreate, policiesToDelete []*eventingv1alpha1.EventPolicy + // Prepare lists for different actions so that policies can be categorized + // Corresponding operations will be performed on these lists + var policiesToUpdate, policiesToCreate []*eventingv1alpha1.EventPolicy + + // pre-allocation because we know the maximum possible size upfront (the number of existing policies). + policiesToDelete := make([]*eventingv1alpha1.EventPolicy, 0, len(existingPolicies)) // Handle intermediate channel policies (skip the first channel as it's the input channel!) for i := 1; i < len(channels); i++ { From 8126f8cf61b2a7088cf78727ff2422ed67caf816 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Fri, 26 Jul 2024 13:14:48 -0400 Subject: [PATCH 14/26] fix: using auth.GetEventPoliciesForResource when trying to list all Sequence's eventPolicy (not for the immediate channels) Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence.go | 40 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 49bf17df618..6e3cd4692fe 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -355,10 +355,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, } // Prepare lists for different actions so that policies can be categorized - // Corresponding operations will be performed on these lists var policiesToUpdate, policiesToCreate []*eventingv1alpha1.EventPolicy - - // pre-allocation because we know the maximum possible size upfront (the number of existing policies). policiesToDelete := make([]*eventingv1alpha1.EventPolicy, 0, len(existingPolicies)) // Handle intermediate channel policies (skip the first channel as it's the input channel!) @@ -376,13 +373,12 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, } } - // Handle input channel policy - inputPolicy, err := r.prepareInputChannelEventPolicy(s, channels[0]) + // Handle input channel policies + inputPolicies, err := r.prepareInputChannelEventPolicy(s, channels[0]) if err != nil { - return fmt.Errorf("failed to prepare input channel EventPolicy: %w", err) + return fmt.Errorf("failed to prepare input channel EventPolicies: %w", err) } - if inputPolicy != nil { - // The sequence has the event policy, so we are creating the event policy for the input channel + for _, inputPolicy := range inputPolicies { existingInputPolicy, exists := existingPolicyMap[inputPolicy.Name] if exists { if !equality.Semantic.DeepDerivative(inputPolicy.Spec, existingInputPolicy.Spec) { @@ -413,6 +409,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, return nil } +// listEventPoliciesForSequence lists all EventPolicies (e.g. the policies for the input channel and the intermediate channels) created during reconcileKind that are associated with the given Sequence. func (r *Reconciler) listEventPoliciesForSequence(s *v1.Sequence) ([]*eventingv1alpha1.EventPolicy, error) { labelSelector := labels.SelectorFromSet(map[string]string{ resources.SequenceChannelEventPolicyLabelPrefix + "sequence-name": s.Name, @@ -420,16 +417,27 @@ func (r *Reconciler) listEventPoliciesForSequence(s *v1.Sequence) ([]*eventingv1 return r.eventPolicyLister.EventPolicies(s.Namespace).List(labelSelector) } -func (r *Reconciler) prepareInputChannelEventPolicy(s *v1.Sequence, inputChannel *eventingduckv1.Channelable) (*eventingv1alpha1.EventPolicy, error) { - // Trying to see whether the user manually created the eventpolicy for the sequence - sequencePolicy, err := r.eventPolicyLister.EventPolicies(s.Namespace).Get(s.Name + "-ep") +func (r *Reconciler) prepareInputChannelEventPolicy(s *v1.Sequence, inputChannel *eventingduckv1.Channelable) ([]*eventingv1alpha1.EventPolicy, error) { + matchingPolicies, err := auth.GetEventPoliciesForResource( + r.eventPolicyLister, + v1.SchemeGroupVersion.WithKind("Sequence"), + s.ObjectMeta, + ) if err != nil { - if apierrs.IsNotFound(err) { - return nil, nil // No EventPolicy for the Sequence, so we don't create one for the input channel - } - return nil, err + return nil, fmt.Errorf("failed to get matching EventPolicies for Sequence: %w", err) } - return resources.MakeEventPolicyForSequenceInputChannel(s, inputChannel, sequencePolicy), nil + + if len(matchingPolicies) == 0 { + return nil, nil + } + + var inputChannelPolicies []*eventingv1alpha1.EventPolicy + for _, policy := range matchingPolicies { + inputChannelPolicy := resources.MakeEventPolicyForSequenceInputChannel(s, inputChannel, policy) + inputChannelPolicies = append(inputChannelPolicies, inputChannelPolicy) + } + + return inputChannelPolicies, nil } func (r *Reconciler) createEventPolicies(ctx context.Context, policies []*eventingv1alpha1.EventPolicy) error { From 268c59500fa7250fa16100923c0b242a979b1ead Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 31 Jul 2024 01:05:14 -0400 Subject: [PATCH 15/26] feat: add the sorting to avoid flaky test when there are multiple eventplocies per sequence Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 6e3cd4692fe..21ce0f4b884 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -19,7 +19,6 @@ package sequence import ( "context" "fmt" - "go.uber.org/zap" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" @@ -30,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/dynamic" "knative.dev/pkg/kmeta" + "sort" duckapis "knative.dev/pkg/apis/duck" "knative.dev/pkg/logging" @@ -431,12 +431,17 @@ func (r *Reconciler) prepareInputChannelEventPolicy(s *v1.Sequence, inputChannel return nil, nil } + sort.Slice(matchingPolicies, func(i, j int) bool { + return matchingPolicies[i].Name < matchingPolicies[j].Name + }) + var inputChannelPolicies []*eventingv1alpha1.EventPolicy for _, policy := range matchingPolicies { inputChannelPolicy := resources.MakeEventPolicyForSequenceInputChannel(s, inputChannel, policy) inputChannelPolicies = append(inputChannelPolicies, inputChannelPolicy) } + return inputChannelPolicies, nil } From 38017b8c3e5ca9d9818242c97391e362351a861c Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 31 Jul 2024 01:05:39 -0400 Subject: [PATCH 16/26] feat: remove the nil condition for channel name when creating the sequence policy name Signed-off-by: Leo Li --- pkg/reconciler/sequence/resources/eventpolicy.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/reconciler/sequence/resources/eventpolicy.go b/pkg/reconciler/sequence/resources/eventpolicy.go index 13b68ca725d..7b1bfbdce00 100644 --- a/pkg/reconciler/sequence/resources/eventpolicy.go +++ b/pkg/reconciler/sequence/resources/eventpolicy.go @@ -76,11 +76,7 @@ func LabelsForSequenceChannelsEventPolicy(sequenceName string) map[string]string func SequenceEventPolicyName(sequenceName, channelName string) string { // if channel name is empty, it means the event policy is for the output channel - if channelName == "" { - return kmeta.ChildName(sequenceName, "-ep") // no need to add the channel name - } else { - return kmeta.ChildName(sequenceName, "-ep-"+channelName) - } + return kmeta.ChildName(sequenceName, channelName+"-ep") } @@ -89,7 +85,7 @@ func MakeEventPolicyForSequenceInputChannel(s *flowsv1.Sequence, inputChannel *e return &eventingv1alpha1.EventPolicy{ ObjectMeta: metav1.ObjectMeta{ Namespace: inputChannel.Namespace, - Name: SequenceEventPolicyName(s.Name, inputChannel.Name), + Name: SequenceEventPolicyName(s.Name, sequencePolicy.Name), OwnerReferences: []metav1.OwnerReference{ { APIVersion: flowsv1.SchemeGroupVersion.String(), From fc8be572aba66a014684e43ea616b83f014da8fc Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 31 Jul 2024 01:05:47 -0400 Subject: [PATCH 17/26] feat: add more unit tests Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence_test.go | 970 +++++++++++++++++++++-- 1 file changed, 914 insertions(+), 56 deletions(-) diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index c7d903b6f00..c05c911d280 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -159,6 +159,7 @@ func TestAllCases(t *testing.T) { }, Spec: &runtime.RawExtension{Raw: []byte("{}")}, } + differentIMC := &messagingv1.ChannelTemplateSpec{ TypeMeta: metav1.TypeMeta{ APIVersion: "messaging.knative.dev/v1", @@ -166,6 +167,7 @@ func TestAllCases(t *testing.T) { }, Spec: &runtime.RawExtension{Raw: []byte("{}")}, } + table := TableTest{{ Name: "bad workqueue key", // Make sure Reconcile handles bad keys. @@ -1765,10 +1767,7 @@ func TestAllCases(t *testing.T) { makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 2), 2), - makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0)), - - // make the eventpolicy for the sequence - + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewSequence(sequenceName, testNS, @@ -2025,7 +2024,7 @@ func TestAllCases(t *testing.T) { {Destination: createDestination(0)}, {Destination: createDestination(1)}}))), makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), - makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0)), + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), // make the eventpolicy for the sequence @@ -2207,10 +2206,7 @@ func TestAllCases(t *testing.T) { WithSequenceSteps([]v1.SequenceStep{ {Destination: createDestination(0)}}))), - makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0)), - - // make the eventpolicy for the sequence - + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewSequence(sequenceName, testNS, @@ -2556,57 +2552,919 @@ func TestAllCases(t *testing.T) { WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{})), }}, }, - } - - logger := logtesting.TestLogger(t) - table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { - ctx = channelable.WithDuck(ctx) - r := &Reconciler{ - sequenceLister: listers.GetSequenceLister(), - channelableTracker: duck.NewListableTrackerFromTracker(ctx, channelable.Get, tracker.New(func(types.NamespacedName) {}, 0)), - subscriptionLister: listers.GetSubscriptionLister(), - eventingClientSet: fakeeventingclient.Get(ctx), - dynamicClientSet: fakedynamicclient.Get(ctx), - eventPolicyLister: listers.GetEventPolicyLister(), - } - return sequence.NewReconciler(ctx, logging.FromContext(ctx), - fakeeventingclient.Get(ctx), listers.GetSequenceLister(), - controller.GetEventRecorder(ctx), r) - }, false, logger)) -} + { + Name: "sequenceupdate-remove-step with 3 steps with AuthZ enabled, and sequence does have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}})), + makeSequenceEventPolicy(sequenceName), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + createChannel(sequenceName, 2), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + resources.NewSubscription(2, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + // Making the event policy for the sequence: + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), -func makeEventPolicy(sequenceName, channelName string, step int) *eventingv1alpha1.EventPolicy { - return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, channelName), testNS, - WithEventPolicyToRef(channelV1GVK, channelName), - // from a subscription - WithEventPolicyFrom(subscriberGVK, resources.SequenceSubscriptionName(sequenceName, step-1), testNS), - WithEventPolicyOwnerReferences([]metav1.OwnerReference{ - { - APIVersion: "flows.knative.dev/v1", - Kind: "Sequence", - Name: sequenceName, + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 2), 2), }, - }...), - WithEventPolicyLabels(resources.LabelsForSequenceChannelsEventPolicy(sequenceName)), - ) -} - -// Write a function to make the event policy for the sequence -func makeSequenceEventPolicy(sequenceName string) *eventingv1alpha1.EventPolicy { - return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, ""), testNS, - // from a subscription - WithEventPolicyOwnerReferences([]metav1.OwnerReference{ - { - APIVersion: "flows.knative.dev/v1", - Kind: "Sequence", - Name: sequenceName, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Name: resources.SequenceChannelName(sequenceName, 2), + }, { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), + }, + Name: resources.SequenceChannelName(sequenceName, 2), + }, + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("eventpolicies"), + }, + Name: resources.SequenceEventPolicyName(sequenceName, resources.SequenceChannelName(sequenceName, 2)), + }, }, - }...), - ) -} + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}, + ))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "sequenceupdate-remove-step with 2 steps with AuthZ enabled, and sequence does have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + })), + makeSequenceEventPolicy(sequenceName), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + // Making the event policy for the sequence: + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), -func makeInputChannelEventPolicy(sequenceName, channelName string) *eventingv1alpha1.EventPolicy { - return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, channelName), testNS, + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Name: resources.SequenceChannelName(sequenceName, 1), + }, { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("inmemorychannels"), + }, + Name: resources.SequenceChannelName(sequenceName, 1), + }, + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("eventpolicies"), + }, + Name: resources.SequenceEventPolicyName(sequenceName, resources.SequenceChannelName(sequenceName, 1)), + }, + }, + WantUpdates: []clientgotesting.UpdateActionImpl{{ + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}, + ))), + }}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "sequenceupdate-remove-step with 1 steps with AuthZ enabled, and sequence does have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{})), + makeSequenceEventPolicy(sequenceName), + createChannel(sequenceName, 0), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + }))), + }, + WantErr: true, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantEvents: []string{ + Eventf(corev1.EventTypeWarning, "UpdateFailed", "Failed to update status for \"test-sequence\": missing field(s): spec.steps"), + }, + + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{}), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{}), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{})), + }}, + }, + { + Name: "sequenceupdate-add-step with 2 steps (3 in total) with AuthZ enabled, and sequence doesn't have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + })), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + createChannel(sequenceName, 2), + resources.NewSubscription(2, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 2), 2), + }, + WantUpdates: []clientgotesting.UpdateActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + }, + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "sequenceupdate-add-step with 2 steps (3 in total) with AuthZ enabled, and sequence does have event policy", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + })), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + makeSequenceEventPolicy(sequenceName), + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + createChannel(sequenceName, 2), + resources.NewSubscription(2, + NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 2), 2), + }, + WantUpdates: []clientgotesting.UpdateActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("subscriptions"), + }, + Object: resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }))), + }, + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + {Destination: createDestination(2)}, + }), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", sequenceName+"-ep")), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 2), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "sequence eventpolicy deleted", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + })), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), + + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: v1.SchemeGroupVersion.WithResource("eventpolicies"), + }, + Name: resources.SequenceEventPolicyName(sequenceName, resources.SequenceEventPolicyName(sequenceName, "")), + }, + }, + + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesReadyBecauseNoPolicyAndOIDCEnabled(), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + { + Name: "sequence with multiple eventpolicies", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + })), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + makeSequenceEventPolicy(sequenceName), + makeSequenceEventPolicy(sequenceName + "-additional-1"), + makeSequenceEventPolicy(sequenceName + "-additional-2"), + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantCreates: []runtime.Object{ + + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName+"-additional-1", "")), + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName+"-additional-2", "")), + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s, %s, %s are not ready", sequenceName+"-ep", sequenceName+"-additional-1-ep", sequenceName+"-additional-2-ep")), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, + } + + logger := logtesting.TestLogger(t) + table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { + ctx = channelable.WithDuck(ctx) + r := &Reconciler{ + sequenceLister: listers.GetSequenceLister(), + channelableTracker: duck.NewListableTrackerFromTracker(ctx, channelable.Get, tracker.New(func(types.NamespacedName) {}, 0)), + subscriptionLister: listers.GetSubscriptionLister(), + eventingClientSet: fakeeventingclient.Get(ctx), + dynamicClientSet: fakedynamicclient.Get(ctx), + eventPolicyLister: listers.GetEventPolicyLister(), + } + return sequence.NewReconciler(ctx, logging.FromContext(ctx), + fakeeventingclient.Get(ctx), listers.GetSequenceLister(), + controller.GetEventRecorder(ctx), r) + }, false, logger)) +} + +func makeEventPolicy(sequenceName, channelName string, step int) *eventingv1alpha1.EventPolicy { + return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, channelName), testNS, + WithEventPolicyToRef(channelV1GVK, channelName), + // from a subscription + WithEventPolicyFrom(subscriberGVK, resources.SequenceSubscriptionName(sequenceName, step-1), testNS), + WithEventPolicyOwnerReferences([]metav1.OwnerReference{ + { + APIVersion: "flows.knative.dev/v1", + Kind: "Sequence", + Name: sequenceName, + }, + }...), + WithEventPolicyLabels(resources.LabelsForSequenceChannelsEventPolicy(sequenceName)), + ) +} + +// Write a function to make the event policy for the sequence +func makeSequenceEventPolicy(sequenceName string) *eventingv1alpha1.EventPolicy { + return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, ""), testNS, + // from a subscription + WithEventPolicyOwnerReferences([]metav1.OwnerReference{ + { + APIVersion: "flows.knative.dev/v1", + Kind: "Sequence", + Name: sequenceName, + }, + }...), + ) +} + +func makeInputChannelEventPolicy(sequenceName, channelName string, sequenceEventPolicyName string) *eventingv1alpha1.EventPolicy { + return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, sequenceEventPolicyName), testNS, WithEventPolicyToRef(channelV1GVK, channelName), // from a subscription WithEventPolicyOwnerReferences([]metav1.OwnerReference{ From b7bfc92064c6420aa8216eade94373f186c7682e Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 31 Jul 2024 01:38:30 -0400 Subject: [PATCH 18/26] fix: lint & goimports Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 21ce0f4b884..4f070f1b412 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -19,6 +19,8 @@ package sequence import ( "context" "fmt" + "sort" + "go.uber.org/zap" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" @@ -29,7 +31,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/dynamic" "knative.dev/pkg/kmeta" - "sort" duckapis "knative.dev/pkg/apis/duck" "knative.dev/pkg/logging" @@ -435,13 +436,12 @@ func (r *Reconciler) prepareInputChannelEventPolicy(s *v1.Sequence, inputChannel return matchingPolicies[i].Name < matchingPolicies[j].Name }) - var inputChannelPolicies []*eventingv1alpha1.EventPolicy + inputChannelPolicies := make([]*eventingv1alpha1.EventPolicy, 0, len(matchingPolicies)) for _, policy := range matchingPolicies { inputChannelPolicy := resources.MakeEventPolicyForSequenceInputChannel(s, inputChannel, policy) inputChannelPolicies = append(inputChannelPolicies, inputChannelPolicy) } - return inputChannelPolicies, nil } From 5da98e03d078cdceb19a228d213069b679464011 Mon Sep 17 00:00:00 2001 From: Leo HC Li <36619969+Leo6Leo@users.noreply.github.com> Date: Wed, 7 Aug 2024 00:54:54 -0400 Subject: [PATCH 19/26] fix: fix the review comments --- .../sequence/resources/eventpolicy.go | 13 +++++++++---- pkg/reconciler/sequence/sequence.go | 4 ++-- pkg/reconciler/sequence/sequence_test.go | 17 ++++++++--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pkg/reconciler/sequence/resources/eventpolicy.go b/pkg/reconciler/sequence/resources/eventpolicy.go index 7b1bfbdce00..9ae64cc0d7e 100644 --- a/pkg/reconciler/sequence/resources/eventpolicy.go +++ b/pkg/reconciler/sequence/resources/eventpolicy.go @@ -40,6 +40,7 @@ func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduc APIVersion: flowsv1.SchemeGroupVersion.String(), Kind: sequenceKind, Name: s.Name, + UID: s.UID, }, }, Labels: LabelsForSequenceChannelsEventPolicy(s.Name), @@ -57,8 +58,8 @@ func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduc From: []eventingv1alpha1.EventPolicySpecFrom{ { Ref: &eventingv1alpha1.EventPolicyFromReference{ - APIVersion: subscription.APIVersion, - Kind: subscription.Kind, + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", Name: subscription.Name, Namespace: subscription.Namespace, }, @@ -75,8 +76,11 @@ func LabelsForSequenceChannelsEventPolicy(sequenceName string) map[string]string } func SequenceEventPolicyName(sequenceName, channelName string) string { - // if channel name is empty, it means the event policy is for the output channel - return kmeta.ChildName(sequenceName, channelName+"-ep") + + if channelName == "" { + return sequenceName + } + return kmeta.ChildName(sequenceName, "-"+channelName) } @@ -91,6 +95,7 @@ func MakeEventPolicyForSequenceInputChannel(s *flowsv1.Sequence, inputChannel *e APIVersion: flowsv1.SchemeGroupVersion.String(), Kind: sequenceKind, Name: s.Name, + UID: s.UID, }, }, Labels: LabelsForSequenceChannelsEventPolicy(s.Name), diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index e9f9a2cf7ae..4b07676ee3b 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -367,7 +367,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, existingPolicy, exists := existingPolicyMap[expectedPolicy.Name] if exists { - if !equality.Semantic.DeepDerivative(expectedPolicy.Spec, existingPolicy.Spec) { + if !equality.Semantic.DeepDerivative(expectedPolicy, existingPolicy) { policiesToUpdate = append(policiesToUpdate, expectedPolicy) } delete(existingPolicyMap, expectedPolicy.Name) @@ -384,7 +384,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, for _, inputPolicy := range inputPolicies { existingInputPolicy, exists := existingPolicyMap[inputPolicy.Name] if exists { - if !equality.Semantic.DeepDerivative(inputPolicy.Spec, existingInputPolicy.Spec) { + if !equality.Semantic.DeepDerivative(inputPolicy, existingInputPolicy) { policiesToUpdate = append(policiesToUpdate, inputPolicy) } delete(existingPolicyMap, inputPolicy.Name) diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index c05c911d280..91e05c2d9d6 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -1784,7 +1784,7 @@ func TestAllCases(t *testing.T) { WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence are not ready"), WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ @@ -2043,7 +2043,7 @@ func TestAllCases(t *testing.T) { WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence are not ready"), WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ @@ -2221,7 +2221,7 @@ func TestAllCases(t *testing.T) { WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence are not ready"), WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ @@ -2642,7 +2642,7 @@ func TestAllCases(t *testing.T) { WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence are not ready"), WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ @@ -2782,7 +2782,7 @@ func TestAllCases(t *testing.T) { WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence-ep are not ready"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", "event policies test-sequence are not ready"), WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ @@ -3090,7 +3090,7 @@ func TestAllCases(t *testing.T) { WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", sequenceName+"-ep")), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s are not ready", sequenceName)), WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ @@ -3335,10 +3335,9 @@ func TestAllCases(t *testing.T) { feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, }), WantCreates: []runtime.Object{ - + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName+"-additional-1", "")), makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName+"-additional-2", "")), - makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewSequence(sequenceName, testNS, @@ -3351,7 +3350,7 @@ func TestAllCases(t *testing.T) { WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), - WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s, %s, %s are not ready", sequenceName+"-ep", sequenceName+"-additional-1-ep", sequenceName+"-additional-2-ep")), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s, %s, %s are not ready", sequenceName, sequenceName+"-additional-1", sequenceName+"-additional-2")), WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ { Channel: corev1.ObjectReference{ From 36a1cb3a537d5fffef59b226895eca345cac08fd Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 7 Aug 2024 09:58:03 -0400 Subject: [PATCH 20/26] fix: fix Christoph's review comments Signed-off-by: Leo Li --- pkg/reconciler/sequence/resources/eventpolicy.go | 11 ++++++----- pkg/reconciler/sequence/sequence.go | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/reconciler/sequence/resources/eventpolicy.go b/pkg/reconciler/sequence/resources/eventpolicy.go index 9ae64cc0d7e..e5338dd66d3 100644 --- a/pkg/reconciler/sequence/resources/eventpolicy.go +++ b/pkg/reconciler/sequence/resources/eventpolicy.go @@ -28,6 +28,7 @@ import ( const ( SequenceChannelEventPolicyLabelPrefix = "flows.knative.dev/" sequenceKind = "Sequence" + subscriptionKind = "Subscription" ) func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduckv1.Channelable, subscription *messagingv1.Subscription) *eventingv1alpha1.EventPolicy { @@ -58,8 +59,8 @@ func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduc From: []eventingv1alpha1.EventPolicySpecFrom{ { Ref: &eventingv1alpha1.EventPolicyFromReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", + APIVersion: messagingv1.SchemeGroupVersion.String(), + Kind: subscriptionKind, Name: subscription.Name, Namespace: subscription.Namespace, }, @@ -75,12 +76,12 @@ func LabelsForSequenceChannelsEventPolicy(sequenceName string) map[string]string } } -func SequenceEventPolicyName(sequenceName, channelName string) string { +func SequenceEventPolicyName(sequenceName, postfix string) string { - if channelName == "" { + if postfix == "" { return sequenceName } - return kmeta.ChildName(sequenceName, "-"+channelName) + return kmeta.ChildName(sequenceName, "-"+postfix) } diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index 4b07676ee3b..fe60c8f90d3 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -368,6 +368,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, if exists { if !equality.Semantic.DeepDerivative(expectedPolicy, existingPolicy) { + expectedPolicy.SetResourceVersion(existingPolicy.ResourceVersion) policiesToUpdate = append(policiesToUpdate, expectedPolicy) } delete(existingPolicyMap, expectedPolicy.Name) @@ -385,6 +386,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, existingInputPolicy, exists := existingPolicyMap[inputPolicy.Name] if exists { if !equality.Semantic.DeepDerivative(inputPolicy, existingInputPolicy) { + inputPolicy.SetResourceVersion(existingInputPolicy.ResourceVersion) policiesToUpdate = append(policiesToUpdate, inputPolicy) } delete(existingPolicyMap, inputPolicy.Name) From 6042cbbd95fb7018ded81ee7edf70000869d934a Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 7 Aug 2024 17:00:33 -0400 Subject: [PATCH 21/26] feat: adding a test for sequence with existing intermediate eventpolicies requiring update and cleanup. Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence_test.go | 174 +++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index 91e05c2d9d6..6331029d8cd 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -3413,6 +3413,149 @@ func TestAllCases(t *testing.T) { })), }}, }, + { + Name: "sequence with existing intermediate eventpolicies requiring update and cleanup", + Key: pKey, + Objects: []runtime.Object{ + NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + })), + createChannel(sequenceName, 0), + createChannel(sequenceName, 1), + resources.NewSubscription(0, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + resources.NewSubscription(1, NewSequence(sequenceName, testNS, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }))), + makeSequenceEventPolicy(sequenceName), + makeSequenceEventPolicy(sequenceName + "-additional"), + // Existing intermediate policy for input channel (needs update) + makeInputChannelEventPolicyWithWrongSpec(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), + // Existing intermediate policy for step 0 (correct, no update needed) + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), 0), + // Existing intermediate policy for step 1 (needs to be deleted) + makeEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 1), 1), + // Obsolete policy that should be deleted + makeObsoleteEventPolicy(sequenceName), + }, + WantErr: false, + Ctx: feature.ToContext(context.Background(), feature.Flags{ + feature.OIDCAuthentication: feature.Enabled, + feature.AuthorizationDefaultMode: feature.AuthorizationAllowSameNamespace, + }), + WantUpdates: []clientgotesting.UpdateActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: eventingv1alpha1.SchemeGroupVersion.WithResource("eventpolicies"), + }, + Object: makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName, "")), + }, + }, + WantCreates: []runtime.Object{ + makeInputChannelEventPolicy(sequenceName, resources.SequenceChannelName(sequenceName, 0), resources.SequenceEventPolicyName(sequenceName+"-additional", "")), + }, + WantDeletes: []clientgotesting.DeleteActionImpl{ + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: eventingv1alpha1.SchemeGroupVersion.WithResource("eventpolicies"), + }, + Name: resources.SequenceEventPolicyName(sequenceName, resources.SequenceChannelName(sequenceName, 0)), + }, + { + ActionImpl: clientgotesting.ActionImpl{ + Namespace: testNS, + Resource: eventingv1alpha1.SchemeGroupVersion.WithResource("eventpolicies"), + }, + Name: resources.SequenceEventPolicyName(sequenceName, "obsolete"), + }, + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewSequence(sequenceName, testNS, + WithInitSequenceConditions, + WithSequenceChannelTemplateSpec(imc), + WithSequenceSteps([]v1.SequenceStep{ + {Destination: createDestination(0)}, + {Destination: createDestination(1)}, + }), + WithSequenceChannelsNotReady("ChannelsNotReady", "Channels are not ready yet, or there are none"), + WithSequenceAddressableNotReady("emptyAddress", "addressable is nil"), + WithSequenceSubscriptionsNotReady("SubscriptionsNotReady", "Subscriptions are not ready yet, or there are none"), + WithSequenceEventPoliciesNotReady("EventPoliciesNotReady", fmt.Sprintf("event policies %s, %s are not ready", sequenceName, sequenceName+"-additional")), + WithSequenceChannelStatuses([]v1.SequenceChannelStatus{ + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + { + Channel: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: resources.SequenceChannelName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Channel does not have Ready condition", + }, + }, + }), + WithSequenceSubscriptionStatuses([]v1.SequenceSubscriptionStatus{ + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 0), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + { + Subscription: corev1.ObjectReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: resources.SequenceSubscriptionName(sequenceName, 1), + Namespace: testNS, + }, + ReadyCondition: apis.Condition{ + Type: apis.ConditionReady, + Status: corev1.ConditionUnknown, + Reason: "NoReady", + Message: "Subscription does not have Ready condition", + }, + }, + })), + }}, + }, } logger := logtesting.TestLogger(t) @@ -3476,3 +3619,34 @@ func makeInputChannelEventPolicy(sequenceName, channelName string, sequenceEvent WithEventPolicyLabels(resources.LabelsForSequenceChannelsEventPolicy(sequenceName)), ) } + +func makeInputChannelEventPolicyWithWrongSpec(sequenceName, channelName, policyName string) *eventingv1alpha1.EventPolicy { + policy := makeInputChannelEventPolicy(sequenceName, channelName, policyName) + // Modify the policy to have an incorrect specification + policy.Spec.From = []eventingv1alpha1.EventPolicySpecFrom{ + { + Ref: &eventingv1alpha1.EventPolicyFromReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "Subscription", + Name: "wrong-subscription", + Namespace: testNS, + }, + }, + } + + return policy +} + +func makeObsoleteEventPolicy(sequenceName string) *eventingv1alpha1.EventPolicy { + return NewEventPolicy(resources.SequenceEventPolicyName(sequenceName, "obsolete"), testNS, + WithEventPolicyToRef(channelV1GVK, "obsolete-channel"), + WithEventPolicyOwnerReferences([]metav1.OwnerReference{ + { + APIVersion: "flows.knative.dev/v1", + Kind: "Sequence", + Name: sequenceName, + }, + }...), + WithEventPolicyLabels(resources.LabelsForSequenceChannelsEventPolicy(sequenceName)), + ) +} From 9d1e73b40cb44de69c8681706f6330b0ef7b3307 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Wed, 7 Aug 2024 17:01:13 -0400 Subject: [PATCH 22/26] fix: the deepDerivative failed to compare the eventpolicy's From.Spec, change to reflect.DeepEqual Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index fe60c8f90d3..fb167317f1e 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -19,6 +19,7 @@ package sequence import ( "context" "fmt" + "reflect" "sort" "go.uber.org/zap" @@ -385,7 +386,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, for _, inputPolicy := range inputPolicies { existingInputPolicy, exists := existingPolicyMap[inputPolicy.Name] if exists { - if !equality.Semantic.DeepDerivative(inputPolicy, existingInputPolicy) { + if !reflect.DeepEqual(inputPolicy, existingInputPolicy) { inputPolicy.SetResourceVersion(existingInputPolicy.ResourceVersion) policiesToUpdate = append(policiesToUpdate, inputPolicy) } From e6cddbe740383291906a361c7c45c7bed422c576 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Thu, 8 Aug 2024 10:46:26 -0400 Subject: [PATCH 23/26] fix: change back to use DeepDerivative Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index fb167317f1e..fe60c8f90d3 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -19,7 +19,6 @@ package sequence import ( "context" "fmt" - "reflect" "sort" "go.uber.org/zap" @@ -386,7 +385,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence, for _, inputPolicy := range inputPolicies { existingInputPolicy, exists := existingPolicyMap[inputPolicy.Name] if exists { - if !reflect.DeepEqual(inputPolicy, existingInputPolicy) { + if !equality.Semantic.DeepDerivative(inputPolicy, existingInputPolicy) { inputPolicy.SetResourceVersion(existingInputPolicy.ResourceVersion) policiesToUpdate = append(policiesToUpdate, inputPolicy) } From cf4d257928d5bcf94d6fac21d44cf80952a8c6e2 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Thu, 8 Aug 2024 10:47:02 -0400 Subject: [PATCH 24/26] fix: fix the test case to make the eventpolicy has a valid spec Signed-off-by: Leo Li --- pkg/reconciler/sequence/sequence_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index 6331029d8cd..4e353c5b36a 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -3634,6 +3634,16 @@ func makeInputChannelEventPolicyWithWrongSpec(sequenceName, channelName, policyN }, } + policy.Spec.To = []eventingv1alpha1.EventPolicySpecTo{ + { + Ref: &eventingv1alpha1.EventPolicyToReference{ + APIVersion: "messaging.knative.dev/v1", + Kind: "InMemoryChannel", + Name: "wrong-channel", + }, + }, + } + return policy } From ad4df83298432fb07ebb8fae7f1617ddc7057f2b Mon Sep 17 00:00:00 2001 From: Leo Li Date: Thu, 8 Aug 2024 16:27:45 -0400 Subject: [PATCH 25/26] fix: fix the flaky issue by soring the policies Signed-off-by: Leo Li --- pkg/auth/event_policy.go | 6 ++++++ pkg/reconciler/sequence/sequence.go | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/auth/event_policy.go b/pkg/auth/event_policy.go index 7d4fcb1dbad..d8635167439 100644 --- a/pkg/auth/event_policy.go +++ b/pkg/auth/event_policy.go @@ -18,6 +18,7 @@ package auth import ( "fmt" + "sort" "strings" eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" @@ -93,6 +94,11 @@ func GetEventPoliciesForResource(lister listerseventingv1alpha1.EventPolicyListe } } + // Sort the policies by name to ensure deterministic order + sort.Slice(relevantPolicies, func(i, j int) bool { + return relevantPolicies[i].Name < relevantPolicies[j].Name + }) + return relevantPolicies, nil } diff --git a/pkg/reconciler/sequence/sequence.go b/pkg/reconciler/sequence/sequence.go index fe60c8f90d3..530d70b7166 100644 --- a/pkg/reconciler/sequence/sequence.go +++ b/pkg/reconciler/sequence/sequence.go @@ -19,7 +19,6 @@ package sequence import ( "context" "fmt" - "sort" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -436,10 +435,6 @@ func (r *Reconciler) prepareInputChannelEventPolicy(s *v1.Sequence, inputChannel return nil, nil } - sort.Slice(matchingPolicies, func(i, j int) bool { - return matchingPolicies[i].Name < matchingPolicies[j].Name - }) - inputChannelPolicies := make([]*eventingv1alpha1.EventPolicy, 0, len(matchingPolicies)) for _, policy := range matchingPolicies { inputChannelPolicy := resources.MakeEventPolicyForSequenceInputChannel(s, inputChannel, policy) From 6c8fa1ab8ff7b262da49827d31ab54514da61f52 Mon Sep 17 00:00:00 2001 From: Leo HC Li <36619969+Leo6Leo@users.noreply.github.com> Date: Fri, 9 Aug 2024 00:49:25 -0400 Subject: [PATCH 26/26] fix: change input channel's ownerref to sequence's eventpolicy --- .../sequence/resources/eventpolicy.go | 9 +++---- pkg/reconciler/sequence/sequence_test.go | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pkg/reconciler/sequence/resources/eventpolicy.go b/pkg/reconciler/sequence/resources/eventpolicy.go index e5338dd66d3..efe14d3d541 100644 --- a/pkg/reconciler/sequence/resources/eventpolicy.go +++ b/pkg/reconciler/sequence/resources/eventpolicy.go @@ -29,6 +29,7 @@ const ( SequenceChannelEventPolicyLabelPrefix = "flows.knative.dev/" sequenceKind = "Sequence" subscriptionKind = "Subscription" + eventPolicyKind = "EventPolicy" ) func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduckv1.Channelable, subscription *messagingv1.Subscription) *eventingv1alpha1.EventPolicy { @@ -93,10 +94,10 @@ func MakeEventPolicyForSequenceInputChannel(s *flowsv1.Sequence, inputChannel *e Name: SequenceEventPolicyName(s.Name, sequencePolicy.Name), OwnerReferences: []metav1.OwnerReference{ { - APIVersion: flowsv1.SchemeGroupVersion.String(), - Kind: sequenceKind, - Name: s.Name, - UID: s.UID, + APIVersion: eventingv1alpha1.SchemeGroupVersion.String(), + Kind: eventPolicyKind, + Name: sequencePolicy.Name, + UID: sequencePolicy.UID, }, }, Labels: LabelsForSequenceChannelsEventPolicy(s.Name), diff --git a/pkg/reconciler/sequence/sequence_test.go b/pkg/reconciler/sequence/sequence_test.go index 4e353c5b36a..02d59cecc96 100644 --- a/pkg/reconciler/sequence/sequence_test.go +++ b/pkg/reconciler/sequence/sequence_test.go @@ -82,6 +82,12 @@ var ( Version: "v1", Kind: "InMemoryChannel", } + + eventPolicyV1Alpha1GVK = metav1.GroupVersionKind{ + Group: "eventing.knative.dev", + Version: "v1alpha1", + Kind: "EventPolicy", + } ) func createReplyChannel(channelName string) *duckv1.Destination { @@ -3611,9 +3617,9 @@ func makeInputChannelEventPolicy(sequenceName, channelName string, sequenceEvent // from a subscription WithEventPolicyOwnerReferences([]metav1.OwnerReference{ { - APIVersion: "flows.knative.dev/v1", - Kind: "Sequence", - Name: sequenceName, + APIVersion: apiVersion(eventPolicyV1Alpha1GVK), + Kind: eventPolicyV1Alpha1GVK.Kind, + Name: sequenceEventPolicyName, }, }...), WithEventPolicyLabels(resources.LabelsForSequenceChannelsEventPolicy(sequenceName)), @@ -3626,8 +3632,8 @@ func makeInputChannelEventPolicyWithWrongSpec(sequenceName, channelName, policyN policy.Spec.From = []eventingv1alpha1.EventPolicySpecFrom{ { Ref: &eventingv1alpha1.EventPolicyFromReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "Subscription", + APIVersion: apiVersion(subscriberGVK), + Kind: subscriberGVK.Kind, Name: "wrong-subscription", Namespace: testNS, }, @@ -3637,8 +3643,8 @@ func makeInputChannelEventPolicyWithWrongSpec(sequenceName, channelName, policyN policy.Spec.To = []eventingv1alpha1.EventPolicySpecTo{ { Ref: &eventingv1alpha1.EventPolicyToReference{ - APIVersion: "messaging.knative.dev/v1", - Kind: "InMemoryChannel", + APIVersion: apiVersion(channelV1GVK), + Kind: channelV1GVK.Kind, Name: "wrong-channel", }, }, @@ -3652,8 +3658,8 @@ func makeObsoleteEventPolicy(sequenceName string) *eventingv1alpha1.EventPolicy WithEventPolicyToRef(channelV1GVK, "obsolete-channel"), WithEventPolicyOwnerReferences([]metav1.OwnerReference{ { - APIVersion: "flows.knative.dev/v1", - Kind: "Sequence", + APIVersion: apiVersion(sequenceGVK), + Kind: sequenceGVK.Kind, Name: sequenceName, }, }...),