Skip to content

Commit 8126f8c

Browse files
committed
fix: using auth.GetEventPoliciesForResource when trying to list all Sequence's eventPolicy (not for the immediate channels)
Signed-off-by: Leo Li <[email protected]>
1 parent 092f87e commit 8126f8c

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

pkg/reconciler/sequence/sequence.go

+24-16
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,7 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence,
355355
}
356356

357357
// Prepare lists for different actions so that policies can be categorized
358-
// Corresponding operations will be performed on these lists
359358
var policiesToUpdate, policiesToCreate []*eventingv1alpha1.EventPolicy
360-
361-
// pre-allocation because we know the maximum possible size upfront (the number of existing policies).
362359
policiesToDelete := make([]*eventingv1alpha1.EventPolicy, 0, len(existingPolicies))
363360

364361
// 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,
376373
}
377374
}
378375

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])
381378
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)
383380
}
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 {
386382
existingInputPolicy, exists := existingPolicyMap[inputPolicy.Name]
387383
if exists {
388384
if !equality.Semantic.DeepDerivative(inputPolicy.Spec, existingInputPolicy.Spec) {
@@ -413,23 +409,35 @@ func (r *Reconciler) reconcileEventPolicies(ctx context.Context, s *v1.Sequence,
413409
return nil
414410
}
415411

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.
416413
func (r *Reconciler) listEventPoliciesForSequence(s *v1.Sequence) ([]*eventingv1alpha1.EventPolicy, error) {
417414
labelSelector := labels.SelectorFromSet(map[string]string{
418415
resources.SequenceChannelEventPolicyLabelPrefix + "sequence-name": s.Name,
419416
})
420417
return r.eventPolicyLister.EventPolicies(s.Namespace).List(labelSelector)
421418
}
422419

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+
)
426426
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)
431428
}
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
433441
}
434442

435443
func (r *Reconciler) createEventPolicies(ctx context.Context, policies []*eventingv1alpha1.EventPolicy) error {

0 commit comments

Comments
 (0)