Skip to content

fix(eventpolicy): drop deleted EventPolicies from the tracker - #9517

Open
lbarrosby wants to merge 1 commit into
knative:mainfrom
lbarrosby:fix-eventpolicy-tracker-delete
Open

lbarrosby wants to merge 1 commit into
knative:mainfrom
lbarrosby:fix-eventpolicy-tracker-delete

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

Same issue and fix as #9421 (Subscription) and #9511 (ApiServerSource), here for the EventPolicy controller.

The EventPolicy controller registers every EventPolicy as an observer of the objects referenced in spec.from through resolver.NewAuthenticatableResolverFromTracker(ctx, impl.Tracker). Its informer handler is controller.HandleAll(impl.Enqueue), so nothing calls Tracker.OnDeletedObserver when a EventPolicy is deleted. The deleted EventPolicy stays in the tracker until the lease expires, and every change to a tracked object in the meantime re-enqueues a key that no longer exists.

Proposed Changes

  • 🐛 Drop deleted EventPolicies from the tracker in the delete handler. Add and update still enqueue; on delete there is nothing left to reconcile.

Pre-review Checklist

  • At least 80% unit test coverage
  • E2E tests for any new behavior
  • Docs PR for any user-facing impact
  • Spec PR for any new API feature
  • Conformance test for any change to the spec

Testing

TestEventPolicyDeleteRemovesTrackerObservers (same shape as the tests in #9421 and #9511) tracks a reference for a EventPolicy, creates and deletes the EventPolicy through the fake client and waits for the tracker to drop it. The ConfigMap watcher used by TestNew moved to a small helper so both tests share it.

On main:

$ go test ./pkg/reconciler/eventpolicy/ -run TestEventPolicyDeleteRemovesTrackerObservers
    controller_test.go:108: Tracker still has observers after EventPolicy deletion: [ns/obj]
--- FAIL: TestEventPolicyDeleteRemovesTrackerObservers (5.00s)

With the fix:

$ go test ./pkg/reconciler/eventpolicy/...
ok  	knative.dev/eventing/pkg/reconciler/eventpolicy
$ go vet ./pkg/reconciler/eventpolicy/...
$ golangci-lint run ./pkg/reconciler/eventpolicy/...
0 issues.

Release Note

NONE

Docs

AI disclosure: written with the help of Claude Code, reviewed and tested by me.

The EventPolicy controller registers every EventPolicy as an observer of the objects referenced in `spec.from` through `resolver.NewAuthenticatableResolverFromTracker(ctx, impl.Tracker)`. The informer handler only enqueued on delete, so a deleted
EventPolicy stayed in the tracker until its lease expired and kept being
re-enqueued.

Call Tracker.OnDeletedObserver on delete, as done for Subscriptions in knative#9421.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@knative-prow

knative-prow Bot commented Nov 8, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lbarrosby
Once this PR has been reviewed and has the lgtm label, please assign dsimansk for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow
knative-prow Bot requested review from aliok and creydr November 8, 2026 19:25
@knative-prow knative-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 8, 2026
@knative-prow

knative-prow Bot commented Nov 8, 2026

Copy link
Copy Markdown

Hi @lbarrosby. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.34%. Comparing base (495a0f9) to head (6f29ed8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9517      +/-   ##
==========================================
+ Coverage   51.31%   51.34%   +0.02%     
==========================================
  Files         411      411              
  Lines       22187    22191       +4     
==========================================
+ Hits        11386    11393       +7     
+ Misses       9920     9916       -4     
- Partials      881      882       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant