@@ -355,10 +355,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence,
355
355
}
356
356
357
357
// Prepare lists for different actions so that policies can be categorized
358
- // Corresponding operations will be performed on these lists
359
358
var policiesToUpdate , policiesToCreate []* eventingv1alpha1.EventPolicy
360
-
361
- // pre-allocation because we know the maximum possible size upfront (the number of existing policies).
362
359
policiesToDelete := make ([]* eventingv1alpha1.EventPolicy , 0 , len (existingPolicies ))
363
360
364
361
// 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,
376
373
}
377
374
}
378
375
379
- // Handle input channel policy
380
- inputPolicy , err := r .prepareInputChannelEventPolicy (s , channels [0 ])
376
+ // Handle input channel policies
377
+ inputPolicies , err := r .prepareInputChannelEventPolicy (s , channels [0 ])
381
378
if err != nil {
382
- return fmt .Errorf ("failed to prepare input channel EventPolicy : %w" , err )
379
+ return fmt .Errorf ("failed to prepare input channel EventPolicies : %w" , err )
383
380
}
384
- if inputPolicy != nil {
385
- // The sequence has the event policy, so we are creating the event policy for the input channel
381
+ for _ , inputPolicy := range inputPolicies {
386
382
existingInputPolicy , exists := existingPolicyMap [inputPolicy .Name ]
387
383
if exists {
388
384
if ! equality .Semantic .DeepDerivative (inputPolicy .Spec , existingInputPolicy .Spec ) {
@@ -413,23 +409,35 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence,
413
409
return nil
414
410
}
415
411
412
+ // 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.
416
413
func (r * Reconciler ) listEventPoliciesForSequence (s * v1.Sequence ) ([]* eventingv1alpha1.EventPolicy , error ) {
417
414
labelSelector := labels .SelectorFromSet (map [string ]string {
418
415
resources .SequenceChannelEventPolicyLabelPrefix + "sequence-name" : s .Name ,
419
416
})
420
417
return r .eventPolicyLister .EventPolicies (s .Namespace ).List (labelSelector )
421
418
}
422
419
423
- func (r * Reconciler ) prepareInputChannelEventPolicy (s * v1.Sequence , inputChannel * eventingduckv1.Channelable ) (* eventingv1alpha1.EventPolicy , error ) {
424
- // Trying to see whether the user manually created the eventpolicy for the sequence
425
- sequencePolicy , err := r .eventPolicyLister .EventPolicies (s .Namespace ).Get (s .Name + "-ep" )
420
+ func (r * Reconciler ) prepareInputChannelEventPolicy (s * v1.Sequence , inputChannel * eventingduckv1.Channelable ) ([]* eventingv1alpha1.EventPolicy , error ) {
421
+ matchingPolicies , err := auth .GetEventPoliciesForResource (
422
+ r .eventPolicyLister ,
423
+ v1 .SchemeGroupVersion .WithKind ("Sequence" ),
424
+ s .ObjectMeta ,
425
+ )
426
426
if err != nil {
427
- if apierrs .IsNotFound (err ) {
428
- return nil , nil // No EventPolicy for the Sequence, so we don't create one for the input channel
429
- }
430
- return nil , err
427
+ return nil , fmt .Errorf ("failed to get matching EventPolicies for Sequence: %w" , err )
431
428
}
432
- return resources .MakeEventPolicyForSequenceInputChannel (s , inputChannel , sequencePolicy ), nil
429
+
430
+ if len (matchingPolicies ) == 0 {
431
+ return nil , nil
432
+ }
433
+
434
+ var inputChannelPolicies []* eventingv1alpha1.EventPolicy
435
+ for _ , policy := range matchingPolicies {
436
+ inputChannelPolicy := resources .MakeEventPolicyForSequenceInputChannel (s , inputChannel , policy )
437
+ inputChannelPolicies = append (inputChannelPolicies , inputChannelPolicy )
438
+ }
439
+
440
+ return inputChannelPolicies , nil
433
441
}
434
442
435
443
func (r * Reconciler ) createEventPolicies (ctx context.Context , policies []* eventingv1alpha1.EventPolicy ) error {
0 commit comments