[Test]: Add unit tests for pkg/controllers/exceptions package
Author: JituRewarCreated Sep 18, 2026Updated Sep 18, 2026
Labelsbugtriage
Kyverno Version
1.18.0
Description
Summary
The pkg/controllers/exceptions package responsible for managing and indexing PolicyException objects for quick rule-based lookups currently has zero unit tests.
Proposed Changes / Scope
Add comprehensive unit tests in pkg/controllers/exceptions/controller_test.go to ensure correctness and prevent future regressions:
Lookup Logic (
Find):- Querying an empty index returns
nilwithout errors. - Exact hits for matching policy and rule names.
- Misses when querying non-existent policies or rules.
- Querying an empty index returns
Event Handlers (
addPolex,updatePolex,deletePolex):- Enqueueing referenced policy names into the workqueue.
- Deduplication of policy names within the same exception.
- Enqueueing the union of policy names during exception updates.
Reconciliation (
reconcile):- Building and updating the policy-rule index for both
ClusterPolicyand namespacedPolicyresources. - Proper deletion of cache entries when a policy is deleted (
NotFound). - Namespace scoping: ensuring a controller configured for a specific namespace only indexes exceptions from that namespace.
- Deterministic ordering of exceptions by
(namespace, name).
- Building and updating the policy-rule index for both
Concurrency & Thread Safety:
- Concurrent
Findoperations across multiple goroutines. - Concurrent
reconcile(writes) andFind(reads) verified under Go race detector (-race).
- Concurrent
Benefit
Improves test coverage for exception controller caching and guarantees thread-safe index mutation and lookup.
Slack discussion
No response
Troubleshooting
- I have read and followed the documentation AND the troubleshooting guide.
- I have searched other issues in this repository and mine is not recorded.
Source: kyverno/kyverno